在更改Windows Powser Shell 默认字体Consolas (一)中已经介绍对PowerShell 字体的进本设置更改,本文会进一步介绍使用posh-git
和oh-my-posh
对PowerShell进行美化,在VS Code中设置优化,以及在设置过程中遇到的坑。
美化后的Windows PowerShell界面:
在Windows PowerShell中安装配置 posh-git
和oh-my-posh
模块
posh-git
为 PowerShell 提供了 git 状态显示和命令补全等,oh-my-posh
为 PowerShell 提供了多种自定义主题和配色。
按步骤配置安装如下:
1、在系统开始菜单中打开 Windows PowerShell
2、依次安装如下模块
Install-Module posh-git -Scope CurrentUser # posh-git
Install-Module oh-my-posh -Scope CurrentUser -RequiredVersion 2.0.496 # oh-my-posh
3、编辑文件 $Profile
,这个文件类似于 ~/.zshrc
,会在 PowerShell 启动的时候自动执行,因此我们在这个文件中加载我们所需的模块,操作步骤:
notepad.exe $Profile
在打开的文件里面添加以下所有内容:
Import-Module posh-git # 引入 posh-git
Import-Module oh-my-posh # 引入 oh-my-posh
Set-Theme Paradox # 设置主题为 Paradox
Set-PSReadlineKeyHandler -Key Tab -Function Complete # 设置 Tab 键补全
Set-PSReadLineKeyHandler -Key "Ctrl+d" -Function MenuComplete # 设置 Ctrl+d 为菜单补全和 Intellisense
Set-PSReadLineKeyHandler -Key "Ctrl+z" -Function Undo # 设置 Ctrl+z 为撤销
Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward # 设置向上键为后向搜索历史记录
Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward # 设置向下键为前向搜索历史纪录
$OutputEncoding = [console]::InputEncoding = [console]::OutputEncoding = New-Object System.Text.UTF8Encoding #解决中文乱码
上述安装过程中参照图:
4、安装等宽字体Cascadia Code
(非常重要,如果不安装会出现符号乱码)
下载链接:https://github.com/microsoft/cascadia-code/releases
在下载链接里的Assets
中下载第一个字体包,下载后解压安装到系统中。
安装完后再次打开PowerShell 属性设置,设置字体为:Cascadia Mono PL
。
Cascadia Code
字体已经加入微软标准字体库,详细请参照微软官方链接:
https://docs.microsoft.com/zh-cn/windows/terminal/cascadia-code
注意:如果你本地安装了 Fluent Terminal 或者 Tabby,同样需要在其设置中找到Terminal字体设置选择Cascadia Mono PL
。
以Fluent Terminal
举例,先设置Fluent Terminal终端字体样式:
设置后的Fluent Terminal终端效果:
在VS Code中配置Git Bash或者PowerShell
很多文章千篇一律说在VS Code中配置Git Bash的时候需要添加什么terminal.integrated.shell.windows
参数,
就非常离(che)谱(dan)。
最简单的操作步骤:
1、打开VS Code,点击左下角齿轮,点击设置,设置中搜索 profile
或者 Terminal
,找到图下图所示设置 Default Profile:Windows
2、下拉菜单选择 Git Bash
或者 Windows PowerShell
3、(非常重要)在设置中搜索 font family
滚动到最下面找到 Terminal > Integrated: Font Family, 填入Cascadia Mono PL
。
注意该字体
Cascadia Mono PL
下载安装方式请参照上文。
VS Code配置完 PowerShell 的界面:
VS Code配置完 Git Bash 的界面: