I was typically opening four cmd prompts for working on this project. In each I would have to execute commands to put each shell in the appropriate working directory. When I started using Windows Terminal, I would open four tabs and change each to the appropriate directory. Now, do I need four shells open? Don’t know, but I find it convenient.

I use two for working with Hugo, the static site generator I use for the blog. One PowerShell tab for using Hugo to generate the pages as I work on them. And one mainly for issuing git commands as I go along. One of the most common Hugo commands locks the shell because it is serving up a test site for me to review my posts as they are written. So, having the other open makes sense.

I have a similar arrangement for working on my py_play code. One PowerShell tab for git commands. And an Anaconda prompt for running code, which I sometimes do so I can capture images of everything written to the shell by the application I am working on. It’s also much larger than the small terminal window VS Code provides.

It occurred to me it would be really nice if I could get Windows Terminal to open with the four tabs configured the way I use them. Turns out it is possible, using a desktop shortcut

Anaconda Prompt vs Anaconda PowerShell

While working on getting this to work, I ran into problems trying to use the Anaconda Prompt I had previously added to my Windows Terminal settings. So I added an Anaconda Powershell to my list of profiles in my settings file. Using the technique described in that earlier post. My profiles now look like this:

    "profiles":
    {
        "defaults":
        {
            // Put settings here that you want to apply to all profiles.
        },
        "list":
        [
            {
                // Make changes here to the powershell.exe profile.
                "guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
                "name": "Windows PowerShell",
                "commandline": "powershell.exe",
                "hidden": false
            },
            {
                // Make changes here to the cmd.exe profile.
                "guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
                "name": "Command Prompt",
                "commandline": "cmd.exe",
                "hidden": false
            },
            {
                // Make changes here to the anaconda powershell profile.
                "guid": "{9aabd3ef-ec47-4dbb-b4af-92c0ce3862f1}",
                "name": "Anaconda PowerShell",
                "commandline": "%windir%\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -ExecutionPolicy ByPass -NoExit -Command & 'E:\\appDev\\Miniconda3\\shell\\condabin\\conda-hook.ps1' ; conda activate 'E:\\appDev\\Miniconda3' ",
                "icon": "E:\\appDev\\Miniconda3\\Menu\\Iconleak-Atrous-PSConsole.ico",
                "hidden": false
            },
            {
                // Make changes here to the anaconda profile.
                "guid": "{6ce8d80e-b55a-4655-9739-4ccb9c452bde}",
                "name": "Anaconda Prompt",
                "commandline": "cmd.exe /K E:\\appDev\\Miniconda3\\Scripts\\activate.bat",
                "icon": "E:\\appDev\\Miniconda3\\Menu\\Iconleak-Atrous-Console.ico",
                "hidden": false
            },
            {
                "guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b8}",
                "hidden": false,
                "name": "Azure Cloud Shell",
                "source": "Windows.Terminal.Azure"
            }
        ]
    },

Windows Terminal Shortcut Tab Commands

I used the information from the two articles/posts in the resources section at the bottom of this post to help me get the job done.

After reading the articles and likely one or two others, I decided it best I sort out the commands I would need for wt.exe to give me the four tabs I was after. I am going to show the command parameters for all four tabs I use, though you may not be wanting that many.

First Tab: PowerShell, in blog directory

Since Windows Terminal is configured, in my case, to open a PowerShell tab by default, all I need do is tell it what I want for the current working directory (cwd). So -d r:\hugo\tooOldCode should do. And a meaningful tab title would be nice. So: -d r:\hugo\tooOldCode --title Hugo is what I am going with.

Second Tab: PowerShell, in blog directory

A semicolon is used to seperate the parameters for commands in the list. So, for this one we need a semi-colon to seperate it from the previous command. Then we need to tell Windows Terminal that we want to open a new tab running PowerShell. Since my default profile for a new tab is “Windows PowerShell”, I don’t need to specify a profile in this command. Then, that we want the cwd to be the home directory for my blog development. And, a tab title as well. So somethng like the following should work: ; new-tab -d r:\hugo\tooOldCode --title git-Hugo.

Third Tab: PowerShell, in py_play directory

Again a semicolon to separate commands. A new tab parameter with a profile of PowerShell, the new cwd and title. Something like: ; new-tab -d r:\learn\py_play --title git-py_play.

Fourth Tab: Anaconda PowerShell, in py_play directory

So, this time we need a new profile name, in my case, “Anaconda PowerShell”. Same cwd as above. Which gives: ; new-tab -p "Anaconda PowerShell" -d r:\learn\py_play. And that’s why I had to switch to an Anaconda PowerShell. The “Anconda Prompt” didn’t seem to understand the command issued by wt.exe to change the cwd. I decided a tab title really wasn’t needed.

Active Tab

Unless otherwise specified, the active tab will be the last one created. Since I almost always start working on my blog by starting the blogging software’s in-memory server, I’d like the first tab to have the focus. So, ; focus-tab -t 0.

And finally the whole shortcut target becomes:

wt.exe -d r:\hugo\tooOldCode --title Hugo; new-tab -d r:\hugo\tooOldCode --title git-Hugo; new-tab -d r:\learn\py_play --title git-py_play; new-tab -p "Anaconda PowerShell" -d r:\learn\py_play; focus-tab -t 0

Most of the articles I looked at left a space before the semi-colon to make things a little more obvious and easier to read. But, there is in fact a limit to the length of the string you can have in the shortcut’s Target field. I tried just entering wt.exe rather than C:\Users\bark\AppData\Local\Microsoft\WindowsApps\wt.exe to try and get more room for additional text. But, no go, Win 10 adds the path to the front of the wt.exe command and truncates the line. So keep that in mind when building your shortcut. If you don’t want to open four tabs like I am doing you should be just fine.

The above was an iterative and learning process for me. My first attempt opened the four tabs and changed to the desired working directory in each. But no meaningful tab titles and no change of tab focus. I used it that way for serveral weeks. While working on this blog post, I realized I could do things a bit differently.

Even though I had skipped specifying a profile for the first tab, it didn't occur to me to do the same for the 2nd and 3rd tabs. Duh! The result is that I hit that text length limit fairly quickly. I also had the spaces around the semi-colons. A bit less space to play with. So I skipped those two extra profile options and the leading space on the semi-colon. Didn't try eliminating the trailing space. That gave me the extra room to add the tab titles and the tab focus command.

Pays to experiment. Though perhaps a little extra research might have gotten me there sooner. But at least I can say, working on this post improved the shortcut for my situation.

Creating the Shortcut

  • Right click anywhere on the desktop and select New -> Shortcut from the menu presented.
  • I didn’t really know exactly what I was doing the first time, so I entered wt.exe (the Windows Terminal executable). And clicked Next. specify shortcut location/target
  • I entered a name and clicked Finish. For this example I have used “Multi-tab Terminal”. For my case I called it “Blogging Terminal”. specify shortcut name shortcut shown on desktop
  • If you double click the shortcut, you should now get a Windows Terminal Window with one tab. Not quite want I want, but progress. The cwd directory is my home directory. Close that terminal window.
  • Now right click the shortcut and select Properties. You will see that Windows has found the location of wt.exe for us. shortcut properties showing that the 'Start in:' and 'Target:' have been fully populated with Terminals path
  • Let’s add our list of commands to the end of the Target line. Which currently is C:\Users\bark\AppData\Local\Microsoft\WindowsApps\wt.exe. I have the following:
C:\Users\bark\AppData\Local\Microsoft\WindowsApps\wt.exe -d r:\hugo\tooOldCode --title Hugo; new-tab -d r:\hugo\tooOldCode --title git-Hugo; new-tab -d r:\learn\py_play --title git-py_play; new-tab -p "Anaconda PowerShell" -d r:\learn\py_play; focus-tab -t 0
shortcut properties showing a portion of the modified 'Target:' value - Hit okay and test. My test worked perfectly. - Finally, I didn't want to be hunting on the desktop (often covered with open windows) for this shortcut. So, I right clicked the shortcut and selected *Pin to start*. I then opened the start menu and arranged my icons/shortcuts to my liking. view of start menu showing the new shortcut

That’s it for this one. Hope this proves of as much use to you as it has to me. You can of course have multiple shortcuts, suitably named, creating differing tabs depending on your needs in each case.

Resources