Installing oh-my-posh using winget

Advocate for better developer's productivity and experience
Documenting my learnings and sharing it
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
wingetis 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
PowershellRun
Remove-Item $env:POSH_PATH -Force -RecurseRun
Uninstall-Module oh-my-posh -AllVersionsRun
code $PROFILE- This will launch your PowerShell profile on
VSCode
- This will launch your PowerShell profile on
Remove the following from your profile
Import-Module oh-my-poshlineSet-PoshPrompt night-owl- Or any profile you have defined previously, in my case, it was
night-owl
- Or any profile you have defined previously, in my case, it was
Remove
%USERPROFILE%\.oh-my-poshfrom yourPATHenvironment variable
Now, re-launch your PowerShell, it should look plain now

Installation
Now that we have removed it, we need to set up oh-my-posh again
Launch
PowerShellRun
winget install JanDeDobbeleer.OhMyPosh -s winget

Restart
PowerShellterminalRun
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 $PROFILEAdd
oh-my-posh init pwsh | Invoke-Expressionto the last line of your $PROFILE

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-Expressionwithoh-my-posh init pwsh --config "$env:POSH_THEMES_PATH\night-owl.omp.json" | Invoke-Expressionin your $PROFILE
Replace
night-owl.omp.jsonwith your preferred theme

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

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!




