2024/04/10

Windows PowerShell Theme

็„กๆ„้–“็œ‹ๅˆฐไบ†้€™ๅ€‹ๅฝฑ็‰‡How to set up PowerShell prompt with Oh My Posh on Windows 11,ๆฒ’ๆƒณๅˆฐ PowerShell ไนŸๅฏไปฅๆžๅพ—้€™้บผๆผ‚ไบฎ,ๆ–ผๆ˜ฏๅƒ็…ง่ฃก้ข็š„่จญๅฎš,ๅนซ่‡ชๅทฑ็š„ PowerShell ๅšไบ†ๅ–œๆญก็š„็•ซ้ขๆ”นๅ‹•。

  1. ๅฎ‰่ฃ Scoop
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
Invoke-RestMethod -Uri https://get.scoop.sh | Invoke-Expression
  1. ๅฎ‰่ฃ Nerd Fonts
scoop bucket add nerd-fonts
scoop install Hack-NF


ๅฎ‰่ฃ Nerd Fonts ๅพŒ,่จญๅฎš PowerShell ็š„ๅญ—้ซ”็‚บ Hack Nerd Font,ๅญ—ๅž‹ๅคงๅฐ 11,้€ๆ˜Žๅบฆ 85%。

  1. ๅฎ‰่ฃ Terminal Icons
scoop bucket add extras
scoop install terminal-icons
  1. ๅฎ‰่ฃ Oh My Posh
scoop install https://github.com/JanDeDobbeleer/oh-my-posh/releases/latest/download/oh-my-posh.json
  1. ๅฎ‰่ฃ fzf
scoop install fzf
Install-Module -Name PSFzf
  1. ๅฎ‰่ฃ zoxide
scoop install zoxide
  1. ้…็ฝฎๅ€‹ไบบ็’ฐๅขƒ่ฎŠๆ•ธ
nvim $PROFILE.CurrentUserAllHosts

Config ๅ…งๅฎน

Import-Module -Name Terminal-Icons

oh-my-posh init pwsh --config '~/AppData/Local/Programs/oh-my-posh/themes/remk.omp.json' | Invoke-Expression

Set-Alias ll dir
Set-Alias ls ~/scoop/shims/ls.exe
Set-Alias find ~/scoop/shims/find.exe

Invoke-Expression (& { (zoxide init powershell | Out-String) })

Set-PSReadLineKeyHandler -Key Ctrl+k -Function KillLine

# replace 'Ctrl+t' and 'Ctrl+r' with your preferred bindings:
Set-PsFzfOption -PSReadlineChordProvider 'Ctrl+t' -PSReadlineChordReverseHistory 'Ctrl+r'

# ๅผทๅˆถๆŒ‡ๅฎšๆจ™ๆบ–่ผธๅ…ฅ่ˆ‡่ผธๅ‡บ็š„็ทจ็ขผ
$OutputEncoding = [System.Text.Encoding]::UTF8
[Console]::InputEncoding = [System.Text.Encoding]::UTF8
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8

# ๅŒๆญฅๅŸท่กŒ chcp ็ขบไฟๅบ•ๅฑคๅญ—็ขผ้ ๅˆ‡ๆ›
chcp 65001 | Out-Null

ๆˆ‘้ธๆ“‡ไบ† remk ้€™ๅ€‹ theme,ๅฎ‰่ฃไบ†ๅฅ—ไปถ busybox ่ฎ“ไป–ๆ›ดๅƒ Linux,ไนŸๅŒๆ™‚ๅฎ‰่ฃไบ† versions。

Final Theme
ๆ–ผๆ˜ฏๆˆ‘ๅฐฑๅพ—ๅˆฐไบ†็พŽ็พŽ็š„ terminal。

reference