Use Oh-My-Posh to Polish Your Windows Terminal

目前你用简体中文搜索到 Oh My Posh 安装方法大概都用了这一条命令:Import-Module oh-my-posh

事实上这种方式已经不再被 Oh My Posh 官方支持了,当然你可以用这个方法安装,只不过每次打开你的 Windows Terminal 都会弹出一大串提示信息,官方已经在网站上说明了

https://ohmyposh.dev/docs/migrating

Installation

Windows 直接用 winget 安装就行了。运行下面这条命令,过一会就装上了。如果长时间没反应,那就是网络问题了。

winget install JanDeDobbeleer.OhMyPosh -s winget

Configuration

安装完成之后需要运行一次下面的命令初始化:

oh-my-posh init pwsh | Invoke-Expression

接下来是更换主题,以往我们需要自行修改 oh-my-posh 使用的 json 文件,但是现在可以在 Terminal 里面直接输入 Get-PoshThemes 来查看可用的主题。oh-my-posh 会将其仓库中所有的主题配置文件下载到本地。

 oh-my-posh init pwsh --config 'C:\Users\austie\AppData\Local\Programs\oh-my-posh\themes\jandedobbeleer.omp.json' | Invoke-Expression

接下来只要将jandedobbeleer替换成你想要的主题名称就可以了。

部分主题需要我们使用支持 glyphs 的字体,如 FiraCode Nerd Font。 设置过程如下: Windows Terminal - PowerShell - 外观 - 字体 - 选择 FiraCode Nerd Font。