Windows配置oh-my-posh
概要: 配置堪比 oh-my-zsh 的Windows PWSH神器,oh-my-posh
创建时间: 2022.03.20 13:58:30
更新时间: 2023.08.16 22:33:25
注意:以下命令均在Windows Terminal的powershell环境下执行,建议首先配置好Scoop环境
安装oh-my-posh
oh-my-posh近期的安装方式有变化,详见 PowerShell module | Oh My Posh
使用 Scoop 工具
安装
PowerShell |
---|
| scoop install https://github.com/JanDeDobbeleer/oh-my-posh/releases/latest/download/oh-my-posh.json
|
升级
使用 Winget 工具
安装
PowerShell |
---|
| winget install JanDeDobbeleer.OhMyPosh -s winget
|
更新
PowerShell |
---|
| winget upgrade JanDeDobbeleer.OhMyPosh -s winget
|
安装字体
需要先使用 Scoop 工具安装 sudo 软件包,以便在终端中调起Windows的管理员提权对话框
然后选择字体安装
PowerShell |
---|
| sudo oh-my-posh font install
|

创建/修改powershell启动配置文件
PowerShell |
---|
| if (!(Test-Path -Path $PROFILE )) { New-Item -Type File -Path $PROFILE -Force }
notepad $PROFILE
|
安装powershell必要的包
PowerShell |
---|
| Install-Module posh-git -Scope CurrentUser -Force -AllowClobber
|
写入如下内容,以在启动powershell时应用oh-my-posh环境
PowerShell |
---|
| Import-Module posh-git
oh-my-posh init pwsh --config ~/.custom.omp.json | Invoke-Expression
|
效果如下
使用oh-my-posh
查看当前shell
显示所有可用的主题以及效果
设置主题
此处我们将omp的主题文件统一放到 ~/.config/oh-my-posh/themes
文件夹中,使用 ys
主题作为默认
PowerShell |
---|
| mkdir -p ~/.config/oh-my-posh/themes
cd ~/.config/oh-my-posh/themes
wget https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/ys.omp.json
oh-my-posh init pwsh --config ~/.config/oh-my-posh/themes/ys.omp.json | Invoke-Expression
|
查看主题路径
参考
- 主页:Introduction | Oh My Posh
- 安装指引:PowerShell module | Oh My Posh
- Windows配置:Windows | Oh My Posh
- 主题文件:oh-my-posh/ys.omp.json at main · JanDeDobbeleer/oh-my-posh · GitHub
- Windows Terminal美化+PowerShell插件配置 - DiaosSama's Blog
- JanDeDobbeleer/oh-my-posh: A prompt theme engine for any shell.
- Windows Terminal - PowerShell customization via oh-my-posh/posh-git Set-Theme error? · Issue #9237 · microsoft/terminal