本文主要参考 @skunklabz 在 YouTube 上的视频 Microsoft Windows Terminal Setup using Chocolatey and Oh-My-Posh,介绍了如何安装 Choco,如何通过 Choco 安装并配置 Windows-Terminal,如何安装并配置 Oh-My-Posh 以及列举出 Windows-Terminal 的一些常用快捷键,方便日后查阅。
安装 Chocolaty
1 | Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')) |
使用 Chocolaty 安装 Windows Terminal
1 | choco install microsoft-windows-terminal |
安装 oh-my-posh
安装
1 | Install-Module posh-git -Scope CurrentUser |
验证
1 | Import-Module posh-git |
此时可以发现命令提示符已经改变,但是显示仍然存在问题,需要安装 NerdFonts 并在 Windows Terminal 中配置 FontFace。
安装 NerdFonts
1 | Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://raw.githubusercontent.com/kgodoy/nerd-fonts-downloader/master/nerd-fonts-downloader.ps1')) |
修改 PowerShell 启动文件
1 | notepad $PROFILE |
1 | Import-Module posh-git |
主题可以在 oh-my-posh#themes 进行选择。
配置 Windows Terminal
打开 Windows Terminal
点击设置,会使用默认文本编辑器打开一个 settings.json 文件。
在
json['profiles']['list']
中找到commandline
为powershell.exe
的一项,填加字段FontFace
1
"fontFace": "Meslo LG L for PowerLine",
Windows Terminal 的一些快捷键
命令模式(
ctrl+shift+p
)(和 Visual Studio Code 非常类似,真香!)分屏(
alt+shift+plus
、alt+shift+-
)在分屏之间移动(
alt+up/down/left/right arrows
)调整分屏大小(
alt+shift+up/down/left/right arrows
)关闭分屏(
ctrl+shift+w
)复制(
ctrl+c
、鼠标右键)粘贴(
ctrl+v
、鼠标右键)放大缩小(
ctrl+scroll
、ctrl+plus
、ctrl+-
)搜索(
ctrl+shift+f
)打开配置文件(
ctrl+,
)新建标签页(
ctrl+shift+t
)在标签页之间切换(
ctrl+tab
、ctrl+shift+tab
)跳到第 N 个标签页(
ctrl+alt+${N}
)滚动窗口(
ctrl+shift+up/down arrows
)