美化 PowerShell:Oh My Posh 全攻略 (2025)

最近把內建的 Windows PowerShell 5.1 直接升級到跨平台的 PowerShell 7,啟動速度、互動補全與外觀自訂一次大進化。於是把這次從「升級 → 權限工具 (gsudo) → Prompt 美化 (Oh My Posh) → 文字/字型 → 終端顏色主題」的完整流程整理成筆記,之後重裝或換機也能快速複製。

這篇你將會獲得:

  1. 乾淨可重現的 Profile 初始化步驟
  2. 提升效率的補全與權限操作設定
  3. 一套漂亮又資訊量足夠的 Prompt 主題
  4. Windows Terminal 配色與字型建議

先來看看升級前「尚未美化」的樣子,然後開始改造:

PowerShell Profile 準備

之後的功能(自動補全、別名、提示主題等)都會寫進個人 Profile。先確認目前的 $PROFILE 是否存在,沒有就建立。

1
2
3
4
5
6
7
8
# 查看目前使用的 Profile 路徑
echo $PROFILE

# 檢查檔案是否存在(True = 已存在)
Test-Path $PROFILE

# 直接用記事本編輯
notepad $PROFILE

Windows PowerShell 5.1 目錄

舊版(內建)使用的目錄名稱是 WindowsPowerShell

1
2
3
4
5
6
7
8
# 檢查舊版目錄是否存在
Test-Path "C:\Users\{你的帳戶}\Documents\WindowsPowerShell"

# 建立目錄(若不存在)
New-Item -ItemType Directory -Path "C:\Users\{你的帳戶}\Documents\WindowsPowerShell" -Force

# 建立 Profile(空檔案)
New-Item -ItemType File -Path $PROFILE -Force

PowerShell 7 目錄

PowerShell 7 之後改用新目錄 PowerShell,不要混用。

1
2
3
4
5
6
7
8
# 檢查新版目錄是否存在
Test-Path "C:\Users\{你的帳戶}\Documents\PowerShell"

# 建立目錄
New-Item -ItemType Directory -Path "C:\Users\{你的帳戶}\Documents\PowerShell" -Force

# 建立 Profile
New-Item -ItemType File -Path $PROFILE -Force

安裝 PowerShell 7

使用 winget 最方便:

1
2
3
4
5
# 安裝
winget install --id Microsoft.Powershell --source winget

# 更新
winget upgrade --id Microsoft.Powershell

啟用指令歷史 + AI 預測補全

建議在 Profile 中加入 PSReadLine 設定:

1
2
3
4
5
6
7
# 使用歷史紀錄 (History) + 外掛/擴充來源 (Plugin) 同時提供預測建議。
# 其他可選值:None / History / Plugin / HistoryAndPlugin
Set-PSReadLineOption -PredictionSource HistoryAndPlugin

# 將多筆建議以清單面板顯示於游標下方(ListView)。
# 若偏好行內灰色字體,可改用:InlineView
Set-PSReadLineOption -PredictionViewStyle ListView

若想立即測試:把以上貼進 notepad $PROFILE 開啟的檔案末端後存檔,再開新視窗生效。

gsudo:快速取得系統權限

gsudo 可視為 Windows 版 sudo,不用每次再手動啟動「以系統管理員身分執行」。

1
2
3
4
5
# 安裝
winget install gerardog.gsudo

# 更新
winget upgrade gerardog.gsudo

在 Profile 中加入別名:

1
Set-Alias sudo gsudo

如果在 Windows Terminal 中想建立一個自動提權啟動 PowerShell 7 的命令,可在設定中指定:

1
gsudo.exe "C:\Program Files\PowerShell\7\pwsh.exe"

Oh My Posh:Prompt 主題美化

安裝 Nerd Font 字型

先到 Nerd Fonts 官網 下載一款字型(建議 FiraCode / Meslo / JetBrainsMono),安裝後到 Windows Terminal 的該 Profile 內套用,避免符號亂碼。

安裝 Oh My Posh

1
2
winget install JanDeDobbeleer.OhMyPosh -s winget
winget upgrade JanDeDobbeleer.OhMyPosh

啟用並指定主題

在 Profile 內加入(可先用 notepad $PROFILE 開啟):

1
2
3
4
5
# 初始化(預設主題)
oh-my-posh init pwsh | Invoke-Expression

# 指定 paradox 主題(可改成任意 .omp.json)
oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH\paradox.omp.json" | Invoke-Expression

查看有哪些內建主題:

1
Get-ChildItem $env:POSH_THEMES_PATH | Select-String ".omp.json"

修改後重新開一個新的 PowerShell 視窗即可看到效果。

安裝 Git(若尚未安裝)

1
2
winget install --id Git.Git -e --source winget
winget upgrade Git.Git

Windows Terminal 主題配色(Schemes)

可到 Windows Terminal Themes 挑選喜歡的色票,將 JSON 片段貼進設定檔的 schemes 陣列,再於對應 Profile 設 "colorScheme" 為該名稱。

例如 Espresso

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
{
"background": "#323232",
"black": "#353535",
"blue": "#6C99BB",
"brightBlack": "#535353",
"brightBlue": "#8AB7D9",
"brightCyan": "#DCF4FF",
"brightGreen": "#C2E075",
"brightPurple": "#EFB5F7",
"brightRed": "#F00C0C",
"brightWhite": "#FFFFFF",
"brightYellow": "#E1E48B",
"cursorColor": "#D6D6D6",
"cyan": "#BED6FF",
"foreground": "#FFFFFF",
"green": "#A5C261",
"name": "Espresso",
"purple": "#D197D9",
"red": "#D25252",
"selectionBackground": "#5B5B5B",
"white": "#EEEEEC",
"yellow": "#FFC66D"
}

開啟 JSON 設定:

  1. 將上述片段加入 schemes
  2. 在對應的 Profile 中設定:"colorScheme": "Espresso"

成果展示

PowerShell 7 + Oh My Posh 終端成品示意

希望這篇能幫助你快速打造一個好看、好讀、好用的終端環境。如果你有更喜歡的主題或額外技巧,也歡迎分享交流 🙌