How to install themes for Oh My Posh in Powershell 5.1?

2.2k Views Asked by At

I use Powershell 5.1 daily in Windows Terminal. However, since a few days, my Oh My Posh theme stopped working, and printed an error that said it couldn't find the theme that I wanted (iterm2), and falled back to a default theme.

I have removed (Remove-Module -Name oh-my-posh -Force) and reinstalled (Install-Module -Name oh-my-posh -Scope CurrentUser) Oh My Posh, but this hasn't fixed the problem. How to solve ?

Thanks

2

There are 2 best solutions below

0
On BEST ANSWER

It also happened to me. I got it fixed by manually downloading the themes in the right place.

If you want to make it easy, I created a powershell One-Liner that fixes it:

New-Item -Path "$home\Documents\WindowsPowerShell\Modules\oh-my-posh" -Name "themes" -ItemType Directory; Set-Location -Path "$home\Documents\WindowsPowerShell\Modules\oh-my-posh\themes"; Invoke-WebRequest -UseBasicParsing -Uri https://api.github.com/repos/JanDeDobbeleer/oh-my-posh/contents/themes | Select-Object -ExpandProperty Content | ConvertFrom-Json | ForEach-Object {$_ | Select-Object -ExpandProperty name | Select-String -Pattern ".*.omp.json"} | ForEach-Object {$_.toString().Replace(".omp.json", "")} | ForEach-Object {Invoke-WebRequest -Uri "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/$_.omp.json" -UseBasicParsing -OutFile "$_.omp.json"}

It uses the GH API to get the list of currently available themes, then downloads them in the right place with a bit of PowerShell magic.

0
On

After download themes manually, you can also check env variable "POSH_THEMES_PATH"

it should be "$home\Documents\WindowsPowerShell\Modules\oh-my-posh\themes"

You can check it by:

echo $env:POSH_THEMES_PATH

You can change it by:

$env:POSH_THEMES_PATH = "path"