Skip to Content
OSWindowsoh-my-posh

使用 oh-my-posh 配置 Windows Terminal prompt

这里只保留 oh-my-posh 相关配置。PowerShell 版本、Terminal / VS Code 字体、启动优化、 模块和 alias 放在 PowerShell profile

安装 oh-my-posh

如果有杀毒软件误报毒的情况可以看看下面官方文档怎么解决的。

https://ohmyposh.dev/docs/installation/windows 

# 安装 oh-my-posh winget install JanDeDobbeleer.OhMyPosh -s winget
# 更新 oh-my-posh winget upgrade JanDeDobbeleer.OhMyPosh -s winget

配置 oh-my-posh

配置字体 fonts

这里按官方推荐字体安装 Meslo。

https://ohmyposh.dev/docs/installation/fonts 

oh-my-posh font install meslo

配置提示 prompt

因为我 WT 用的是 powershell,所以这里只给出了 powershell 的配置,其他的看下面官方文档

https://ohmyposh.dev/docs/installation/prompt 

# 使用记事本打开 powershell 的配置文件 # if the profile file does not exist, create it if (-not (Test-Path $profile)) { New-Item $profile -Force } # Open the profile file in notepad notepad $PROFILE

在配置文件内添加一行,让 powershell 每次打开都自动配置 oh-my-posh

oh-my-posh init pwsh | Invoke-Expression

如果后面切到 Starship,就把这行注释掉或者删掉,避免两个 prompt 同时初始化。

配置主题 themes

可以在这里 看到所有的主题

我喜欢和 Linux / Mac 上保持一致,还是用 powerlevel10k 的主题。把下面这行放到 powershell 的配置文件内,每次打开 shell 时自动加载主题。

notepad $PROFILE oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH/powerlevel10k_rainbow.omp.json" | Invoke-Expression
# 如果安装主题的时候报了下面的错误,可以运行下面的命令 # Get-PSReadLineKeyHandler : A positional parameter cannot be found that accepts argument 'Spacebar'. Install-Module PsReadLine -Force # 然后重新打开一遍 Windows Terminal,再装一遍主题
Last updated on