I recently downloaded the new Windows Terminal
. I have created the shortcut for opening the multiple panes(which is working fine). However, I am trying to execute a command for the respective pane.
wt -d <path> -c "cls && php artisan serve" ;
split-pane -p "Command Prompt" -H -d <path> -c "npm run watch"
I googled for the solution but no luck.
Is this even possible..?
If you'd like to open a new pane through the dropdown menu, you can hold alt and click on your desired profile. Both of these options will auto split the active window or pane into a new pane of the selected profile.
Windows Terminal is a modern host application for the command-line shells you already love, like Command Prompt, PowerShell, and bash (via Windows Subsystem for Linux (WSL)).
You can use wt.exe to open a new instance of Windows Terminal from the command line. You can also use the execution alias wt instead. If you built Windows Terminal from the source code on GitHub, you can open that build using wtd.exe or wtd .
option. You can test command line arguments by running an executable from the "Command Prompt" in XP, Vista or later, or from the "DOS prompt" in older versions of Windows. You can also use command line arguments in program shortcuts, or when running an application by using Start -> Run.
I got a similar setup working. Im running Windows Terminal version 1.8.1444.0
My goal was to setup a dotnet core app running in left pane and a react-app running in right pane:
wt -d "C:\path\to\dotnetcoreapp" -p "Command Promt" cmd /k dotnet watch run ; split-pane -d "C:\path\to\reactapp" cmd /k yarn start
Also tried to start an interactive elixir session: wt -d "C:\dev\elixir" cmd /k IEx
which also worked fine...
The short answer is: Yes it is possible but it is a workaround.
The Challenges
wt.exe
does not currently have a command line option to execute a
command from a split-pane
wsl.exe
(which runs your default shell such as bash) does not currently support opening a shell with a command without exiting the shell right after the command is run.The workaround
To get around the first challenge we can launch a custom profile that executes the command via wsl.exe
in the key value pair (in settings json) "commandline": "wsl.exe 'commands go here"
To get around the second challenge we need to execute the wsl.exe 'commands go here'
via powershell.exe
because Powershell has a -NoExit
option which will keep the shell open after the command is executed. So for example if you wanted to open a shell that runs wsl.exe
(your linux shell) with the command watch ps
then the line in the custom profile would look like this:
"commandline": "powershell.exe -NoExit -Command wsl.exe watch ps"
The Solution:
Create a profile in Windows Terminal settings.json
for each command you want to run. Each profile should have a unique guid
that you can generate in Powershell by running the command [guid]::NewGuid()
. So the profile to run the command watch ps
would look something like this:
{
"guid": "{b7041a85-5613-43c0-be35-92d19002404f}",
"name": "watch_ps",
"commandline": "powershell.exe -NoExit -Command wsl.exe watch ps",
"hidden": false,
"colorScheme": "One Half Dark"
},
Now you can open a tab in windows terminal with two panes, the pane on the right will run the command watch ps
and the shell will stay open. Put something like the below line of code in your shortcut (or from the command line) where the value of the option -p
is equal to the value of the profile you created. Each additional pane you open will need a profile that has the command you want to run in it.
wt split-pane -p "watch_ps"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With