Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open Windows Terminal with 4 panes?

I want to open 4 equal panes in Windows Terminal using wt.exe from command line. This is the intended result:

enter image description here

I have attempted using split-pane, but without a focus-pane command, it doesn't work.

Is it possible to do so in any other way?

like image 561
Vitor Durante Avatar asked May 18 '20 20:05

Vitor Durante


People also ask

How do I open multiple windows in terminal?

Using the tab context menu If you'd like to open a new pane of a profile that is already open in your terminal, you can right click on the tab and click Split Tab. This will duplicate the focused pane in the current tab.

What is the fastest way to open terminal in Windows?

You can invoke most features of Windows Terminal through the command palette. The default key combination to invoke it is Ctrl + Shift + P . You can also open it using the Command palette button in the dropdown menu in Windows Terminal Preview.

How do I split a pane in terminal?

The shortcuts cmd-d and cmd-shift-d divide an existing session vertically or horizontally, respectively. You can navigate among split panes with cmd-opt-arrow or cmd-[ and cmd-]. You can "maximize" the current pane--hiding all others in that tab--with cmd-shift-enter.

How do I open terminal on Windows keyboard?

Press the Ctrl + Alt + W hotkey to open Windows Terminal.


3 Answers

You can now start WT using wt.exe from the command line like this (I'm using Windows Terminal Preview version, I'm not sure if you need the Preview version for this or not):

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

Alternatively, you can use the new startupActions setting for which you currently definitely need Windows Terminal Preview version.

I just answered myself in another thread about this. You can modify your Windows Terminal settings.json file by adding the following line to the root of your setting:

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

This means however that this will now be your default (even when you start WT from Start or from the taskbar, not only through the command line.

like image 194
tkit Avatar answered Dec 30 '22 20:12

tkit


Update on 09/06/2021

We can finally achieve it through command line arguments. Here is a working example:

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"

Old Answer

I was able to get it working programatically using JScript. Not as beautiful as using wt.exe arguments, but it is the best we can do from a bat file nowadays.

@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("%+-");
like image 40
Vitor Durante Avatar answered Dec 30 '22 19:12

Vitor Durante


I am able to do that with this single command from windows terminal (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}")

it starts from top left and go as a clockwise, then stop at bottom left, in my windows terminal the sequences are : cmd prompt, opensuse, windows powershell, and kali linux,

it will opens 4 panes equally in windows terminal.

enter image description here

Run it on windows terminal (wt) with power shell.

Add these 2 examples in your windows terminal 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

where index 4 and alt shift 5 (("%+{5}")) refer to kali-linux in my windows terminal (wt) menu, and the image is for its background,

add those 2 examples sequentially and customize it with your wt menu.

Here are the tutorials :

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/

Good Luck.

like image 23
halilintar8 Avatar answered Dec 30 '22 19:12

halilintar8