简单美化 Windows Terminal
本文最后更新于 2022-07-19 17:16,下午
前阵子微软发布了 Windows Terminal 的正式版本,但是这长相也太「规矩」了,浓眉大眼的,咱们得给它稍稍打扮一下。
第一部分:设置 Powerline
「Powerline 提供自定义的命令提示符体验,提供 Git 状态颜色编码和提示符。」
为 PowerShell 设置 Powerline
-
在 Github 上下载支持 Powerline 字形的字体文件(CascadiaCodePL.otf)并安装。
-
安装 Git。
-
安装 posh-git 和 oh-my-posh(需要您允许从「不受信任的存储库」来安装,选择「全是」选项)。
Install-Module posh-git -Scope CurrentUser Install-Module oh-my-posh -Scope CurrentUser
-
以管理员身份打开 PowerShell 并键入
set-ExecutionPolicy RemoteSigned
,选择「全是」选项允许脚本的运行。 -
键入
notepad $PROFILE
打开 PoerShell 的配置文件,添加以下语句并保存。Import-Module posh-git Import-Module oh-my-posh Set-Theme Paradox
为 Ubuntu 设置 Powerline(如果您不用 WSL 可忽略此步)
-
在本机上键入
ipconfig
查看 IPv4 地址。 -
在 Ubuntu 上键入以下语句来设置代理,确保正常连接 GitHub。注意代理软件要设置为允许来自局域网的连接,同时不要忘记使用您自己的 IP 地址及端口,文章中的 IP 地址及端口仅为占位符。
export http_proxy = "http://<Windows IP>:<Port>" export https_proxy = "http://<Windows IP>:<Port>"
-
安装 Go 和 Powerline。
sudo apt install golang-go go get -u github.com/justjanne/powerline-go
-
使用 Vim 等编辑器编辑
~/.bashrc
文件,添加以下语句并保存。GOPATH = $HOME/go function _update_ps1() { PS1 = "$($GOPATH/bin/powerline-go -error $?)" } if [ "$TERM" != "linux" ] && [ -f "$GOPATH/bin/powerline-go" ]; then PROMPT_COMMAND = "_update_ps1; $PROMPT_COMMAND" fi
第二部分:修改 Windows Terminal 配置文件
-
在 Windows Terminal 中按下
Ctrl
和,
组合键打开配置文件。 -
在
defaults
对象中添加以下内容。"useAcrylic": true, //使用亚克力效果。 "acrylicOpacity": 0.75, //设置亚克力效果透明度数值为 0.75。 "colorScheme": "One Half Dark", //使用 One Half Dark 配色。 "fontFace": "Cascadia Code PL" //使用 Cascadia Code PL 字体以显示编程连字及 Powerline 字形。
自此我对 Windows Terminal 的简单美化便完成了。
您还可以阅读 官方文档 去了解如何设置背景图像、如何启用怀旧式命令提示符效果,打造独一无二的终端体验。
另外,每次更新博客都要运行 hexo clean;;hexo g;;hexo d;;hexo b
这条命令过于麻烦。我们可以在 PowerShell 的 $PROFILE
文件内添加这条语句:function go {hexo clean;;hexo g;;hexo d;;hexo b}
,然后重启 PowerShell。这样的话,更新博客的时候只需要使用 go
就可以了。
参考文章
- 《Windows 终端 Powerline 设置》
- 《PowerShell:因为在此系统上禁止运行脚本,解决方法》
- 《WSL2 中访问宿主机 Windows 的代理》
- 《Windows 终端配置文件设置》
- 《Windows 终端配色方案》
完。