10

我想使用wt.exe命令行在 Windows 终端中打开 4 个相等的窗格。这是预期的结果:

在此处输入图像描述

我尝试过使用split-pane,但没有focus-pane命令,它不起作用。

是否有可能以任何其他方式这样做?

4

4 回答 4

9

您现在可以像这样从命令行使用 wt.exe 启动 WT(我使用的是 Windows 终端预览版,我不确定您是否需要预览版):

wt split-pane -V; move-focus left; split-pane -H; move-focus right; split-pane -H

或者,您可以使用当前肯定需要 Windows Terminal Preview 版本的新startupActions设置。

我刚刚在另一个线程中回答了自己。settings.json您可以通过将以下行添加到设置的根目录来修改 Windows 终端文件:

  "startupActions": "split-pane -V; move-focus left; split-pane -H; move-focus right; split-pane -H"

然而,这意味着这将是您的默认设置(即使您从“开始”或从任务栏启动 WT,而不仅仅是通过命令行。

于 2021-02-02T20:28:00.817 回答
5

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参数那么漂亮,但这是我们现在可以从 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("%+-");
于 2020-06-02T15:26:29.403 回答
3

我可以使用来自 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 个窗格。

在此处输入图像描述

使用 power shell 在 windows 终端 (wt) 上运行它。

在您的 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

其中 index 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://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/设置图像背景窗口终端/

祝你好运。

于 2020-10-14T10:16:52.487 回答
0

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

我能管理的最好的是 3 个窗格,1x Half 和 2x Quarters。正如您所说,另一个拆分将始终给出 1x 一半,1x 四分之一,2x 八分之一。

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

更新: 可以使用键盘快捷键在窗格之间移动焦点,因此可以编写执行此操作的 PowerShell 脚本。

于 2020-05-26T22:06:17.920 回答