Setting up Windows Terminal with Zsh

Subscribe to my newsletter and never miss my upcoming articles

I've written a quick post about Moving to Windows from a Mac. On that post, I've mentioned how I've been using the Windows Terminal as my main terminal.

The Windows Terminal is great, but has a few problems:

  • Pretty simple theme (a grey text on a black background)
  • It's not using my favourite shell zsh shell
  • No icons or interactive profiles

The terminal itself it's pretty good and allows you to have different tabs on it. It also comes with integrated support for the Windows Subsystem for Linux, Windows Powershell, Azure cloud shell and the Command Prompt.

Windows Terminal is a modern terminal application for users of command-line tools and shells like Command Prompt, PowerShell, and Windows Subsystem for Linux (WSL). Its main features include multiple tabs, panes, Unicode and UTF-8 character support, a GPU accelerated text rendering engine, and the ability to create your own themes and customize text, colours, backgrounds, and shortcut key bindings.

You can read more about the features of the Windows Terminal on the official documentation website.

You can also download the Windows Terminal from the Microsoft Store.

Setting up WSL as the default profile

When you run the Windows Terminal, you can see that the Terminal opens the Windows PowerShell by default. Since I am going to be using WSL all the time, I want this to be the default.

We can change the default profile by opening the terminal menu (press the down arrow) and select settings.

  • Open settings from the terminal menu
  • Scroll down to find the guid for the WSL
  • Copy that guid and scroll back up
  • Paste the WSL guid inside the defaultProfile setting

Now every time we run the terminal, the default profile will be the WSL one.

Install and setup zsh and Oh-My-Zsh

The next thing we need to do is installing the zsh shell in our WSL. Open the Windows Terminal (if you haven't it open already) and run the following command:

sudo apt update && sudo apt install zsh -y

This command will install the zsh shell, then we can install oh-my-zsh which is zsh on steroids. It comes with more functions, helpers, plugins, themes and much more.

We can install oh-my-zsh by running the command:

sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

Now that we have the zsh shell and oh-my-zsh installed, we can go to the next step. Customizing your terminal to look beautiful!

Pimp my terminal - Themes, Icons, Profiles

Remember that I said earlier in this article, that the Windows Terminal was pretty simple? Well, it's now time to pimp our terminal and change how it looks! We will do a few things:

  • Install Powerlevel10k
  • Install a font that contains icons
  • Adding the font to Windows Terminal by using Nerd Fonts
  • Choosing a decent theme for the terminal
  • Changing the theme for the terminal

Installing Powerlevel10k

If you are unfamiliar with Powerlevel10k, the quick way to explain it to you is saying that it's a theme for zsh. It allows you to customize your terminal prompt from a set of default styles.

You can read more about Powerlevel10K on the official GitHub repo of the project.

To install Powerlevel10K, you can run this command or read the getting started documentation.

git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/themes/powerlevel10k

Then you will have to edit the ~/.zshrc file to activate the powerlevel10k theme. Look for the line that contains:

ZSH_THEME="robbyrussel"

Replace it with

ZSH_THEME="powerlevel10k/powerlevel10k"

Installing a font pack that contains icons

We need to get a font that contains text and icons on the same pack. Nerd Fonts has a lot of different font styles, all supporting the icons that we need.

The one that I've been using all the time is the DroidSansMono Nerd Font that you can find on the font downloads page. You can also preview some of these fonts on Programming Fonts.

Chose a font that you like, download it and install the font.

Now you need to open your Windows Terminal settings and scroll down to the WSL settings and add the following:

"fontFace": "DroidSansMono NF"

Note: You need to use the same font name as the one shown when you open the .otf file.

So your WSL settings will look like this.

{
    "guid": "{07b52e3e-de2c-5db4-bd2d-ba144ed6c273}",
    "hidden": false,
    "name": "Ubuntu-20.04",
    "source": "Windows.Terminal.Wsl",
    "fontFace": "DroidSansMono NF"
}

Note: your guid will have a unique number, don't copy this section of the code.

Activating Powerlevel10K with the new font

After updating your ~/zshrc file together with using a Nerd Font on the terminal, you should restart your terminal. By restarting the terminal, Powerlevel10K should say that it will try to configure itself, but if that doesn't happen, you can start the configure prompt by running the command:

p10k configure

This will go through a series of questions and styles that you can choose. Select the options to get the style and combination that looks best for your needs.

Updating the Windows Terminal colour scheme

Finally, we want to update the colour scheme of the terminal to look better than just the grey text on a black background.

I recommend this site because it allows you to see in real-time the different colour schemes and you can then click the Get Theme button to get the JSON for that colour scheme.

After you've picked a colour scheme that you like, open the Windows Terminal settings again and locate the line that says schemes: []. In this line, you can paste the colour scheme that you picked.

    "schemes": [
        {
            "name": "Tinacious Design (Dark)",
            "black": "#1d1d26",
            "red": "#ff3399",
            "green": "#00d364",
            "yellow": "#ffcc66",
            "blue": "#00cbff",
            "purple": "#cc66ff",
            "cyan": "#00ceca",
            "white": "#cbcbf0",
            "brightBlack": "#636667",
            "brightRed": "#ff2f92",
            "brightGreen": "#00d364",
            "brightYellow": "#ffd479",
            "brightBlue": "#00cbff",
            "brightPurple": "#d783ff",
            "brightCyan": "#00d5d4",
            "brightWhite": "#d5d6f3",
            "background": "#1d1d26",
            "foreground": "#cbcbf0"
        }
    ],

In my case, I've picked Tinacious Design because that's the theme that I am currently using in VS Code.

To activate the theme, we have to also tell Windows Terminal which profile should use this theme. Going back to the WSL configuration, we can add the following option:

"colorScheme": "Tinacious Design (Dark)"

So our WSL configuration will look similar to this:

{
    "guid": "{07b52e3e-de2c-5db4-bd2d-ba144ed6c273}",
    "hidden": false,
    "name": "Ubuntu-20.04",
    "source": "Windows.Terminal.Wsl",
    "fontFace": "DroidSansMono NF",
    "colorScheme": "Tinacious Design (Dark)"
}

By saving the file, we can see that our terminal already changed colours and it's now using the colour scheme that we want.

Set your WSL as default when opening a new terminal

You might notice that after opening the windows terminal back and forth, that it defaults to the Powershell.

If you are like me and are just using the WSL for all your dev needs, you probably want to set that shell as your default one.

Let's open the terminal settings again and scroll down to your WSL settings.

{
    "guid": "{07b52e3e-de2c-5db4-bd2d-ba144ed6c273}",
    "hidden": false,
    "name": "Ubuntu-20.04",
    "source": "Windows.Terminal.Wsl",
    "fontFace": "DroidSansMono NF",
    "colorScheme": "Tinacious Design (Dark)"
}

Copy your guid and then scroll back up and look for the "defaultProfile" setting. We can then replace that with the WSL guid, in my case I have to change this setting like this:

{
    "defaultProfile": "{07b52e3e-de2c-5db4-bd2d-ba144ed6c273}"
}

Save the file, restart your terminal and you will see that it will open your WSL shell instead of the Windows Powershell.

Setting a default starting directory

The last thing that is worth mentioning on this article, is that, by default, when opening the terminal it starts the shell on mnt/c/Users/<your username>.

If you are happy to have this as your default starting directory, then you are all set. If you would rather change that starting location to the home folder instead, you can open the terminal settings and scroll down to your WSL settings.

We can have a look at the starting directory setting on the Windows Terminal documentation, we have the startingDirectory property that allows us to set the directory that the shell starts in when it's loaded.

Let's update the WSL setting with this startingDirectory property.

{
    "guid": "{07b52e3e-de2c-5db4-bd2d-ba144ed6c273}",
    "hidden": false,
    "name": "Ubuntu-20.04",
    "source": "Windows.Terminal.Wsl",
    "fontFace": "DroidSansMono NF",
    "colorScheme": "Tinacious Design (Dark)",
    "startingDirectory": "\\\\wsl$\\<distro name>\\home\\<username>"
}

Note: Don't copy this as you will have to change the <distro name and <username for your distro of choice and username.

So in my case, I am using Ubuntu 20.04 as my distro and FabioRosado as my username so this setting will become:

"startingDirectory": "\\\\wsl$\\Ubuntu-20.04\\home\\FabioRosado"

An important thing to mention here is that, if you mess up your path somehow it will just put the shell back on mnt/c/Users/<your username> so there are no issues if you make a mistake.

I hope this helps you, if it does or if you have any suggestions feel free to tweet @FabioRosado_


References

Comments (2)

Kevin Cunningham's photo

I don't know if I'll ever do this but it's good to know it can be done.

My journey has been Mac -> Linux -> Mac -> Linux -> Mac. If I ever leave Mac again, I imagine it'll be to Linux :)

Fábio Rosado's photo

Yeah I've been using the Mac for such a long time, but since I built my desktop, I thought it could be a good way to give it a try.

Initially, I was planning to dual-boot with a Linux distro, but WSL is surprisingly good so I kept using windows only haha