如何打开带有 4 个窗格的 Windows 终端?
How to open Windows Terminal with 4 panes?
我想在 Windows 终端中使用 wt.exe
从命令行打开 4 个相等的窗格。这是预期的结果:
我曾尝试使用 split-pane
,但没有 focus-pane
命令,它不起作用。
是否可以通过其他方式做到这一点?
我想要这个,但我认为目前不可能。
我能管理的最好的是 3 个窗格,1 个半格和 2 个四分之一格。正如您所说,另一个拆分将始终给出 1x 半、1x 四分之一、2x 八分之一。
我尝试使用配置文件加载另一个 wt 并拆分第一个窗格,但它总是一个新的 window/process。
更新:
可以使用键盘快捷键在窗格之间 moveFocus,因此可以编写执行此操作的 PowerShell 脚本。
更新于 09/06/2021
我们终于可以通过命令行参数来实现了。这是一个工作示例:
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
参数那么漂亮,但这是我们现在可以从 bat 文件中做的最好的事情。
@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("%+-");
我可以通过 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) 上 shell.
在您的 windows 终端中添加这 2 个示例 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,
并且图像是它的背景,
按顺序添加这 2 个示例并使用您的 wt 菜单对其进行自定义。
教程如下:
https://www.howtogeek.com/673729/heres-why-the-new-windows-10-terminal-is-amazing/
https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.sendkeys.send?view=net-5.0
https://docs.microsoft.com/en-us/windows/terminal/customize-settings/actions#move-pane-focus
https://pureinfotech.com/set-image-background-windows-terminal/
祝你好运。
您现在可以像这样从命令行使用 wt.exe 启动 WT(我使用的是 Windows 终端预览版,我不确定您是否需要此预览版或不是):
wt split-pane -V; move-focus left; split-pane -H; move-focus right; split-pane -H
或者,您可以使用新的 startupActions 设置,您目前绝对需要 Windows 终端预览版。
我刚刚在另一个 中回答了自己。您可以通过将以下行添加到设置的根目录来修改 Windows 终端 settings.json
文件:
"startupActions": "split-pane -V; move-focus left; split-pane -H; move-focus right; split-pane -H"
然而,这意味着这将成为您的默认设置(即使您从“开始”或任务栏启动 WT,而不仅仅是通过命令行。
我想在 Windows 终端中使用 wt.exe
从命令行打开 4 个相等的窗格。这是预期的结果:
我曾尝试使用 split-pane
,但没有 focus-pane
命令,它不起作用。
是否可以通过其他方式做到这一点?
我想要这个,但我认为目前不可能。
我能管理的最好的是 3 个窗格,1 个半格和 2 个四分之一格。正如您所说,另一个拆分将始终给出 1x 半、1x 四分之一、2x 八分之一。
我尝试使用配置文件加载另一个 wt 并拆分第一个窗格,但它总是一个新的 window/process。
更新: 可以使用键盘快捷键在窗格之间 moveFocus,因此可以编写执行此操作的 PowerShell 脚本。
更新于 09/06/2021
我们终于可以通过命令行参数来实现了。这是一个工作示例:
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
参数那么漂亮,但这是我们现在可以从 bat 文件中做的最好的事情。
@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("%+-");
我可以通过 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) 上 shell.
在您的 windows 终端中添加这 2 个示例 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, 并且图像是它的背景,
按顺序添加这 2 个示例并使用您的 wt 菜单对其进行自定义。
教程如下:
https://www.howtogeek.com/673729/heres-why-the-new-windows-10-terminal-is-amazing/ https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.sendkeys.send?view=net-5.0 https://docs.microsoft.com/en-us/windows/terminal/customize-settings/actions#move-pane-focus https://pureinfotech.com/set-image-background-windows-terminal/
祝你好运。
您现在可以像这样从命令行使用 wt.exe 启动 WT(我使用的是 Windows 终端预览版,我不确定您是否需要此预览版或不是):
wt split-pane -V; move-focus left; split-pane -H; move-focus right; split-pane -H
或者,您可以使用新的 startupActions 设置,您目前绝对需要 Windows 终端预览版。
我刚刚在另一个 settings.json
文件:
"startupActions": "split-pane -V; move-focus left; split-pane -H; move-focus right; split-pane -H"
然而,这意味着这将成为您的默认设置(即使您从“开始”或任务栏启动 WT,而不仅仅是通过命令行。