配置 Windows Terminal 的步骤
前提:在微软商店下载两个软件
- Windows Terminal
- PowerShell(因为最好使用 PowerShell7 ,否则以下命令可能执行不了)
安装 oh my posh
安装 oh my posh,可以在 windows terminal 中的 Windows PowerShell7 中输入以下命令(安装过程中需要输入 Y 即可)
Install-Module oh-my-posh -Scope CurrentUser -SkipPublisherCheck
Install-Module posh-git -Scope CurrentUser
Install-Module -Name PSReadLine -AllowPrerelease -Scope CurrentUser -Force -SkipPublisherCheck
启动 oh my posh
- 使用记事本打开配置文件,因为一开始还没有 profile 这个文件,所以第一次需要创建该文件
notepad.exe $PROFILE
- 创建好文件之后,需要在文件中添加如下配置
Import-Module posh-git
Import-Module oh-my-posh
Set-PoshPrompt -Theme material
注意:其中的 set-PoshPrompt-Theme
可以从 oh my posh 提供的主题中自我选择
补充:oh my posh 网址:https://ohmyposh.dev/docs
至此,安装已经完成,重启 terminal 就能看到了
补充
命令行自动补全和提示
Set-PSReadlineKeyHandler -Key Tab -Function MenuComplete
让文件显示图标并变色
安装图标库
Install-Module -Name Terminal-Icons -Repository PSGallery
使用图标
Import-Module -Name Terminal-Icons
字体设置
如果设置的主题出错,可能是因为缺少安装所需的字体;oh my post 官网文档说是需要下载一个 nerd 字体。可以选择 Caskaydia Cove Nerd Font 字体进行下载安装。安装好之后,在 terminal 中设置为对应的字体即可
字体网址如下:https://www.nerdfonts.com/