IT, 筆記

美化 WSL和PowerShell

用上了WSL2也用上了Windows Terminal後,就想用Oh-My-* 美化一下。

因為不熟Powershell, 所以直接上網找並找到這些站:

  1. PowerShell 美化配置
  2. How to make a pretty prompt in Windows Terminal with Powerline, Nerd Fonts, Cascadia Code, WSL, and oh-my-posh
  3. POWERLINE AND ZSH’S AGNOSTER THEME IN VS CODE

我所做的步驟如下:

Font

先安裝 Cascadia Code (w/ Powerline) Fonts:

  1. Download Cascadia Code 2007.01 (或最新)
  2. Extract 後再找到TTF font (有四個.ttf 檔),右鍵選安裝
  3. 打開Windows Terminal,打開 Settings,在 Default 裡加入Fontface,如下
"profiles":
    {
        "defaults":
        {
            // Put settings here that you want to apply to all profiles
	    "fontFace":  "Cascadia Code PL"
        },
  1. Save,完成

WSL - Oh-My-Zsh

打開 Windows Terminal - Ubuntu,輸入:

$ sudo apt-get install zsh
$ sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
$ vi ~/.zshrc
# ---修改ZSH_THEME為 agnoster
# ZSH_THEME="robbyrussell"
ZSH_THEME="agnoster"
# ---

$ exec $SHELL

完成

Powershell

打開 Windows Powershell (admin),輸入:

Install-Module posh-git
Install-Module oh-my-posh
Install-Module -Name PSReadLine -Force -SkipPublisherCheck
Install-Module Get-ChildItemColor -AllowClobber
Install-Module WindowsConsoleFonts

新增或修改 $profile 檔案

打開 Windows Terminal - Powershell,輸入:

if (!(Test-Path -Path $PROFILE )) { New-Item -Type File -Path $PROFILE -Force }
code $profile

加入/修改內文,以下是我使用的設定(參考自: https://github.com/microexs/PowerAdmin/blob/master/PCInit.md):

Set-PSReadlineOption -EditMode Emacs
function which($name) { Get-Command $name | Select-Object Definition }
function rmrf($item) { Remove-Item $item -Recurse -Force }
function mkfile($file) { "" | Out-File $file -Encoding ASCII }
function getMyDoc() { Set-Location "C:\Users\Shunnien Yu\Documents\" }
function getGitOneLineGraphLog() { git log --oneline --all --graph --decorate }
Import-Module posh-git
Import-Module oh-my-posh
Import-Module Get-ChildItemColor
Set-Alias l Get-ChildItemColor -option AllScope
Set-Alias ls Get-ChildItemColorFormatWide -option AllScope
Set-Alias ... getMyDoc -option AllScope
Set-Alias ggl getGitOneLineGraphLog -option AllScope
Set-Theme Paradox

完成

VS Code

  1. 打開 VS Code - Files - Preferences - Settings (或按 Ctrl+,)
  2. Search 中輸入: terminal font
  3. 在 Terminal > Integrated: Font Family 中,加入:cascadia code PL 或 cascadia mono PL

即時生效,完成

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *