Customizing the Windows Terminal command prompt with Oh-My-Posh

Last updated on

powershell

While I use Zsh with Oh-My-Zsh for making my Linux terminal pretty, it's not available for Windows. Luckily it's brother from another mother Oh-My-Posh basically does the same thing for Windows Terminal and PowerShell.

Oh My Posh

Sections

  1. Pre-Requisites
  2. Installing WinGet and using it to install Oh-My-Posh
  3. Changing the theme
  4. Install a Nerd Font for themes that require it
  5. Additional non-bundled custom themes
  6. References

Pre-Requisites

You need to have PowerShell installed on Windows, and ideally you’ll want to use Windows Terminal as well. Follow the official Microsoft instructions to install PowerShell. For Windows Terminal, you’ll have to install it from the Windows Store.

The rest of this guide will assume you are using Windows Terminal.

Installing WinGet and using it to install Oh-My-Posh

If you have Windows 11 or Windows 10 Pro, you should already have the WinGet package manager installed, if not you’ll have to install App Installer which comes with WinGet.

We’ll be using WinGet in Windows Terminal to install Oh-My-Posh, as this is the official preferred method. Do so with this command:

winget install JanDeDobbeleer.OhMyPosh -s winget

Next we’ll make Oh-My-Posh the default shell, which requires editing your PowerShell profile. It should be located in at the following directory:

%userprofile%\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1

If the the profile does not exist, create it with the command New-Item -Path $PROFILE -Type File -Force. Edit the profile as an Administrator with the text editor of your choice. Add the following to the top:

oh-my-posh init pwsh | Invoke-Expression

Restart your terminal or reload the profile with the command . $PROFILE for changes to take effect.

Changing the theme

Once you have installed Oh-My-Posh, the default theme will be used. Use the following command to list all the themes and get a preview of how they’ll look in the terminal. (Give it a minute, there’s a lot of them.)

Get Posh-Themes

The themes will all located in the following directory:

%userprofile%\AppData\Local\Programs\oh-my-posh\themes\

Let’s assume you decided to use the unicorn theme (one of my favorites), you’ll have to edit your Microsoft.PowerShell_profile.ps1 and replace the init script with this:

oh-my-posh init pwsh --config '%userprofile%\AppData\Local\Programs\oh-my-posh\themes\unicorn.omp.json' | Invoke-Expression

Reload the terminal again with . $PROFILE for the change to take effect.

Install a Nerd Font for themes that require it

You may notice that some themes cause weird missing icons in your prompt. This is because many of them require Nerd Fonts. Oh-My-Posh has a built-in CLI and pick out and install a Nerd Font. Any of them will work, but the official recommended font to use is MesloLGM.

Use the following command and pick out a font of your choice:

oh-my-posh font install

Next you’ll need to open Windows Terminal, go to Settings, and under Profiles click on Windows PowerShell, scroll down to Additional Settings and click Appearance, then change Font face to the Nerd Font you downloaded. Make sure to Save your changes.

To ensure the glyphs are correctly rendered, you’ll also want to go into Windows Terminal Settings, click on Rendering and switch on Use the new text renderer (“AtlasEngine”). If you’re noticing the symbols in some themes are not spaced properly and are right on top of text, be sure you do this step.

Custom themes not bundled with Oh-My-Posh

Oh-My-Posh comes with many themes that are regularly maintained, but anyone can create a custom theme. Here’s a few I’ve found on GitHub that I like.