5

所以我尝试为 Windows 安装 oh-my-posh

Install-Module oh-my-posh -Scope CurrentUser

并输入

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

谁能帮我?

4

1 回答 1

6

解决方案

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

首先,安装一个书呆子字体:

[如果你已经这样做了,请跳过]

安装 Nerd 字体的说明:

https://docs.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://docs.microsoft.com/en-us/windows/terminal/tutorials/custom-prompt-setup#install-a-nerd-font

...没有提及posh-git模块或Set-Prompt命令(截至 2021 年 12 月 30 日)。

于 2021-12-30T20:46:37.407 回答