重装系统,再折腾一下。
安裝 Windows Terminal 最新版
winget install Microsoft.WindowsTerminal --accept-source-agreements
或者store安装也行
安裝 PowerShell 7 最新版
winget install Microsoft.PowerShell
安裝 Oh My Posh 工具
winget install JanDeDobbeleer.OhMyPosh
自動安裝
oh-my-posh.exe
主程式,並設定PATH
環境變數。
重開 Windows PowerShell 並安裝 Oh My Posh 所需的字型
執行以下命令會直接安裝 CascadiaCode
字型!
oh-my-posh.exe font install CascadiaCode
工具安裝完畢後,請改用 Windows Terminal 開啟,你可以選擇 Windows PowerShell
(代表 5.1 版) 或是 PowerShell
(代表 7.x 版)!
調整 Windows Terminal 設定
請將 Windows PowerShell、PowerShell Core、WSL 的 外觀 (Appearance) 調整使用 CaskaydiaCove NF
字型 (Font face)!
建議修改 PowerShell 的啟動參數,命令列的部分加入 -NoLogo
參數:
"C:\Program Files\PowerShell\7\pwsh.exe" -NoLogo
安裝 Terminal-Icons 模組
Install-Module -Name Terminal-Icons -Repository PSGallery -Force
這個模組可以讓你在執行
Get-ChildItem
(dir
) 的時候會在檔案與資料夾上顯示檔案類型圖示。
安裝 PSReadLine 模組
優化 PowerShell 環境的利器,不過只能在 PowerShell 7 執行:
Install-Module PSReadLine -AllowPrerelease -Force
初始化 $PROFILE
啟動設定檔
[System.IO.Directory]::CreateDirectory([System.IO.Path]::GetDirectoryName($PROFILE))if (-not (Test-Path -Path $PROFILE -PathType Leaf)) { New-Item $PROFILE -Force}
啟用 PSReadLine 並啟用超強自動完成功能
你可以直接將我的 PROFILE_PSReadLine.ps1 內容加入到 PROFILE 啟動設定檔中!
(Invoke-WebRequest -Uri 'https://gist.githubusercontent.com/doggy8088/d3f3925452e2d7b923d01142f755d2ae/raw/aabe600ed2adccb43165228b8c8ced6e88ac9fc0/$PROFILE_PSReadLine.ps1').Content | Out-File -LiteralPath $PROFILE -Append -Encoding utf8
設定各種命令自動完成提示
你可以直接將我的 PROFILE_ArgumentCompleter.ps1 內容加入到 PROFILE 啟動設定檔中!
(Invoke-WebRequest -Uri 'https://gist.githubusercontent.com/doggy8088/2bf2a46f7e65ae4197b6092df3835f21/raw/e5e73da6aabaf51ae49c641f5ca409f38f660443/$PROFILE_ArgumentCompleter.ps1').Content | Out-File -LiteralPath $PROFILE -Append -Encoding utf8
加上幾個我自訂的 Cmdlets / Functions 與停用兩個不太實用的 Cmdlet Aliases
你可以直接將我的 PROFILE_Cmdlets_Functions.ps1 內容加入到 PROFILE 啟動設定檔中!
(Invoke-WebRequest -Uri 'https://gist.githubusercontent.com/doggy8088/553c4548492b63e4ccbe30d843de85f6/raw/5b8492883519ffbd74557e26d7eaf73dc2692c23/$PROFILE_Cmdlets_Functions.ps1').Content | Out-File -LiteralPath $PROFILE -Append -Encoding utf8
匯入 Terminal-Icons 模組
'Import-Module -Name Terminal-Icons' | Out-File -LiteralPath $PROFILE -Append -Encoding utf8
啟動 Oh My Posh 的 Shell 環境
立即啟用 Oh My Posh 的命令列提示 (Prompt)
oh-my-posh init pwsh | Invoke-Expression
啟動後,你就可以透過 Get-PoshThemes
快速顯示所有的 Themes 樣式,選一個自己喜歡的版本!😍
假設你選擇 atomicBit
的話,就可以這樣重新啟動:
oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH\atomicBit.omp.json" | Invoke-Expression
然後將以下命令加入到 $PROFILE
啟動設定檔中
'oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH\atomicBit.omp.json" | Invoke-Expression' | Out-File -LiteralPath $PROFILE -Append -Encoding utf8
重新啟動 Windows Terminal 或重新載入 $PROFILE
啟動設定檔
你可以使用點表示法重新載入 $PROFILE
啟動設定檔:
. $PROFILE