How to Install Oh My Posh on Windows

📜Part of the PowerShell Complete Guide, every PowerShell post on this site, grouped by the job you are doing.

Oh My Posh is a prompt theme engine: it turns your PowerShell prompt into one that shows the folder, the Git branch and status, whether the last command failed, and more. To set it up on Windows: install it with winget, install a Nerd Font, then add one line to your PowerShell profile.

If you followed an older guide that used Set-Theme, that was Oh My Posh version 2, the PowerShell module, which this post originally covered. That module is deprecated and Set-Theme is not part of the current version. Everything below is the current way.

Install Oh My Posh

PowerShell
winget install JanDeDobbeleer.OhMyPosh -s winget

Close and reopen your terminal afterwards so the new oh-my-posh command is on your PATH.

choco install oh-my-posh in 2020

Close and reopen your terminal afterwards so the new oh-my-posh command is on your PATH.

Install a Nerd Font

Most themes use icons that only show in a Nerd Font, otherwise you get empty boxes. Oh My Posh can install one for you:

PowerShell
oh-my-posh font install meslo

Then set it in Windows Terminal: Settings > Profiles > Defaults > Appearance > Font face, and pick MesloLGM Nerd Font.

Turn It On in Your Profile

PowerShell
# open your PowerShell profile (creates it if it does not exist)
if (-not (Test-Path $PROFILE)) { New-Item -Path $PROFILE -ItemType File -Force }
notepad $PROFILE

Add this line to the profile, save it, and open a new PowerShell window:

PowerShell
oh-my-posh init pwsh | Invoke-Expression

More on finding and editing the profile is in Find and Edit Your PowerShell Profile. If the new window says running scripts is disabled, the execution policy is blocking your profile: Fix “.ps1 cannot be loaded”.

Pick a Theme

The themes ship with Oh My Posh. To use one, point the same line at its file, here the Zash theme I used in 2020:

PowerShell
oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH\zash.omp.json" | Invoke-Expression

Here is Zash as it looked when I first set it up, with the Git status segments showing in a repository:

The Zash theme in Windows Terminal in 2020, set with the old Set-Theme command, which the current version replaces with oh-my-posh init
The Zash theme showing Git branch and status in a repository

All the themes, with previews, are in the Oh My Posh theme gallery. Git status in the prompt works on its own now, so posh-git is no longer needed for it, though it is still worth having for Git tab completion: How to Install posh-git on Windows.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *