前言

本篇主要是在針對不安裝 homebrewiTerm 的前提下也能有好看的 Terminal 字型。

成果

Terminal

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/60726d2a-db38-497d-8339-427340081979/Untitled.png

VSCode Terminal

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/52382faf-8c60-4a1d-b870-64d8da5e2b8c/Untitled.png

Terminal

  1. 按下 CMD + Space 輸入 Terminal 打開終端機

  2. 請確保你的 shell 是 zsh (Mac 會推薦使用這個 Shell)

    如果不是的話執行 chsh -s /bin/zsh

  3. 安裝 Oh My Zsh 並更新至最新版本,如果已經裝過可以跳過此步

    sh -c "$(curl -fsSL <https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh>)"
    

    檢查 zsh 的版本

    zsh --version
    

    執行下列指令更新到最新版本

    upgrade_oh_my_zsh
    
  4. 變更 zsh 的主題至 agnoster

    nano ~/.zshrc
    

    ZSH_THEME="xxx" 改成 ZSH_THEME="agnoster"

    按下 Ctrl + O 儲存 Ctrl + X 離開

    輸入下面的指令變更設定

    source ~/.zshrc
    

    如果 Terminal 風格有變代表成功,沒變的話請回到第一步確保沒有問題

  5. 使用更蝦趴的自訂主題 powerlevel9k

    Clone powerlevel9k 專案到 ~/.oh-my-zsh/custom/themes/powerlevel9k

    git clone <https://github.com/bhilburn/powerlevel9k.git> ~/.oh-my-zsh/custom/themes/powerlevel9k
    

    重新做一次上一步,但是 ZSH 主題從 agnoster 變成 powerlevel9k/powerlevel9k

  6. 安裝字體

    https://github.com/ryanoasis/nerd-fonts 上下載 Sauce Code Pro Nerd Font 讓你的 Terminal 變漂亮,下面的載點可能不會是最新的建議還是上 GitHub 下載最新的。

    Sauce Code Pro Nerd Font Complete.ttf

  7. 修改字體

    在 Terminal 中輸入 CMD + , 可以進入 Preference ,並點選 Profiles > Font > Change...

    https://s3-us-west-2.amazonaws.com/secure.notion-static.com/64bbf420-02b7-4d2e-9224-cf9e77043ac1/Untitled.png

    選取 SauceCodePro Nerd Font / Regular 並關閉視窗

    https://s3-us-west-2.amazonaws.com/secure.notion-static.com/efae8abf-a86d-4ee4-bc60-58735f4124db/Untitled.png

  8. (Optional) 配置更潮的格式

    上面成果的格式是在 ~/.zshrc 中加入以下設定,設定方式與第 4 步變更主題一樣,細節請見參考資料

    POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir dir_writable rbenv vcs)
    POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(status root_indicator background_jobs ram load history time)
    POWERLEVEL9K_PROMPT_ON_NEWLINE=true
    POWERLEVEL9K_MULTILINE_FIRST_PROMPT_PREFIX="%f"
    local user_symbol="$"
    if [[ $(print -P "%#") =~ "#" ]]; then
        user_symbol = "#"
    fi
    POWERLEVEL9K_MULTILINE_LAST_PROMPT_PREFIX="%{%B%F{black}%K{yellow}%} $user_symbol%{%b%f%k%F{yellow}%} %{%f%}"
    POWERLEVEL9K_PROMPT_ADD_NEWLINE=true
    
  9. (Optinal) 透明化 Terminal 變更顏色

VSCode Terminal

與原生的 Terminal 不同的是必須使用 Monospace Font,也就等寬字體,所以採用 ``SauceCodePro Nerd Font Mono就只是多了個Mono` 而已。

  1. 安裝字體

    Sauce Code Pro Nerd Font Complete Mono.ttf

  2. 在 VSCode 打開快速命令列 CMD + Shift + P 輸入 JSON Settings 後進入設定

    主要是加入設定 terminal.integrated.fontFamily

    {
        "terminal.integrated.shell.osx": "/bin/zsh",
        "terminal.integrated.fontFamily": "SauceCodePro Nerd Font Mono",
    }
    
  3. 打開快速命令列輸入 Reload Window 重新啟動 VSCode

參考資料