37

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.

  1. GitBash to my workspace
  2. Cmd to the building dir in my workspace
  3. Ubuntu bash to some data generation app
  4. ...

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.

2
  • 1
    This is not possible now. See this issue for get notified github.com/microsoft/terminal/issues/756.
    – Biswapriyo
    Sep 25, 2019 at 19:12
  • It is a shame we'll have to wait to 2.0 to get this feature as they are saying in that issue. This would be insanely useful. I could open one program and I have 90% of what I need to do my work for the day.
    – mBrice1024
    Jan 16, 2021 at 15:03

8 Answers 8

24

I think creating a custom shortcut might at least partially solve your issue.

  1. Right click anywhere on the desktop -> New -> Shortcut
  2. 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/

  1. Type shortcut name.
  2. Run the shortcut, you should get two tabs and second tab should be split in two. Something like that:

Windows terminal with multiple tabs

  1. Optionally, you can change icon, pin to the task or start bars.
4
  • 1
    I wasn't able to get the new-tab to work. After looking at their documentation, it looks like the ` tilde character is needed before each semicolon.
    – Recognizer
    Oct 7, 2020 at 14:48
  • 2
    This works, but the start config line you shared is misleading as it was not what the asker was looking for. They want multiple tabs not one tab split in two. I think what they are looking for is something more like this: wt ; new-tab -p "Command Prompt" -d C:\Temp ; new-tab -p "Command Prompt" -d C:\git ; ... (other tabs) ...
    – mBrice1024
    Jan 16, 2021 at 15:11
  • Command-line arguments: docs.microsoft.com/en-us/windows/terminal/… May 11, 2021 at 15:29
  • Note: I do "Right click anywhere on the desktop -> New -> Shortcut", I get a Window which says "Type the location of the item"; if I try to paste a command text here, I cannot - I have to type; just typing wt ; will result with a shortcut where full path to wt.exe is resolved; command with rest of arguments gets resolved with full path, and the rest of the commands appended. Also, shortcut command string length is limited to 259 characters only.
    – sdbbs
    Jan 11 at 5:05
8
  1. Open Windows Terminal
  2. Open Settings (Ctrl+,)
  3. Click "Open JSON file"
  4. Add (or modify) optional parameter "startupActions" with your start configuration (for example as @Donatas Repečka described). Only difference - you don't need to put "wt" on the start.
  5. Save file and reopen WT.

Don't forget that string should be properly escaped.

My sample:

    "startupActions": "new-tab -p \"Command Prompt\" --title \"mytab\" -d C:\\Users\\blabla ; new-tab -p \"Command Prompt\" --title \"othertab\" -d C:\\Users\\otherbla ,

Few more things about:

  • comma at the end in my sample just because there are next lines of config exist
  • if you put ";" at the beginning (or at the end) WT will open default tab at the beginning (or at the end)
  • solution with Windows shortcut is amazing, but you can't use really long (more that 260 symbols) strings, so it may not work for you
2

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.

2

Since I don't have the reputation to comment, I'll post an answer.

wt ; new-tab -p "Command Prompt" -d C:\Users\Donatas\Workspace ; split-pane -p "Ubuntu"

This command only works in a windows command (cmd) shell, but not in the Power Shell. The command is different in WSL as well. See the CLI reference for wt for more details.

In the Power Shell it looks like this:

wt `; new-tab -p "Command Prompt" -d C:\Users\Donatas\Workspace `; split-pane -p "Ubuntu"

2

This simple oneliner command creates a tab with 3 powershell splitted windows w/ a tab with 3 bash splitted windows;

  • when you're on cmd.exe
wt powershell.exe ; nt bash --noprofile --norc ; sp bash --noprofile --norc ; sp bash --noprofile --norc ; focus-tab -t 0 ; sp powershell.exe ; sp powershell.exe
  • when you're on powershell.exe or wsl bash
cmd.exe /c "wt powershell.exe ; nt bash --noprofile --norc ; sp bash --noprofile --norc ; sp bash --noprofile --norc ; focus-tab -t 0 ; sp powershell.exe ; sp powershell.exe"

enter image description here

1
  • What's wrong with you, Mr downvoter?? Are you smashing a downvote to every single answer on SO/SE that disturbed your tea time via a notification? hey please. Aug 24, 2022 at 4:24
1

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:

  1. 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
  1. In this folder-specific .bashrc I can enter the per-tab start commands

  2. 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
1
  • how can I open the ubuntu terminal in the current directory? I'm able to open both terminals at once but the ubuntu terminal starts at home directory. It would be nice if the ubuntu terminal also opened at the current directory.
    – S. Karki
    Jan 6, 2022 at 11:54
0

I have a different solution for this: in Windows 11, the Windows terminal app allows to configure predefined "profiles". Each profile can simply be a direct link to an executable, which when selected will start in its own tab. This is ideal for developers which may want to run only specific microservices, and choose only the ones that are needed at any time.

Steps:

  • open windows terminal
  • click the "drop-down" symbol and then choose settings
  • under profiles, select "add a new profile"
  • choose "new empty profile"
  • at name, define the name as you want it to appear
  • at command line, browse to the executable you want to execute

You can even define custom backgrounds to differentiate test and production environments.

1
  • 1
    Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Nov 28, 2022 at 10:20
0

building on the answer from @kilj You can build profiles in the settings.json and then call the different profile with the startupActions line. each profile requires a uuid for a guid and can be referenced by the name. for example you could add the profile:

{
  "guid": "{7c58fcf0-5fcd-4d8e-8f96-e6908c600f6b}",
  "hidden": false,
  "tabColor": "#0000FF",
  "startingDirectory": "%systemdrive%\\Windows\\System32\\openssh",
  "name": "foo"
 }

and add the startup action:

"startupActions": "nt -p foo"

to open a new terminal tab that will start in the openssh directory and have a blue tab color. you can stack multiple new tab commands to match the different profiles that you create and add `"commandline": "" if you'd like to have the profile start with a command. Look here for more information.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.