提示符美化
下载Windows Terminal
在Microsoft商店中就可以下载,可以设置背景图片,更改字体,添加命令配置文件等,这里省略,自行摸索更有趣😁
下载字体
首先得下载字体,Windows自带的不支持下面的主题格式
这里推荐下载:MesloLGS NF
这个字体可以直接在Windows Terminal中使用powershell,但是直接运行powershell会有问题
下载路径如下:
以上4个下载好了以后,依次双击运行,点击安装即可(安装完以后就可以删除文件了)
安装Oh My Posh主题
这里推荐使用winget安装
winget install oh-my-posh
输入如下命令打开$Profile文件
# 如果之前没有配置文件,就新建一个 Powershell 配置文件
if (!(Test-Path -Path $PROFILE )) { New-Item -Type File -Path $PROFILE -Force }
# 打开配置文件,优先使用 vscode ,其次会使用记事本打开
notepad $PROFILE
若是以上命令打不开的话,可以去以下路径直接打开Microsoft.PowerShell_profile.ps1文件进行编辑
也就是你的文档文件夹中的Powershell文件夹中
C:\Users\用户名\Documents\PowerShell
然后在$Profile中添加如下命令
oh-my-posh init pwsh | Invoke-Expression
修改完后重启Windows Terminal即可使用oh-my-posh
的命令了
更改字体
先更改字体,不然等下的预览效果不好
打开Windows Terminal,按快捷键ctrl+,打开设置,选择左边的powershell ->然后选择外观 ->选择字体为刚刚下载的 -> MesloLGS NF
查看可选主题
Get-PoshThemes
以下就是预览的主题
更改主题
选择刚刚查看的一款自己喜欢的主题,然后将它的名字复制到如下命令中
在之前的文件中的oh-my-posh init pwsh ... 的部分後面加上 --config "$env:POSH_THEMES_PATH\{主題名稱}.omp.json"
例如:
oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH\paradox.omp.json" | Invoke-Expression
重启Windows Terminal即可看到效果
踩坑记录
之前安装用的命令是:
Install-Module oh-my-posh -Scope CurrentUser
但是会出现如下错误:
Hey friend
In an effort to grow oh-my-posh, the decision was made to no
longer support the PowerShell module. Over the past year, the
added benefit of the module disappeared, while the burden of
maintaining it increased.
However, this doesn't mean oh-my-posh disappears from your
terminal, it just means that you'll have to use a different
tool to install it.
All you need to do, is follow the migration guide here:
https://ohmyposh.dev/docs/migrating
解决方案:
删除过去的版本,打开pwsh输入:
Uninstall-Module oh-my-posh -AllVersions
然后按照以上的方法安装
注意:我用的是powershell7,安装好后,按win+r后输入pwsh即可运行
若想安装,可下载:
PowerShell7.3.0
下载后直接运行即可安装,默认路径是:
C:\Program Files\PowerShell
参考:https://www.kwchang0831.dev/dev-env/pwsh/oh-my-posh