Windows终端美化
总所周知,Windows默认的终端非常难看且不好用,本文介绍使用Windows Terminal+nerd-fonts+Oh my posh+PSReadLine 实现终端的美化字体样式和自动补全。
1. 安装Chocolatey
在Chocolatey Software | Installing Chocolatey网页下,复制安装脚本
安装脚本
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
复制到终端中
即可自动安装Chocolatey
2. 安装字体
推荐使用等宽连体带图标(终端显示的花样多一点)的字体
我使用Nerd Fonts
安装使用Chocolatey
即可
choco install nerd-fonts-hack
3. 编辑windows terminal 配置使用Nerd Fonts字体
这里很多人都会去下载一个powershell,其实没有必要,Windows自带的powershell的版本和功能已经可以满足要求。
当然也可以直接使用配置文件,"defaults"
在"profiles"
属性下
"defaults":
{
"backgroundImage": null,
"colorScheme": "Campbell",
"cursorShape": "filledBox",
"experimental.retroTerminalEffect": false,
"font":
{
"face": "CodeNewRoman Nerd Font Mono",
"size": 14.0,
"weight": "normal"
},
"opacity": 90,
"padding": "0",
"scrollbarState": "hidden",
"useAcrylic": false
},
其余的配置文件内容
"copyFormatting": "none",
"copyOnSelect": false,
"defaultProfile": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
"alwaysOnTop": false,
"alwaysShowTabs": true,
"autoHideWindow": false,
"disableAnimations": false,
"firstWindowPreference": "defaultProfile",
"focusFollowMouse": false,
"initialCols": 88,
"initialPosition": "750,350",
"initialRows": 24,
"launchMode": "focus",
大概在这个行数
4. 设置管理员权限启动
没有这个选项的更新即可
5. 使用oh-my-posh
- 安装,还是使用
Chocolatey
choco install oh-my-posh
- 创建
powershell
配置文件
if (!(Test-Path -Path $PROFILE )) { New-Item -Type File -Path $PROFILE -Force }
- 打开配置文件
notepad $PROFILE
- 写入指令,这里是让终端在启动时加载
oh-my-posh
配置文件,其中~/.omp.theme.json
是配置文件的所在路径,windows的话就是在C:\Users\Administrator
下创建.omp.theme.json
文件并写入配置即可
oh-my-posh init pwsh --config ~/.omp.theme.json | Invoke-Expression
-
使用
kushal
主题,其他主题在这里选择Themes | Oh My Posh -
复制内容粘贴到配置文件中即可
- 关闭启动时的banner,添加
-nologo
项即可
6. 使用自动补全
- 先安装最新的
PowerShellGet
Install-Module -Name PowerShellGet -Force
Exit
- 再安装
PSReadLine
Install-Module PSReadLine -AllowPrerelease -Force
- 在
powsershell
输入
notepad.exe $PROFILE
- 在打开的界面输入下面内容
Set-PSReadLineKeyHandler -Key Tab -Function MenuComplete #Tab键会出现自动补全菜单
Set-PSReadlineKeyHandler -Key UpArrow -Function HistorySearchBackward
Set-PSReadlineKeyHandler -Key DownArrow -Function HistorySearchForward
# 上下方向键箭头,搜索历史中进行自动补全
- 保存重启
powershell
即可