DEV Community

Chiranjib
Chiranjib

Posted on

Beautify WSL2 terminal with ohmyposh

Read on if you

  • Are using the combination: Windows, WSL2, Ubuntu
  • Don't like the look and feel of the limited terminal
  • Like me, aren't yet using Windows Terminal for some inexplicable reason

Prerequisites

  • Have a computer that runs Windows OS (Mine is Windows 10)
  • Enable WSL2 -> Here's how, if you need it
  • A little tech knowledge about how these things work, just enough to make small changes and understand what's going on

Step 1: Installation

Open Ubuntu in WSL and download oh-my-posh. Oh My Posh is a prompt theme engine for your shell (I, being a simpleton, am using bash). Their somewhat detailed installation instructions enable you to download and set it up smoothly.

Once the installation has completed, let's take small steps towards enabling it. Let's edit the ~/.bashrc file to ensure that it loads when we start.

export PATH=$PATH:~/.local/bin
if [ -f $(which oh-my-posh) ]; then
  eval "$(oh-my-posh init bash)"
fi
Enter fullscreen mode Exit fullscreen mode

Let's see what we just did:

  • assuming that oh-my-posh got installed in the location ~/.local/bin, we are ensuring that it's loaded in the PATH. This is necessary to be able to invoke the command itself.
  • since we are using bash, we invoked the command oh-my-posh init bash at startup, so that things are nice and pretty for us to use from the start.

Step 2: Selecting a theme

Discover all the ohmyposh themes that you can choose from, and download the file from the link provided there or just pick one from the list here: https://github.com/JanDeDobbeleer/oh-my-posh/tree/main/themes

Let's assume we have downloaded the necessary theme .json files in the directory ~/.poshthemes.

Let's now modify the file ~/.bashrc to pick the theme up as shown below:

if [ -f $(which oh-my-posh) ]; then
  eval "$(oh-my-posh init bash --config ~/.poshthemes/jandedobbeleer.omp.json)"
fi
Enter fullscreen mode Exit fullscreen mode

Step 3: Installing a Nerd Font

Oh My Posh requires a Nerd Font to work. So, explore all the nerd fonts, have your pick, and download the font to your windows system. Once, the font is downloaded, navigate to the font location, right click, and click Install.

Once installed, verify that the font is visible in the list of fonts: Win + R, type fonts. I went with Inconsolata.

Verifying the installed font

Step 4: Configure the installed font

As a final step, we need to configure the emulator, that is used by Windows. Launch Command Prompt or Ubuntu App, right click on the toolbar, click Properties. This should allow you to select the installed font. One easy to miss detail is that CMD works with Monospaced fonts only. So, the font that you had chosen, ensure that you've installed the Mono variant.

Choosing the installed Mono font

Top comments (0)