Loading... ## 前言 配置 Windows 下的 Oh My Posh。 ## 安装 通过 scoop 安装 ```shell scoop install oh-my-posh ``` 官网安装 ```shell 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` 提示找不到文件,则执行 ```shell New-Item -Path $PROFILE -Type File -Force ``` ## 配置 ### 1. 安装字体 通过网站 [Nerd Font](https://www.nerdfonts.com/font-downloads) 下载字体,这里选用的是 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 安装 ```shell scoop install terminal-icons ``` 执行 `notepad $PROFILE`,添加以下内容 ``` Import-Module Terminal-Icons ``` ### 4. PSReadLine 通过 scoop 安装 ```shell 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 安装 ```shell 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/ 最后修改:2025 年 03 月 19 日 © 允许规范转载 赞 如果觉得我的文章对你有用,请随意赞赏