如何在 Powershell 5.1 中为 Oh My Posh 安装主题?

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

我每天在 Windows 终端中使用 Powershell 5.1。然而,几天后,我的 Oh My Posh 主题停止工作,并打印出一个错误,说它找不到我想要的主题 (iterm2),并退回到默认主题。

我已删除 (Remove-Module -Name oh-my-posh -Force) 并重新安装 (Install-Module -Name oh-my-posh -Scope CurrentUser) Oh My Posh,但这并没有解决问题。如何解决?

谢谢

我也遇到过。我通过在正确的位置手动下载主题来修复它。

如果你想让它变得简单,我创建了一个 powershell One-Liner 来修复它:

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"}

它使用 GH API 获取当前可用主题的列表,然后使用一些 PowerShell 魔法将它们下载到正确的位置。

手动下载主题后,您还可以查看环境变量“POSH_THEMES_PATH”

应该是“$home\Documents\WindowsPowerShell\Modules\oh-my-posh\themes”

您可以通过以下方式查看:

echo $env:POSH_THEMES_PATH

您可以通过以下方式更改它:

$env:POSH_THEMES_PATH = "path"