Try   HackMD

Terminal 美化 (iTerm2 + powerlevel10k)

這是一篇隨處可見的 iTerm2 安裝教學

有鑒於自己是廢物,所以想把步驟寫到最細,希望可以幫助到跟我一樣沒有技術、但又想要美美 Terminal 的人

先上成品圖

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

前置作業

接下來所有動作都會用到 Homebrew >< macOS 很好用的套件管理,可以先裝

  • 教學可參考 官方網站
  • 安裝指令
    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  • 檢查安裝完成否
    brew --version

正文開始

iTerm2 安裝

brew install iTerm2

zsh 安裝

想要美美的 commandLine 上色嗎?zsh 裝起來!

macOS 預設 shell 為 bash,zsh 和 bash 差異以及 zplug 關係,可以看這篇 第 11 天:終端機功夫

至於 macOS 10.14 Mojave 開始就自帶內建 zsh,可以免去安裝步驟owo

  • bash 切換至 zsh
    chsh -s /bin/zsh

執行完畢後記得退出重開

oh-my-zsh 安裝

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

powerlevel10k 安裝

git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ~/powerlevel10k
裝完之後重啟,輸入 p10k congigure 開始進入設定啦!

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

不得不說跟 powerlevel9k 比起來,這更新功能真的是智障福音

好用 Plugin

其實只是看各篇文章大家都裝,就跟著裝一下啦

  • Syntax Highlighting Plugin
    • 自動檢查語法
      git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting\n
  • ZSH-AutoSuggestion Plugin
    • 自動記憶歷史執行過的指令
      git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions

安裝完畢後要到 ~/.zshrc 檔案中新增這兩個 Plougin

plugins=( git zsh-autosuggestions zsh-syntax-highlighting )

美美的主題

我使用的是 Nord 這套,幾乎各平台、編輯器都有可套用主題,美爆!官網這裡走

主題套用

有空再來補XD 總之就是把主題套上去+背景模糊

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

每次打開 iTerm2 會直接在螢幕上方

左右側顯示

總之就是這裡的設定

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

打開 ~/.p10k.zsh 找到 POWERLEVEL9K_LEFT_PROMPT_ELEMENTS 以及 POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS 去做設定,相關參數可參考開發者的 README.md

  • 這是我的左側設定,右側就沒有動太多了
# The list of segments shown on the left. Fill it with the most important segments. typeset -g POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=( context os_icon # os identifier dir current directory vcs # git status # prompt_char # prompt symbol )

額外需要紀錄的,context 設定會顯示 user@host,這邊需要調整參數才會有結果

拉到同一份文件最底下找到

##################################[ context: user@hostname ]################################## # Default context format (no privileges, no SSH): user@hostname. 下面這行要註解 # typeset -g POWERLEVEL9K_CONTEXT_TEMPLATE='%n@%m' # # Don't show context unless running with privileges or in SSH. # Tip: Remove the next line to always show context. # typeset -g POWERLEVEL9K_CONTEXT_{DEFAULT,SUDO}_{CONTENT,VISUAL_IDENTIFIER}_EXPANSION= # Custom icon. # typeset -g POWERLEVEL9K_CONTEXT_VISUAL_IDENTIFIER_EXPANSION='⭐' # Custom prefix. 下面這行要註解 # typeset -g POWERLEVEL9K_CONTEXT_PREFIX='with '

參考資料

總之就是東抄西抄