Installing oh-my-posh using winget

Joseph GanJoseph Gan
3 min read

This is a follow-up blog post to a previous article on enhance your developer experience with Windows Terminal and PowerShell, specifically with regard to the setup of oh-my-posh

Based on the website, the recommended way now is to use winget to install oh-my-posh

winget is a Windows Package Manager to enables users to discover, install, upgrade, remove and configure applications on Windows 10 and Windows 11 computers

Uninstall

First, let's get rid of the old configuration and setup done previously

  • Launch Powershell

  • Run Remove-Item $env:POSH_PATH -Force -Recurse

  • Run Uninstall-Module oh-my-posh -AllVersions

  • Run code $PROFILE

    • This will launch your PowerShell profile on VSCode
  • Remove the following from your profile

    • Import-Module oh-my-posh line

    • Set-PoshPrompt night-owl

      • Or any profile you have defined previously, in my case, it was night-owl
  • Remove %USERPROFILE%\.oh-my-posh from your PATH environment variable

Now, re-launch your PowerShell, it should look plain now

image.png


Installation

Now that we have removed it, we need to set up oh-my-posh again

  • Launch PowerShell

  • Run winget install JanDeDobbeleer.OhMyPosh -s winget

image.png

  • Restart PowerShell terminal

  • Run oh-my-post --version

    • Your version will differ from mine, depending on when you install it
PS C:\Users\Joseph> oh-my-posh --version
12.13.1

Now that oh-my-posh is installed, we have to instruct PowerShell to use it

  • Run code $PROFILE

  • Add oh-my-posh init pwsh | Invoke-Expression to the last line of your $PROFILE

image.png

What about setting up the theme? It's quite straight forward, upon installation of oh-my-posh, it also set up an environment variable POSH_THEMES_PATH to point to the location of the themes.

  • Replace oh-my-posh init pwsh | Invoke-Expression with oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH\night-owl.omp.json" | Invoke-Expression in your $PROFILE

Replace night-owl.omp.json with your preferred theme

image.png image.png

Your theme is now back!

bashrc

If you have set for .bashrc previously, you might need to update the path

// from
eval "$(oh-my-posh --init --shell bash --config ~/.oh-my-posh/themes/night-owl.omp.json)"

// to
eval "$(oh-my-posh --init --shell bash --config ~/AppData/Local/Programs/oh-my-posh/themes/night-owl.omp.json)"

WSL

If you have set for WSL (previously)

  • Launch your terminal

  • Run

sudo wget https://github.com/JanDeDobbeleer/oh-my-posh/releases/latest/download/posh-linux-amd64 -O /usr/local/bin/oh-my-posh
sudo chmod +x /usr/local/bin/oh-my-posh

And if you are using zsh within your WSL, remember to update your .zshrc config as well

zshrc

# use vim if you like
nano ~/.zshrc
# place this at the end of the file
# we are referencing to our theme in Windows path
# switch the username to yours
eval "$(oh-my-posh --init --shell zsh --config '/mnt/c/Users/Joseph/AppData/Local/Programs/oh-my-posh/themes/night-owl.omp.json')"
// Reload profile
exec zsh

If you face this error Error: unknown flag: --millis

image.png

This is likely that your configuration is wrong, ensure you point to the correct path in your shell (e.g zsh) config

That should be it. Enjoy your newly setup terminal!

0
Subscribe to my newsletter

Read articles from Joseph Gan directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Joseph Gan
Joseph Gan

Advocate for better developer's productivity and experience Documenting my learnings and sharing it