Windows Terminal

Written July 18, 2021, Updated July 29, 2021

As a long time Linux/mac user, I could not stand the built-in Command Prompt/Windows PowerShell terminal application.

It seems I wasn't the only one as Microsoft has made a brand new terminal application (called Windows Terminal) to replace the old ones.

You can use the Microsoft Store to install it microsoft store or if you can't access the store for some reason, you can try the installer from the github release assets.

Configure WSL as the default

The first thing I noticed is I wanted WSL as my default command line environment, so let's fix that.

Open the Settings

terminal settings

Expand the selection

default profile

Change it to Ubuntu

ubuntu

Fix the starting directory

You'll notice the starting directory isn't quite what you expect. If you execute

cd

It will take you to your $HOME, but to do this EVERY TIME is an annoyance I cannot live with, and neither should you. To fix this, simply add this to the very end of your ~/.bashrc:

# use the home directory if a new bash shell spawns in a /mnt/c/* directory
echo "${PWD}" | grep -q '^/mnt/c/' && cd

The old method of modifying the Starting directory in the Windows Terminal Ubuntu-20.04 profile no longer works when wsl is not yet initialized :(

Fix exit behaviour

Another annoyance I noticed is sometimes, when you type command exit, the active Windows Terminal tab does not actually exit. Here is a little test:

echo 'Does Windows Terminal exit' | grep -q 'properly?'
exit

If you see:

logout

[process exited with code 1]

that means it didn't actually exit, did it?

So to fix this madness, Open your Windows Terminal Settings again, select the Ubuntu-20.04 Profile, Advanced, under Profile termination behavior, select the first option as per the screenshot below:

terminiation behaviour

Click Save. It will take effect upon the next tab launch.