Skip to content
Advertisement

Open tabs in Windows Terminal w/ Ubuntu WSL & Zsh

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?

Advertisement

Answer

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"
Advertisement