Windows终端 - 通过oh-my-posh/posh-git进行PowerShell定制时出现Set-Theme错误?

10

Windows 终端 - 通过 oh-my-posh/posh-git 设置主题时出现错误?

我按照微软链接的精确教程进行操作:enter link description here,视频链接:enter link description here

我已经通过以下代码安装了 Posh-Git 和 Oh-My-Posh:

Install-Module posh-git -Scope CurrentUser

Install-Module oh-my-posh -Scope CurrentUser

我也通过以下代码安装了 PSReadLine:

Install-Module -Name PSReadLine -Scope CurrentUser -Force -SkipPublisherCheck

我还在 PowerShell 配置文件中创建了 Microsoft.PowerShell_profile.ps1 文件,并复制/粘贴了此代码:

Import-Module posh-git
Import-Module oh-my-posh
Set-Theme Paradox
但是我遇到了这个错误:enter image description here

请不要上传代码/错误/数据的图片。为什么?看这里...为什么在提问时不能上传代码/错误的图片?- Meta Stack Overflow - https://meta.stackoverflow.com/questions/285551/why-not-upload-images-of-code-errors-when-asking-a-question - Lee_Dailey
2个回答

31

Set-Theme 是一个 oh-my-posh V2 的 cmdlet;你可能正在运行 V3。如果你正确地按照了其余的设置,你可以简单地用 Set-PoshPrompt -Theme Paradox 替换 Set-Theme Paradox

更多信息请参见:https://ohmyposh.dev/docs/installation/windows#update


1
CoolBots,感谢您的完美回答。点赞。 @Nihal Towfiq,我认为您需要接受这个答案。 - manu

2
尝试以下步骤:
  1. 首先,请确保您使用的是管理员shell,并通过powershell.exe(或Windows终端)进行安装。

  2. 安装Powershell GetPowershell Get MS

PowerShell Gallery 是 PowerShell 内容的中央仓库。在其中,您可以找到有用的 PowerShell 模块,包含 PowerShell 命令和 Desired State Configuration (DSC) 资源。

Install-Module -Name PowerShellGet -Force
  1. 安装PS Readline PS Readline GitHub

此模块替换了版本为3及以上的PowerShell的命令行编辑体验。它提供:语法着色;简单的语法错误和更多功能(请查看上面的链接)。

Install-Module PSReadLine
  1. 现在,将您的执行策略更改为Bypass。了解更多信息,请单击此处

执行策略是 PowerShell 安全策略的一部分。执行策略决定您是否可以加载配置文件,例如您的 PowerShell。

Set-ExecutionPolicy Bypass

3.1 检查您的执行策略:

Get-ExecutionPolicy
  1. 最后,尝试或重新安装你的oh-my-posh。在这里链接oh-my-posh:这里
Install-Module oh-my-posh -Scope AllUsers

在替换现有提示符之前,请编辑您首选的PowerShell版本中的$PROFILE并添加以下行。自动完成可用,因此它将循环遍历所有可用的主题。

如果您有VSCode 4.1

Code $PROFILE

4.2 and write

Set-PoshPrompt -Theme 'posh-theme-here'

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接