解决方案
(注意:我正在运行 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 日)。