打造專屬的 CLI - iTerm2 & Oh My Zsh


Posted by Wes on 2020-06-14

在安裝 iTerm2 之前,我主要使用 VS Code Terminal 和 Mac Terminal,都是最基本的黑白畫面,不過既然之後要常常用到 Command Line,不如就用好看一點的 CLI 吧!

iTerm2

如果不滿意作業系統內建的 Terminal,那麼 iTerm2 是個好選擇,iTerm2 的介面好看、操作容易,可以開多個 Tabs,還有不少 Plugins,使用者可以依據個人喜好,客製化不同的介面。

首先下載並安裝 iTerm2,選擇喜歡的 主題,儲存 .itermcolors 為副檔名

Preference > Profiles > Colors 設定,右下角有一個 Color Presets...,Import 自己喜歡的 .itermcolors,重新啟動 iTerm2 就可以看到主題的樣式,我自己是用 Ryuuko

zsh

如果預設的 shell 是 bash,可以換成 zsh,會好用非常多

先安裝 Homebrew

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

透過 Homebrew 安裝 zsh

brew install zsh

將原本預設的 bash 改成 zsh

sudo sh -c "echo $(which zsh) >> /etc/shells"
chsh -s $(which zsh)

確認是否安裝成功

echo $SHELL

如果設定成功,會顯示以下訊息

/bin/zsh

Oh My Zsh

oh-my-zsh 是 zsh 的套件管理工具,可以透過 curl 安裝

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

更多的套件可以在 awesome-zsh-pluginsoh-my-zsh plugins 找到,我有安裝 zsh-autosuggestionszsh-syntax-highlighting

zshrc

.zshrc 是 zsh 的設定檔,之後所有設定都在這個檔案做調整

Theme

預設的主題是 ZSH_THEME="robbyrussell"

想更換主題的話,只要更改 ZSH_THEME 的值即可,例如:

ZSH_THEME="agnoster" 
# (this is one of the fancy ones)

# see https://github.com/ohmyzsh/ohmyzsh/wiki/Themes#agnoster

Note: many themes require installing the Powerline Fonts in order to render properly.

https://cloud.githubusercontent.com/assets/2618447/6316862/70f58fb6-ba03-11e4-82c9-c083bf9a6574.png

Powerlevel10k

Powerlevel10k is a theme for Zsh. It emphasizes speed, flexibility and out-of-the-box experience.

透過 Oh My Zsh 安裝

git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/themes/powerlevel10k
  1. Set ZSH_THEME="powerlevel10k/powerlevel10k" in ~/.zshrc
  2. Type p10k configure to access the builtin configuration wizard right from your terminal.

https://raw.githubusercontent.com/romkatv/powerlevel10k-media/master/configuration-wizard.gif

記得將 iTerm2 的字型改為 MesloLGS NF ,才能正確顯示 icon,設定路徑是 Preference > Profiles > Text > Font

Final Result

Theme: Ryuuko.itermcolors + Powerlevel10k

小提醒:任何的 zsh 設定修改過後,還要執行以下指令才會生效(或者重新啟動終端機)

exec $SHELL

References


#CLI #terminal #iterm2 #zsh #OhMyZsh







Related Posts

[Web 開發] Chrome+Postman 複製頁面 API

[Web 開發] Chrome+Postman 複製頁面 API

Google Cloud Source Repositories 使用紀錄

Google Cloud Source Repositories 使用紀錄

day01 安裝android studio + 認識adb

day01 安裝android studio + 認識adb


Comments