配置 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/
