1

I'm writing a script to run on UBUNTU WSL in Windows. I use zsh as my shell, but bash could work too here.

I'd like that bash script to use wt.exe (Windows Terminal) to open some new tabs.

Here's what I have so far:

#!/bin/bash

cmd.exe /c "wt.exe" \
  new-tab --title 'a' --tabColor "#f00" wsl.exe "ls" \; \
  new-tab --title 'b' --tabColor "#f33" wsl.exe zsh -is -c "ls" \; \
  new-tab --title 'c' --tabColor "#f99" wsl.exe zsh -is "ls" \; \
  new-tab --title 'd' --tabColor "#0f0" wsl.exe zsh -i -c "ls" \; \
  new-tab --title 'e' --tabColor "#3f3" wsl.exe zsh -c "ls" \; \
  new-tab --title 'f' --tabColor "#9f9" wsl.exe zsh "ls" \; \

You'll need Windows 10 w/ Ubuntu WSL and Windows Terminal for that to work.

This bash script opens a bunch of tabs.

  • Tabs that ls immediately exit.
  • Tabs that error stick around.

enter image description here I'd like to automate:

  • opening several tabs in different folders:
  • run a command (yarn dev)
  • cancel that command (ctrl-c) and have the terminal interactive instead of exit.

I got this to work on previous version of these tools, but they changed.

What's the new way?

Michael Cole
  • 15,473
  • 7
  • 79
  • 96
  • Before fiddling around with the `wt` problem, a few basic question: Does a `cmd.exe wsl.exe ls` or a `cmd.exe wsl.exe zsh` do something reasonable, or do you get an error message? – user1934428 Nov 21 '21 at 11:08

1 Answers1

1

zsh ls does not make sense. In general,

zsh some_file

asks zsh to interpret some_file as a text file containing a zsh script. To invoke the external command ls, you would at least have to write

zsh -c ls

In your case, it makes perhaps (depending on how you configured zsh) sense to run it as login shell. The invocation would be then something like

zsh -lc ls

Of course the zsh exits after that immediately, because you don't open an interactive shell. To achieve this, you could overlay your non-interactive zsh with an interactive zsh process after the ls has been performed:

zsh -lc "ls; zsh"
Michael Cole
  • 15,473
  • 7
  • 79
  • 96
user1934428
  • 19,864
  • 7
  • 42
  • 87
  • I get `[error 0x80070002 when launching 'zsh'`. Did you try this before answering? – Michael Cole Nov 16 '21 at 15:11
  • Did you escape the quotes properly when embedding this command in the context of your cmd.exe invocation? Otherwise the double quotes would be consumed by the cmd-shell. It is important that `zsh` receives the string `ls;zsh` as a single argument. – user1934428 Nov 17 '21 at 08:57
  • Hi @user1934428 thanks for the reply. I don't know. I plugged several of your suggestions into the script above and didn't get a positive result. Something like: `cmd.exe /c "wt.exe" new-tab wsl.exe zsh -lc \"ls; zsh\" \; new-tab wsl.exe zsh -lc "ls; zsh"` What would be proper escaping be? – Michael Cole Nov 19 '21 at 19:10
  • I don't know whether a semicolon has special meaning to cmd.exe and/or wt.exe and/or wsl.exe, but if it doesn't, I would just write `ls;zsh`without space in between, and then don't care about the quotes. In your case, the quotes are necessary to pass `ls; zsh` as a single argument to `zsh`, and it must be ensured that `zsh` never sees the quotes. For a start, try to run just a `wsl.exe zsh -lc ....` from the command line, without caring about the enclosing cmd.ex and wt.exe, and from here work to the outside (wt.exe, cmd.exe). – user1934428 Nov 21 '21 at 10:14