Windows terminal: Predefined tabs on startup
Is it possible to start the Windows terminal with (multiple) tabs, each on a configured working directory?
The reason for this is, because I usually manually do the same steps each day: Start the same handful of shells and cd on each of them to a specific path. E.g.
- GitBash to my workspace
- Cmd to the building dir in my workspace
- Ubuntu bash to some data generation app
- ...
It would be super cool to automate these steps.
This question is a bit similar to Open Terminal with predefined tabs but for the new Windows Terminal.
I think creating a custom shortcut might at least partially solve your issue.
- Right click anywhere on the desktop -> New -> Shortcut
- Type the start configuration you want, for example:
wt ; new-tab -p "Command Prompt" -d C:\Users\Donatas\Workspace ; split-pane -p "Ubuntu"
- wt - opens Windows Terminal
- new-tab - opens new tab
- split-pane - splits the screen (you can split the tab both, vertically and horizontally)
- -p specifies the profile for example, Ubuntu
- -d specifies starting directory of the profile
More information: https://devblogs.microsoft.com/commandline/windows-terminal-preview-v0-9-release/
- Type shortcut name.
- Run the shortcut, you should get two tabs and second tab should be split in two. Something like that:
Windows terminal with multiple tabs
- Optionally, you can change icon, pin to the task or start bars.
There is a way to add in the right click menu the option to open Windows Terminal set with the tabs you'd like in the directory you are stepped on. You'll need to make use of the Registry Editor of Windows.
The steps are the following:
Step 1: Open Registry Editor you can do this by typing its name in Start Search or by typing regedit
in the Run command window (open it with Windows + R
).
Step 2: Once on the Registry Editor, go to \HKEY_CLASSES_ROOT\Directory\Background
. Right click on the subdirectory shell
and press new
, selecting key
. Rename this key as you like, it could be something of the sort of "Open Windows Terminal here". Here you can see a picture of how it should look creating a new key.
Step 3: On the new key created, you must create another subkey, by right clicking it and creating a new key just like before. This new key must be called command
.
Step 4: With the command
key selected, double click the string value which you can see at the right of the screen. You can modify its value as you please. Now the commands you can introduce on the terminal come handy. You can type the following as the string value:
wt -d . ; new-tab -p "Ubuntu-20.04" -d . ; new-tab -p "Command Prompt" -d . ;
This should do the trick, changing the name of the terminal tabs opened by the name of the terminals you would like to open.
Step 5, Optional: You can add the icon that you like to the entry you just created in the context menu (right click menu). This is done by creating a new string value in the key (Picture here) you created in Step 2. This string value must be renamed as Icon
and the value it must contain is the directory of the icon you'd like to use in the new menu entry you created. It seems that it also works with the directory of the app you want to execute, I say this because it worked for me by establishing the Windows Terminal absolute directory on the Icon
key's value.
The only unexpected thing in this is that when opening the Windows Terminal, an additional tab which is the Terminal's default tab is also opened. I do not think it's a difficult thing to solve, but I just close that tab whenever I open the Terminal.
I solved the startup problem per tab for Bash (but probably similar solutions can be used for Ubuntu, PowerShell or Cmd) by using the following:
- I changed my .bash-profile to contain the following (meaning: if there is a .bashrc in the start-folder it executes that one instead of the standard .bashrc):
test -f ~/.profile && . ~/.profile
test -f ./.bashrc && . ./.bashrc
test ! -f ./.bashrc && test -f ~/.bashrc && . ~/.bashrc
-
In this folder-specific .bashrc I can enter the per-tab start commands
-
I start WindowsTerminal like this:
C:\Users\[USER]\AppData\Local\Microsoft\WindowsApps\wt.exe new-tab -p "Bash" -d E:\work\api-server ; new-tab -p "Bash" -d E:\work\web-client