Skip to content
夏天的风
Go back

Windows 配置 Oh My Posh

安装

通过 scoop 安装

scoop install oh-my-posh

官网安装

Set-ExecutionPolicy Bypass -Scope Process -Force; Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://ohmyposh.dev/install.ps1'))

生效配置,执行 notepad $PROFILE,添加以下内容

oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH\M365Princess.omp.json" | Invoke-Expression

如果 notepad $PROFILE 提示找不到文件,则执行

New-Item -Path $PROFILE -Type File -Force

配置

1. 安装字体

通过网站 Nerd Font 下载字体,这里选用的是 CaskaydiaMono Nerd Font

安装后在 Windows Terminal 中配置为该字体,设置->配置文件->默认值->外观->字体,上面选择的是 CaskaydiaMono NFM

2. posh-git

通过 scoop 安装

scoop install posh-git

执行 notepad $PROFILE,添加以下内容

Import-Module posh-git

3. Termianl Icons

通过 scoop 安装

scoop install terminal-icons

执行 notepad $PROFILE,添加以下内容

Import-Module Terminal-Icons

4. PSReadLine

通过 scoop 安装

scoop install psreadline

执行 notepad $PROFILE,添加以下内容

Import-Module PSReadLine

Set-PSReadLineOption -PredictionSource History
Set-PSReadLineOption -Colors @{
    "Command" = "Yellow"
    "Parameter" = "Green"
    "Operator" = "Red"
    "Variable" = "Cyan"
    "String" = "Magenta"
    "Number" = "Blue"
    "Member" = "Gray"
}
Set-PSReadLineKeyHandler -Key Tab -Function Complete
Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward
Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward

5. ZLocation

通过 scoop 安装

scoop install zlocation

执行 notepad $PROFILE,添加以下内容

Import-Module ZLocation

6. 完整配置

oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH\M365Princess.omp.json" | Invoke-Expression
Import-Module posh-git
Import-Module Terminal-Icons
Import-Module ZLocation
Import-Module PSReadLine

Set-PSReadLineOption -PredictionSource History
Set-PSReadLineOption -Colors @{
    "Command" = "Yellow"
    "Parameter" = "Green"
    "Operator" = "Red"
    "Variable" = "Cyan"
    "String" = "Magenta"
    "Number" = "Blue"
    "Member" = "Gray"
}
Set-PSReadLineKeyHandler -Key Tab -Function Complete
Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward
Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward

参考资料

  1. https://juejin.cn/post/7210596158934433853
  2. https://ohmyposh.dev/
  3. https://www.nerdfonts.com/

Share this post on:

Previous Post
macOS 设置 Git GPG
Next Post
Mac mini M4 开箱和搭配戴尔 U2725QE