Home > Back-end >  How to install themes for Oh My Posh in Powershell 5.1?
How to install themes for Oh My Posh in Powershell 5.1?

Time:12-12

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

CodePudding user response:

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.

  • Related