尝试安装 oh-my-posh 时,提示“该项术语未被识别为...”。

12

因此,我尝试使用 Install-Module oh-my-posh -Scope CurrentUser 在Windows上安装 oh-my-posh,并输入 Get-PoshThemes 来查看可用的主题并进行下载。但是我收到了以下错误信息。

Get-PoshThemes : The term 'Get-PoshThemes' is not recognized as the name of a cmdlet, function, script file, or
operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try
again.
At line:1 char:1
+ Get-PoshThemes
+ ~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Get-PoshThemes:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

有人能帮帮我吗?


1
安装后,您不应该还需要Import-Module oh-my-posh并将该命令添加到您的$Profile中吗?请参见此链接 - Theo
我也遇到了同样的问题... @Theo Import-Module oh-my-posh 对我没有起作用。这可能是最新版本的问题--我正在使用6.42.3。等我有时间,我会尝试在oh-my-posh GitHub存储库上进行最新提交。 - Robbie Capps
旧的解决方案已经被弃用,请尝试使用此链接:https://ohmyposh.dev/docs/migrating - QMaster
5个回答

14

解决方案

(注意:我正在运行PowerShell 7.1 LTS)

首先,安装Nerd字体:

(如果您已经安装了,则跳过此步骤)

安装Nerd字体的说明:

https://learn.microsoft.com/en-us/windows/terminal/tutorials/custom-prompt-setup#install-a-nerd-font


然后,安装oh-my-posh

1. 安装:posh-git oh-my-posh

   # This first step isn't included in the Microsoft Docs page:
   Install-Module posh-git -Scope CurrentUser
   
   # ...though this one is:
   Install-Module oh-my-posh -Scope CurrentUser

2. ...按照以下步骤操作:

https://github.com/JanDeDobbeleer/oh-my-posh2#installation

3. ...最后,再次尝试该命令:

   # Set the prompt theme (defaults to 'agnoster' for me)
   # ! Note: You have to do this step first (or it still won't work)
   Set-PoshPrompt

   # List the available themes (should work now)
   # ! Note: this will attempt to render a bunch of graphics in your shell
   Get-PoshThemes
   
   # ! Note: use the -List option to avoid a bunch of graphics in your shell
   # This will list the paths to the themes (in plaintext):
   Get-PoshThemes -List

可选项

为了避免手动输入 Set-PoshPrompt 命令,在您的 PowerShell $PROFILE 中包含该命令:

    # ...e.g. to use the included 'zash' theme:
    Set-PoshPrompt zash

当你打开一个启动的shell实例(即新的PowerShell选项卡或窗口)时,你应该看到你的PowerShell提示符发生了改变。


总结(附注)

在我使它工作之前,我最初按照这里的说明进行操作:

https://learn.microsoft.com/en-us/windows/terminal/tutorials/custom-prompt-setup#install-a-nerd-font

截至2021年12月30日,没有提到posh-git模块或Set-PoshPrompt命令。


你好,我先按照微软的指南,然后是你的(以及GitHub上的)指南,但对我来说都不起作用。当尝试运行Set-Prompt时,我只会收到一个错误:未将“Set-Prompt”识别为cmdlet的名称。有什么提示可以处理这个问题吗? - GKroch
@GKroch 你所说的 Set-Prompt 是指 Set-PoshPrompt 吗?抱歉,我的回答中有一个打字错误(现已更正)。 - Robbie Capps

1
尝试使用refreshenv。这对我有效。

0

我一直在按照Robbie的指南操作,但仍然收到“cmdlet未找到”错误。不知何故,重新安装并没有解决我的问题,但更新却解决了:

Update-Module oh-my-posh

0
我跟着ohmyposh的文档操作,它对我起作用了。

1
你到底是从中间哪部分开始看的?你是指特定的部分还是整个内容?另外请参考https://meta.stackexchange.com/a/8259/997587。 - starball
请提供对问题的适当解决方案。 - Hrishikesh
虽然这个链接可能回答了问题,但最好在这里包含答案的关键部分,并提供链接作为参考。仅有链接的答案如果链接页面发生变化,就可能失效。- 来自评论 - ryanwebjackson

-1

您可以以管理员权限启动vs code,这样问题就会得到解决。 我正在使用oh-my-posh版本14.29.1


这只是一个解决方法,而不是安全的方法。如果你犯了错误或者你的个人资料被攻击,那么就会显著减少保护措施来防止“坏事情”发生。如果你按照oh-my-posh的安装说明操作,它是有效的。 - Jeter-work

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