美化PowerShell优化终端Terminal、在VS Code中配置Git Bash(二)

更改Windows Powser Shell 默认字体Consolas (一)中已经介绍对PowerShell 字体的进本设置更改,本文会进一步介绍使用posh-gitoh-my-posh对PowerShell进行美化,在VS Code中设置优化,以及在设置过程中遇到的坑。

美化后的Windows PowerShell界面:

在Windows PowerShell中安装配置 posh-gitoh-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 的界面:

  • 4
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

bluetata

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值