Ability to run scripts or additional commands per pane from wt launch #8248

Closed
opened 2026-01-31 01:24:30 +00:00 by claunia · 11 comments
Owner

Originally created by @ZelCloud on GitHub (May 19, 2020).

It would be really nice to have something like --script or --commands in addition to the split pane options we currently have. This will help fully automate the launch of multiple services from a single script / command.

Example:

wt -d "C:\dev_folder\some_project" --commnads "dir & npm run some_command" ; wt -d "C:\dev_folder\some_other_service" --commnads "dir & npm run some_command" 

I noticed in some of the issues there were talks of a --command flag already but it's different functionality from my request above.

Originally created by @ZelCloud on GitHub (May 19, 2020). It would be really nice to have something like --script or --commands in addition to the split pane options we currently have. This will help fully automate the launch of multiple services from a single script / command. Example: ```batch wt -d "C:\dev_folder\some_project" --commnads "dir & npm run some_command" ; wt -d "C:\dev_folder\some_other_service" --commnads "dir & npm run some_command" ``` I noticed in some of the issues there were talks of a --command flag already but it's different functionality from my request above.
claunia added the Issue-QuestionNeeds-TriageNeeds-Tag-FixResolution-Answered labels 2026-01-31 01:24:31 +00:00
Author
Owner

@DHowett commented on GitHub (May 19, 2020):

Thanks! This isn't something we can generically do, because we don't know how every shell will accept commands.

The best way to do this is to tell the shell what to do. This works today:

wt -d . cmd /c dir ; powershell -noexit -command gci

Fortunately, you can do that without a Terminal update 😄

@DHowett commented on GitHub (May 19, 2020): Thanks! This isn't something we can generically do, because we don't know how every shell will accept commands. The best way to do this is to tell the _shell_ what to do. This works today: `wt -d . cmd /c dir ; powershell -noexit -command gci` Fortunately, you can do that without a Terminal update :smile:
Author
Owner

@ZelCloud commented on GitHub (May 19, 2020):

Glad to hear there's already something like this.

The powershell portion seems to work just fine, but the cmd one seems to instantly exit.

@ZelCloud commented on GitHub (May 19, 2020): Glad to hear there's already something like this. The powershell portion seems to work just fine, but the cmd one seems to instantly exit.
Author
Owner

@DHowett commented on GitHub (May 19, 2020):

Whoops, I meant to say cmd /k. I pretend that k means something like [k]eep running

@DHowett commented on GitHub (May 19, 2020): Whoops, I meant to say `cmd /k`. I pretend that `k` means something like `[k]eep running`
Author
Owner

@ZelCloud commented on GitHub (May 19, 2020):

Awesome, thanks a lot @DHowett.

Also for anyone who runs into this ticket here's the syntax for running the above in separate tabs or in separate panes.

Split panes both running commands on start (just remove the split-pane if you want separate tabs instead).

wt -d "C:\project1" cmd /k dir ; split-pane -d "C:\DevProject2" cmd /k dir
@ZelCloud commented on GitHub (May 19, 2020): Awesome, thanks a lot @DHowett. Also for anyone who runs into this ticket here's the syntax for running the above in separate tabs or in separate panes. Split panes both running commands on start (just remove the split-pane if you want separate tabs instead). ```batch wt -d "C:\project1" cmd /k dir ; split-pane -d "C:\DevProject2" cmd /k dir ```
Author
Owner

@mitchpascoe commented on GitHub (May 20, 2020):

Just to piggy-back on this, is there a similar flag for wsl? Running wt -p Ubuntu-18.04; split-pane -H wsl -d Ubuntu-18.04 ls for example splits the pane, but then removes it once ls has returned the results.

@mitchpascoe commented on GitHub (May 20, 2020): Just to piggy-back on this, is there a similar flag for wsl? Running `wt -p Ubuntu-18.04; split-pane -H wsl -d Ubuntu-18.04 ls` for example splits the pane, but then removes it once ls has returned the results.
Author
Owner

@DHowett commented on GitHub (May 20, 2020):

Probably something horribly complicated like wt -p Ubuntu-18.04 -- bash -c "ls\; exec bash"

This is complicated because powershell has -noexit and cmd has /k but bash doesn't have a "keep running" option. The resulting command does this:

  1. runs ls
  2. replaces bash, which is about to exit, with a new bash, which is not about to exit

Also, stuff like this is exactly why WT will not implement that feature: it can't possibly guess what you want when the options are so insane as that.

@DHowett commented on GitHub (May 20, 2020): Probably something horribly complicated like `wt -p Ubuntu-18.04 -- bash -c "ls\; exec bash"` This is complicated because powershell has `-noexit` and cmd has `/k` but bash doesn't have a "keep running" option. The resulting command does this: 1. runs `ls` 2. replaces bash, which is about to exit, with a new bash, which is not about to exit Also, stuff like this is _exactly why WT will not implement that feature_: it can't possibly guess what you want when the options are so insane as that.
Author
Owner

@chiqui3d commented on GitHub (Mar 3, 2021):

Do you know why this command gives error? wt -p "Ubuntu18" phpstorm.sh I just want to start a script that I have globally once WSL opens, it opens but does not run phpstorm.sh.

I am using ZSH. I also clarify that without adding phpstorm.sh it works, it opens the terminal and I type phpstorm.sh manually, but I want to create several shortcuts.bat.

@chiqui3d commented on GitHub (Mar 3, 2021): Do you know why this command gives error? `wt -p "Ubuntu18" phpstorm.sh` I just want to start a script that I have globally once WSL opens, it opens but does not run `phpstorm.sh`. I am using `ZSH`. I also clarify that without adding phpstorm.sh it works, it opens the terminal and I type phpstorm.sh manually, but I want to create several shortcuts.bat.
Author
Owner

@zadjii-msft commented on GitHub (Mar 3, 2021):

Because wt -p "Ubuntu18" some-commandline doesn't append some-commandline to the commandline for Ubuntu18, it replaces it. So you'd probably want wt -p "Ubuntu18" wsl.exe -d Ubuntu-18.04 sh phpstorm.sh (or similar) to tell wsl to run your "Ubuntu-18.04" distro with a commandline like sh phpstorm.sh

@zadjii-msft commented on GitHub (Mar 3, 2021): Because `wt -p "Ubuntu18" some-commandline` doesn't _append_ `some-commandline` to the `commandline` for `Ubuntu18`, it _replaces_ it. So you'd probably want `wt -p "Ubuntu18" wsl.exe -d Ubuntu-18.04 sh phpstorm.sh` (or similar) to tell `wsl` to run your "Ubuntu-18.04" distro with a commandline like `sh phpstorm.sh`
Author
Owner

@chiqui3d commented on GitHub (Mar 3, 2021):

wt -p "Ubuntu18" wsl.exe -d Ubuntu-18.04 sh phpstorm.sh

Thank you very much indeed, it has almost worked, now I just need to find out why I get the message


Startup Error
Unable to detect graphics environment

It is as if it does not load the .zshrc configuration when executing the direct command.

@chiqui3d commented on GitHub (Mar 3, 2021): > wt -p "Ubuntu18" wsl.exe -d Ubuntu-18.04 sh phpstorm.sh Thank you very much indeed, it has almost worked, now I just need to find out why I get the message ``` Startup Error Unable to detect graphics environment ``` It is as if it does not load the .zshrc configuration when executing the direct command.
Author
Owner

@zadjii-msft commented on GitHub (Mar 3, 2021):

I mean yea - I just told you to run sh to execute the phpstorm.sh script. sh by itself definitely won't load your .zshrc 😄. You'll probably need to change that to zsh with some other args to force it to load your .zshrc. Unfortunately, I don't really have any experience with zsh so I'm not too helpful here 😕

@zadjii-msft commented on GitHub (Mar 3, 2021): I mean yea - I just told you to run `sh` to execute the `phpstorm.sh` script. `sh` by itself definitely won't load your `.zshrc` 😄. You'll probably need to change that to `zsh` with some other args to force it to load your `.zshrc`. Unfortunately, I don't really have any experience with `zsh` so I'm not too helpful here 😕
Author
Owner

@chiqui3d commented on GitHub (Mar 3, 2021):

Yes
I have succeeded. Here is the final phpstorm.bat command with GWSL active:

wt -p "Ubuntu18" wsl.exe -d Ubuntu18 -u chiqui3d DISPLAY=172.26.0.1:0 LIBGL_ALWAYS_INDIRECT=1 sh /home/chiqui3d/PhpStorm-203.7148.74/bin/phpstorm.sh

@chiqui3d commented on GitHub (Mar 3, 2021): Yes I have succeeded. Here is the final `phpstorm.bat` command with GWSL active: `wt -p "Ubuntu18" wsl.exe -d Ubuntu18 -u chiqui3d DISPLAY=172.26.0.1:0 LIBGL_ALWAYS_INDIRECT=1 sh /home/chiqui3d/PhpStorm-203.7148.74/bin/phpstorm.sh`
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#8248