7

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..?

MrSingh
  • 659
  • 1
  • 9
  • 22

1 Answers1

4

The short answer is: Yes it is possible but it is a workaround.

The Challenges

  1. wt.exe does not currently have a command line option to execute a command from a split-pane
  2. 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"

apena
  • 1,486
  • 7
  • 18