如何打开具有四个窗格的Windows终端?

16
我希望使用命令行中的wt.exe在Windows Terminal中打开4个相等的面板。这是预期的结果:

enter image description here

我已尝试使用split-pane,但没有focus-pane命令,它无法工作。
是否可以以其他方式实现?
4个回答

19
你现在可以像这样从命令行启动WT,使用wt.exe(我正在使用Windows Terminal Preview版本,我不确定你是否需要此版本):
wt split-pane -V; move-focus left; split-pane -H; move-focus right; split-pane -H

或者,你可以使用新的startupActions设置,但目前需要使用Windows Terminal预览版。

我在另一个线程中回答了类似问题。你可以通过在设置的根目录下添加以下行来修改Windows终端settings.json文件:

  "startupActions": "split-pane -V; move-focus left; split-pane -H; move-focus right; split-pane -H"
这意味着从现在开始,这将是你的默认设置(即使你从“开始”菜单或任务栏启动WT,而不仅仅是通过命令行)。
这意味着从现在起,这将成为您的默认设置(即使您从“开始”菜单或任务栏启动WT,而不仅仅是通过命令行)。

1
如果你正在尝试"move-focus",请务必阅读"Windows Terminal Preview"。 - EMalik
2
@EMalik 现在,“正常”版本(即“非预览”)已经达到了1.6,因此不再需要预览版本。 - Fabio says Reinstate Monica
3
4x4格子:wt sp -V; mf left; sp -H; mf up; sp -V; sp -H; mf left; sp -H; mf down; sp -V; sp -H; mf left; sp -H; mf right; mf right; sp -H; mf up; sp -V; sp -H; mf left; sp -H; mf down; sp -V; sp -H; mf left; sp -HTranslated: 4x4 grid: wt sp -V; mf left; sp -H; mf up; sp -V; sp -H; mf left; sp -H; mf down; sp -V; sp -H; mf left; sp -H; mf right; mf right; sp -H; mf up; sp -V; sp -H; mf left; sp -H; mf down; sp -V; sp -H; mf left; sp -H - Lewik

8

2021年9月6日更新

我们终于可以通过命令行参数来实现它了。以下是一个可用的示例:

wt -M -d "./dir-a"; ^
split-pane -V -d "./dir-b"; ^
move-focus left; ^
split-pane -H -d "./dir-c"; ^
move-focus right; ^
split-pane -H -d "./dir-d"

旧答案

我能够使用 JScript 编程使其工作。虽然不像使用 wt.exe 参数那样优美,但现在从批处理文件的角度来看这是我们最好的选择。

@if (@X) == (@Y) @end /*
@cscript //E:JScript //nologo "%~f0" "%*"
@exit /b %errorlevel%
*/

// run windows terminal
var shell = WScript.CreateObject("WScript.Shell");
shell.run("wt.exe");
WScript.Sleep(500);

// ALT+SHIFT+=
shell.SendKeys("%+=");
WScript.Sleep(500);

// ALT+SHIFT+-
shell.SendKeys("%+-");
WScript.Sleep(500);

// focus left pane
shell.SendKeys("%{LEFT}");

// ALT+SHIFT+-
WScript.Sleep(500);
shell.SendKeys("%+-");

1
这真的很棒,谢谢!看起来 "%{LEFT}" 在这里不起作用,那个键到底是什么,它只是左边的键盘键吗? - jonathancardoso
这是按下alt键后的左侧键盘按键。 - Vitor Durante
这个答案已经过时了,请查看得票最高的答案。 - MarcMush
将正确答案链接到之前的帖子中,这样更公平。 - c z

5
我可以使用Windows终端(wt)的这个单一命令来完成这件事:
wt -p "Command Prompt" `; sp -V -p "openSUSE-Leap-15-1" `; sp -H -p "Windows PowerShell"; [void][System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms'); Start-Sleep -s 2; [System.Windows.Forms.SendKeys]::SendWait("%{LEFT}"); Start-Sleep -s 2; [System.Windows.Forms.SendKeys]::SendWait("%+{5}")

从左上角开始顺时针方向移动,然后停在左下角,在我的Windows终端中,序列是:cmd提示符、OpenSUSE、Windows PowerShell和Kali Linux。

它将在Windows终端中均匀地打开4个窗格。

输入图像描述

在Windows终端(WT)上使用PowerShell运行它。

将这两个示例添加到您的Windows终端settings.json文件中。

{ "command": { "action": "splitPane", "split": "horizontal", "index": 4 }, "keys": "alt+shift+5" }

"backgroundImage": "%USERPROFILE%/Downloads/win_terminal_bg_img/kali_linux.jpg",
"backgroundImageOpacity": 0.3

其中索引4和alt shift 5((“%+ {5}”))是指在我的Windows终端(wt)菜单中的kali-linux,图片用于其背景,

将这两个示例按顺序添加并根据您的wt菜单进行自定义。

以下是教程:

https://www.howtogeek.com/673729/heres-why-the-new-windows-10-terminal-is-amazing/ https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.sendkeys.send?view=net-5.0 https://learn.microsoft.com/en-us/windows/terminal/customize-settings/actions#move-pane-focus https://pureinfotech.com/set-image-background-windows-terminal/

祝你好运。


1
请确保您从命令提示符中调用wt。我之前是从另一个Windows终端运行的,但它没有起作用。 - Hernan Veiras

0

我想要这个,但我认为目前不可能。

我能做到的最好的是3个窗格,1x一半和2x四分之一。正如你所说,另一个分割总会给出1x一半,1x四分之一,2x八分之一。

我尝试使用配置文件加载另一个wt并拆分第一个窗格,但它总是一个新的窗口/进程。

更新: 可以通过键盘快捷键移动焦点在窗格之间移动,因此可能可以编写一个PowerShell脚本来实现这一点。


1
如果你感兴趣的话,我已经从一个批处理文件中让它工作了。 - Vitor Durante
干得好!我尝试过在Settings.json中嵌入一个PowerShell脚本,但我认为那是个错误。参数很难传递,容易遇到解析错误。 - Ash Lawson
@VitorSubs 我很好奇,请分享。 - John Homer
@JohnHomer请查看被采纳的答案。它向进程发送键盘命令。但是目前还没有更好的方法。 - Vitor Durante

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接