# Windows Terminal custom prompt ###### tags: `Windows Terminal` `PowerShell` `posh-git` `oh-my-posh` `Terminal-Icon` > 關於美化自訂 `Windows Terminal` 的命令列提示主題。 > 網路上大部分找到的教學都是 `2` 的,比較少關於 `3` 的。 > > 因此寫了這篇來記錄一下筆者在安裝 `oh-my-posh 3` 時的步驟, > 接下來會安裝的套件有 `posh-git`、`oh-my-posh`、`Terminal-Icon`。 ## :memo: 安裝相關程式與套件 ### Step 1: Install Windows Terminal > 透過 Windows Store 安裝 [Install Windwos Terminal](https://aka.ms/terminal) ### Step 2: Install PowerShell > 在官方的 [PowerShell GitHub](https://aka.ms/powershell-release?tag=stable) 下載最新的穩定版 > 筆者在這邊使用的是 [PowerShell-7.2.0-win-x64.msi](https://github.com/PowerShell/PowerShell/releases/download/v7.2.0/PowerShell-7.2.0-win-x64.msi) ### Step 3: Install posh-git、oh-my-posh > 使用 Terminal 打開你的 PowerShell,依序安裝以下套件 - posh-git > [posh-git](https://github.com/dahlbyk/posh-git) 其它方式可參考官方文件 [color=#3b75c6] ```powershell # Install Install-Module posh-git -Scope CurrentUser -Force # Update Update-Module posh-git ``` - oh-my-posh > [Oh My Posh](https://ohmyposh.dev/) 可以進一步美化 PowerShell 的 `git status` 外觀,使其更容易閱讀,其它方式可參考官方文件。[color=#3b75c6] > > 筆者這裡使用 `winget` 所安裝的版本為 `oh-my-posh 3` ```powershell # Install winget install JanDeDobbeleer.OhMyPosh # Update winget upgrade JanDeDobbeleer.OhMyPosh ``` > 安裝完成後,現在需要選擇一個喜歡主題,使用 `code $PROFILE` 或 `notepad $PROFILE` 編輯 PowerShell 的 profile 設定檔加入以下指令,讓每次 PowerShell 打開時都會載入主題,筆者選擇的是 `atomic.omp.json`,你也參考位於 `~\AppData\Local\Programs\oh-my-posh\themes\` 目錄下的其它主題 [color=#3b75c6] ```powershell # Load oh-my-posh theme oh-my-posh --init --shell pwsh --config ~\AppData\Local\Programs\oh-my-posh\themes\atomic.omp.json | Invoke-Expression ``` ### Step 4: Install Nerd Fonts > `oh-my-posh` 使用了 powerline font 來製作 theme,因此我們必須安裝一種 [Nerd Fonts](https://www.nerdfonts.com/) 字型來顯示缺少的字元,筆者這裡選用的是 `DejaVuSansMono Nerd Font`。 > > 然後在 **Windows Terminal > settings > Appearance > Font face** > 選擇剛剛所安裝的 `DejaVuSansMono Nerd Font` 即可完整顯示字元。 ### Step 5: Install Terminal-Icon(Optional) > [Terminal-Icon](https://github.com/devblackops/Terminal-Icons) 是選擇性安裝,但筆者覺得使用後體驗更佳,Terminal-Icon 會在檔案名稱的前方增加類別圖示使其更容易辨示。 [color=#3b75c6] ```powershell # Install Install-Module -Name Terminal-Icons -Repository PSGallery ``` ### Full profile settings ```powershell # using utf-8 display non-ascii git log comments $env:LC_ALL = 'C.UTF-8' # Import modules Import-Module posh-git Import-Module -Name Terminal-Icons # Load oh-my-posh theme oh-my-posh --init --shell pwsh --config ~\AppData\Local\Programs\oh-my-posh\themes\atomic.omp.json | Invoke-Expression ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up