【问题标题】:How to open Windows Terminal with 4 panes?如何打开带有 4 个窗格的 Windows 终端?
【发布时间】:2020-09-04 18:08:57
【问题描述】:

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

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

是否可以通过其他方式做到这一点?

【问题讨论】:

    标签: windows-terminal


    【解决方案1】:

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

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

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

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

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

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

    【讨论】:

    • 如果您正在尝试“移动焦点”,请不要错过阅读“Windows 终端预览”
    • @EMalik 现在“普通”版本(如“非预览”)has reached 1.6,不再需要预览版本。
    • 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 -H
    【解决方案2】:

    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("%+-");
    

    【讨论】:

    • 这个姐姐太棒了,谢谢!看起来“%{LEFT}”在这里不起作用,那个键到底是什么,它只是左键盘键吗?
    • 它是按住 alt 的左键盘键
    • 此答案已过时,请查看票数最高的答案
    【解决方案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 prompt、opensuse、windows powershell 和 kali linux,

    它将在 windows 终端中平均打开 4 个窗格。

    在带有 power shell 的 windows 终端 (wt) 上运行它。

    在您的 windows 终端 settings.json 中添加这 2 个示例

    { "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, 并且图像是它的背景,

    按顺序添加这 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/

    祝你好运。

    【讨论】:

      【解决方案4】:

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

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

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

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

      【讨论】:

      • 如果您有兴趣,我可以从 bat 文件中找到它
      • 出色的工作,我尝试在 Settings.json 的配置文件中嵌入 Powershell 脚本,但我认为这是一个错误。参数很难传递而不遇到解析错误。
      • @VitorSubs 我很好奇,请分享。
      • @JohnHomer 检查接受的答案。它向进程发送键盘命令。不幸的是,目前还没有更好的办法。
      猜你喜欢
      • 2021-08-11
      • 2020-01-20
      • 1970-01-01
      • 2022-11-11
      • 1970-01-01
      • 1970-01-01
      • 2015-05-02
      • 2012-09-27
      • 2017-03-14
      相关资源
      最近更新 更多