Oh My Posh × Windows Terminal 安裝指南
什麼是 Oh My Posh?
Oh My Posh 是一個跨平台的終端機提示列(prompt)美化引擎,可以自訂 Terminal 每行指令前面顯示的文字,加入顏色、圖示、Git 狀態、執行時間、程式語言版本等資訊。支援 PowerShell、Bash、Zsh、Fish 等主流 shell,Windows / macOS / Linux 都能用。
前置知識:PL 與 NF 字型差異
| 後綴 | 全名 | 內容 | 適用場景 |
|---|---|---|---|
| PL | Powerline | Powerline 符號(箭頭分隔符、Git 分支圖示等) | 僅需基本提示列美化 |
| NF | Nerd Font | Powerline 符號 + 數千個額外圖示(Font Awesome、Devicons、Material Design Icons 等) | TUI 工具、nvim 插件、完整 icon 顯示 |
PL ⊂ NF,直接裝 NF 版就好,一次涵蓋所有符號。
安裝步驟
Step 1:安裝 PowerShell 7
winget install Microsoft.PowerShell
裝完後重開 Windows Terminal,下拉選單會多一個「PowerShell」選項(跟原本的「Windows PowerShell 5.1」不同)。
設定 Windows Terminal Profile
在 Windows Terminal 的 settings.json → profiles → list 中新增:
{
"commandline": "C:\\Program Files\\PowerShell\\7\\pwsh.exe",
"font": {
"face": "Cascadia Mono NF"
},
"guid": "{574e775e-4f2a-5b96-ac1e-a2962a402336}",
"hidden": false,
"name": "PowerShell 7"
}
注意: 使用
pwsh.exe可能會因 PATH 問題無法啟動,建議改用完整路徑C:\\Program Files\\PowerShell\\7\\pwsh.exe。
如需設為預設 profile:
"defaultProfile": "{574e775e-4f2a-5b96-ac1e-a2962a402336}"
Step 2:解除腳本執行限制
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
輸入 Y 確認。
Step 3:安裝 Oh My Posh
winget install JanDeDobbeleer.OhMyPosh
裝完後完全關閉再重開 Windows Terminal,讓 PATH 生效。
Step 4:安裝 Nerd Font
Oh My Posh 內建字型安裝功能,官方推薦 Meslo LGM NF:
oh-my-posh font install meslo
或者直接使用已安裝的 Cascadia Mono NF / Cascadia Code NF 也可以。
Step 5:設定 Windows Terminal 字型
開啟 Windows Terminal 設定(Ctrl + ,)→ 選擇 PowerShell 7 profile → Appearance → Font face,選擇已安裝的 Nerd Font。
或在 settings.json 中直接設定:
"font": {
"face": "Cascadia Mono NF"
}
Step 6:建立 PowerShell Profile 並啟用 Oh My Posh
建立 profile 檔案(如果不存在):
New-Item -Path $PROFILE -Type File -Force
編輯 profile:
notepad $PROFILE
加入以下內容(以 atomic 主題為例):
oh-my-posh init pwsh --config atomic | Invoke-Expression
存檔後重開 Terminal 即可生效。
主題選擇
瀏覽主題
直接用主題名稱載入,會在啟動時從網路下載並快取:
oh-my-posh init pwsh --config <主題名稱> | Invoke-Expression
或前往官方主題頁面瀏覽截圖:ohmyposh.dev/docs/themes
熱門主題
| 主題 | 特色 |
|---|---|
jandedobbeleer | 作者預設主題,最經典 |
powerlevel10k_modern | 資訊豐富,顯示 Git / 語言版本 / 執行時間,開發者圈最流行 |
paradox | 雙行式提示列,完整路徑 + Git 狀態 |
dracula | Dracula 配色,適合跨工具統一風格 |
atomic | 簡潔乾淨,配色舒服 |
切換主題
編輯 $PROFILE,把主題名稱替換即可:
oh-my-posh init pwsh --config paradox | Invoke-Expression
CMD 支援(透過 Clink)
CMD 本身沒有原生自訂 prompt 支援,需要透過 Clink 橋接:
- 安裝 Clink(安裝時選 autostart)
- 在 CMD 執行
clink info找到 scripts 目錄 - 建立
oh-my-posh.lua:
load(io.popen('oh-my-posh init cmd'):read("*a"))()
- 重開 CMD 生效
建議直接使用 PowerShell 7,體驗會好很多。
常見問題
| 問題 | 解法 |
|---|---|
running scripts is disabled | Set-ExecutionPolicy RemoteSigned -Scope CurrentUser |
The system cannot find the file specified | Profile 不存在,先執行 New-Item -Path $PROFILE -Type File -Force |
pwsh.exe 無法啟動 | 改用完整路徑 C:\Program Files\PowerShell\7\pwsh.exe |
圖示顯示為方框 ▯ | Windows Terminal 字型未設定為 Nerd Font |
Get-PoshThemes 無法辨識 | 這是舊版指令,新版直接用主題名稱或到官網瀏覽 |
| Oh My Posh 已安裝但指令無法辨識 | 用 Get-Command oh-my-posh 確認路徑,可能需重開 Terminal |