How To Open Windows Terminal From the Command Line

The new Windows Terminal is a "Modern" UWP app, which means that it doesn't lend itself to launching from the command-line. Fortunately, there's an easy answer:
> wt

Given how easy that is, I'm not sure if there's any value to this, but you can also launch it via explorer.exe shell, as you can any other Modern app:
> explorer.exe shell:AppsFolder\Microsoft.WindowsTerminal_8wekyb3d8bbwe!App

... or via start
> start "" shell:AppsFolder\Microsoft.WindowsTerminal_8wekyb3d8bbwe!App

And if you'd like to understand how I came up with the longer UWP-specific version of that, you can read more about that here.

How Can I Pass An Argument To the Target of the Shell Command?

If you want to pass command-line arguments to Windows Terminal, you can just add them to the end of the start command. For example, this opens a new tab with my GitBash terminal profile instead of the default:

> start "" shell:AppsFolder\Microsoft.WindowsTerminal_8wekyb3d8bbwe!App new-tab -p "GitBash"

And if you want to run that from SlickRun, which doesn't recognize the start command as a runnable file, you can use cmd /c, like this:

> cmd /c start "" shell:AppsFolder\Microsoft.WindowsTerminal_8wekyb3d8bbwe!App new-tab -p "GitBash"

Opening Multiple Terminals With One Command

On certain projects, it's nice to open several terminals at once, using different profiles and starting in different working directories. This can be done with a single command, making it easy to kick things off again at the start of each work session. In this example, I'm opening five different tabs:

wt.exe -w code new-tab -p "GitBash" ; new-tab -p "Ubuntu" -d "/home/mark/code/project1" ; new-tab -p "Ubuntu" -d "/home/mark/code/project2" ; new-tab -p "Ubuntu" -d "/home/mark/code/project3" ; new-tab -p "GitBash"

The -w code parameter puts all the terminals in a single window named "code", which can later be used to add more tabs to the same window. The semi-colon-separated list of new-tab parameters defines the five tabs, and the -p flag is used to tell WT which named profile each of the tabs should use. In those cases where I want a tab to open to a specific directory, the -d flag is used.

comments powered by Disqus