Command line improvements in PowerShell, WSL, Windows Terminal and VS Code

Mikhail Danshin
7 min readMar 13, 2022

Recently it has become fashionable to use the extended command line in PowerShell or bash/zsh. In this article, I’ll show you what you need to do in PowerShell, WSL, Windows Terminal, and VS Code to customize the command line and take full advantage of it.

Long story short or action plan

  1. Installing the Nerd Font
  2. Installing and configuring Oh My Posh for PowerShell
  3. Installing and configuring Oh My Posh for WSL
  4. Configure Windows Terminal to Display Glyphs Correctly
  5. Configure Windows VS Code to Display Glyphs Correctly

Installing the Nerd Font

The picture above shows different themes of the command line. There are many themes, and you can modify them and create your own. As you can see, almost all variants contain glyphs (graphic symbols). If the font used in the terminal does not contain the appropriate glyphs, replacement characters such as a square — ▯ or a question mark � may appear on the command line. To display all glyphs in the terminal, you must first install the Nerd font from the project website https://www.nerdfonts.com/.

After looking at several fonts, I settled on Caskaydia Cove Nerd Font.

All fonts can be viewed and downloaded at https://www.nerdfonts.com/font-downloads.

After downloading the desired font, you need to install it. Go into the archive, select the desired font and open it.

And then, in the window that opens, click the Install button.

The font is installed, you can proceed to the next step — installing Oh My Posh.

Installing and configuring Oh My Posh for PowerShell

Oh My Posh is a custom prompt engine for any shell that has the ability to adjust the prompt string with a function or variable.

To use this engine in PowerShell, you need to install and import the PowerShell module.

Check you ExecutionPolicy first. Make sure that is not set to Restricted. To run remote script you need set ExecutionPolicy to RemoteSigned at least.

Set-ExecutionPolicy RemoteSigned

To install the Oh My Posh module, run this command.

Install-Module oh-my-posh -Scope CurrentUser

If the NuGet package manager is not already installed, PowerShell will ask for permission. Type Y and press Enter.

Next, you will be warned that you are suggesting installing a module from an untrusted PSGallery repository. It’s normal. Type Y and press Enter.

Update the PowerShell profile. The easiest way to do it is to run the following command.

notepad $PROFILE

If the file does not exist you will receive warning. Click Yes on the dialog box.

Add the next snippet at the end of the file. Instead of jandedobbeleer, you can use the name of another theme. I chose this one.

Import-Module oh-my-posh 
Set-PoshPrompt -Theme jandedobbeleer

Save and close the file and launch a new PowerShell window.

For the first time after starting PowerShell, you can see the process of importing the previously installed Oh My Posh module. All subsequent launches of PowerShell will proceed as usual.

After starting PowerShell, you will see command line as shown in the picture below. Please note that not all characters are displayed correctly. This is because the PowerShell terminal is currently using a font that does not support glyphs.

To fix it, go to the PowerShell terminal settings and select the glyph-enabled font you installed earlier. Or install it now if you skipped this step.

As soon as you set the desired font, you will see the correct display of the command line.

Installing and configuring Oh My Posh for WSL

To install Oh My Posh on WSL, we need the Homebrew package manager. So first start WSL and install Homebrew there by running the following command and follow the instructions in the terminal window.

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

When Homebrew will be installed, run follow next instructions to add Homebrew to your PATH and to your bash shell profile script.

test -d ~/.linuxbrew && eval "$(~/.linuxbrew/bin/brew shellenv)" test -d /home/linuxbrew/.linuxbrew && eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)" test -r ~/.bash_profile && echo "eval \"\$($(brew --prefix)/bin/brew shellenv)\"" >> ~/.bash_profile echo "eval \"\$($(brew --prefix)/bin/brew shellenv)\"" >> ~/.profile

Once Homebrew is installed and configured, you’re ready to install Oh My Posh. Run the following commands.

brew tap jandedobbeleer/oh-my-posh 
brew install oh-my-posh

Now you need to download and unpack the themes.

mkdir -p $(brew --prefix)/oh-my-posh/themeswget https://github.com/JanDeDobbeleer/oh-my-posh/releases/latest/download/themes.zip -O $(brew --prefix)/oh-my-posh/themes/themes.zipunzip $(brew --prefix)/oh-my-posh/themes/themes.zip -d $(brew --prefix)/oh-my-posh/themeschmod u+rw $(brew --prefix)/oh-my-posh/themes/*.jsonrm $(brew --prefix)/oh-my-posh/themes/themes.zip

Copy the theme file to your home directory.

cp $(brew --prefix)/oh-my-posh/themes/jandedobbeleer.omp.json ~/jandedobbeleer.omp.json

And then run oh-my-posh.

test -e ~/jandedobbeleer.omp.json && eval "$(oh-my-posh --init --shell bash --config ~/jandedobbeleer.omp.json)"

You will see that the command line has changed. If it is not displayed correctly, then change the font in your terminal settings, as mentioned earlier.

Now the installation and configuration of Oh My Posh for WSL is completed.

Setting Windows Terminal to Display Glyphs Correctly

After starting Windows Terminal, you will need to change the font, otherwise the command line will not display glyphs.

To fix this, go to the Windows Terminal settings, select the Default profile, and on the Appearance tab, set the desired font. Then click Save and open a new terminal window.

This time the command line will show glyphs, but there is one problem. When opening a WSL terminal, the first command line appears with a defect. It contains gaps. I didn’t understand why this is happening. If you will press enter, then the next line will be displayed normally.

I couldn’t think of anything better than adding a clear screen command to the .profile file so that it runs every time a session is executed. You can also do it by running the next command.

echo "clear" >> ~/.profile

Now, if you reopen the terminal, everything will look as it should.

Setting Windows Terminal is finished.

Setting VS Code to Display Glyphs Correctly

If you open VS Code and open Terminal in it, you will see that the glyphs in it also do not display correctly. It’s all about the font settings.

Go to settings, select Terminal, scroll down to Integrated: Font Family and enter the name of your font. In my case, this is CaskaydiaCove NF. The full name of the setting is terminal.integrated.fontFamily, you can type it into the settings search bar to quickly navigate to it.

If you’re using the Remote — WSL plugin in VS Code, there’s one more advice that might come in handy. When you open a new session in WSL in VS Code, you will notice that nothing has changed there. VS Code, when running bash in WSL, does not read data from the .profile file.

To fix this, you can enter the command

bash -l

But instead of doing it manually every time, let’s change the VS Code configuration.

To the existing settings, add the following.

"terminal.integrated.defaultProfile.linux": "bash",
"terminal.integrated.profiles.linux": {
"bash": {
"path": "bash",
"args": [
"-l"
]
}
}

Save and restart your WSL session. This time you should have everything displayed correctly.

That’s all I wanted to share in this article. Leave your comments and feedback. Peace and goodness to all!

--

--

Mikhail Danshin

DevOps Engineer, Linux System Administrator, C#, Javascript and React full stack programmer.