noeFly's profile picture

終端美化——zsh

終端機大概是一個開發者常常看到的東西吧?那就用好看一點吧!

zshLinux

5/19/2026

終端機大概是一個開發者常常看到的東西吧?那就用好看一點吧!

安裝 zsh

  1. 安裝 zsh 和 git

    $ sudo apt install zsh git
  2. 設定預設終端為 zsh

    tip
    變更預設終端機會在下次登入後生效。
    sh chsh -s $(which zsh)

安裝 Nerd Font 字體

Nerd Font 除了原字體提供的等寬特性,也提供了可以在終端機中顯示的特殊圖標!

  1. 前往 ryanoasis/nerd-fonts 發布頁面。https://github.com/ryanoasis/nerd-fonts/releases

  2. 在下方的 Assets 部份選擇自己喜歡的字體並下載。

  3. 回到終端機的應用程式中更換為 Nerd Font 字體。

正式開始美化終端機

  1. 安裝 oh-my-zsh

    sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
  2. 安裝 powerlevel p10k

    git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k
  3. 編輯 ~/.zshrc,其中的 ZSH_THEME 設定修改為 "powerlevel10k/powerlevel10k"

    ZSH_THEME="powerlevel10k/powerlevel10k"
  4. 讓 zsh 設定立即生效

    source ~/.zshrc
  5. 跟隨 powerlevel 10k 的指示,完成主題設定

tip

如果沒有自動跳出設定提示,可以使用以下指令:

p10k configure

安裝插件

zsh-completions

指令自動補全。

  1. 下載插件

    git clone https://github.com/zsh-users/zsh-completions ${ZSH_CUSTOM:-${ZSH:-~/.oh-my-zsh}/custom}/plugins/zsh-completions
  2. 編輯 ~/.zshrc,在設定檔中尋找 source $ZSH/oh-my-zsh.sh,在上面一行新增

    fpath+=${ZSH_CUSTOM:-${ZSH:-~/.oh-my-zsh}/custom}/plugins/zsh-completions/src
tip

如果你不太理解的話,新增完之後就會長這樣:

git clone https://github.com/zsh-users/zsh-completions ${ZSH_CUSTOM:-${ZSH:-~/.oh-my-zsh}/custom}/plugins/zsh-completions
source $ZSH/oh-my-zsh.sh

zsh-autoseggestions

根據過去的歷史紀錄,建議指令。

  1. 下載插件

    git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
  2. 編輯 ~/.zshrc,在 plugins=() 的括號中,新增 zsh-autosuggestions

    plugins=(zsh-autosuggestions)
tip
如果有多個插件,則不同插件之間要用空格隔開。

zsh-syntax-highlighting

為你的指令新增高亮標注。

  1. 下載插件

    git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
  2. 編輯 ~/.zshrc,在 plugins=() 的括號中,新增 zsh-syntax-highlighting

    plugins=(zsh-syntax-highlighting)

參考資料

  • https://github.com/ohmyzsh/ohmyzsh
  • https://github.com/zsh-users/zsh-completions
  • https://github.com/zsh-users/zsh-autosuggestions
  • https://github.com/zsh-users/zsh-syntax-highlighting
  • https://github.com/NCU-GS4538-Linux/Linux-Community/discussions/84