記錄在 PowerShell 安裝 Oh My Posh 的過程

最近發現許多開發者使用 Oh My Posh 來提升 PowerShell 的生產力,因此研究了一下它的安裝方式。本篇文章將記錄我的操作流程,內容主要以完成基礎安裝為主,若需更進階的功能,可參考文章末尾提供的相關連結。
安裝流程
開啟 Windows Terminal 的 Windows PowerShell
安裝 PowerShell(支援跨平台的版本)
winget install Microsoft.PowerShell重新啟動 Windows Terminal,並使用 PowerShell
💡注意要選擇前一步驟安裝的 PowerShell(版本為 7.x),而非 Windows PowerShell(版本為 5.x)檢查下列指令的執行結果是否為 RemoteSigned
Get-ExecutionPolicy安裝 Oh My Posh
winget install JanDeDobbeleer.OhMyPosh -s winget安裝字型,選擇 Cascadia Code(此指令需要使用系統管理員身分執行)
oh-my-posh font install --user重新開啟 Windows Terminal,在「設定 > 設定檔 > PowerShell > 其他設定 > 外觀 > 字體」將字體設為 CaskaydiaCove Nerd Font Mono
檢查下列指令的執行結果是否為 pwsh
oh-my-posh get shell開啟設定檔
notepad $PROFILE💡若無法開啟,請執行New-Item -Path $PROFILE -Type File -Force指令建立設定檔在設定檔中加入以下內容
oh-my-posh init pwsh | Invoke-Expression輸入下列指令使設定檔生效(或是重新開啟 Windows Terminal)
. $PROFILE
小技巧
在 Windows Terminal 的「設定 > 設定檔 > PowerShell > 命令列」加入
-NoLogo命令,並重新啟動 Windows Terminal,可將每次啟動顯示的橫幅資訊(如下圖紅框處)隱藏。(相關文件)
完整命令如下:
"C:\Program Files\PowerShell\7\pwsh.exe" -NoLogo在 Windows Terminal 的「設定 > 設定檔 > PowerShell > 其他設定 > 外觀 > 字型大小」將字型從 12 改為 13,並重新啟動 Windows Terminal,文字接縫處會變得比較漂亮。
參考資源
如何打造一個華麗又實用的 PowerShell 命令輸入環境
“PowerShell 7.3 隨附于 PSReadLine 2.2.6。” (Source)
作業環境
Windows 11 22H2 Build 22621.2283
Windows Terminal 1.17.11461.0 (已內建)
winget v1.6.2721 (已內建)
winget --versionWindows PowerShell 5.1 (已內建)
$PSVersionTablePowerShell 7.3.7
Oh My Posh 18.10.3
oh-my-posh --version





