- 安裝 iTerm2
- 修改 iTerm2 的 color scheme
- 安裝 powerline font
- 安裝 zsh
- 安裝 oh-my-zsh
- 安裝 zsh theme: powerlevel9k
- 設(shè)置 powerlevel9k
安裝iTerm2
brew search iterm
在搜索結(jié)果中安裝
brew cask install iterm2
安裝好以后 打開(kāi)
Preferences > Profiles > Terminal > Report Terminal Type
改為 xterm-256color,才能在 terminal 中看得到漂亮的顏色。
修改iTerm2的color scheme
打開(kāi):Preferences > Profiles > Colors > Color Presets...
里面很一些內(nèi)置的配色,也可以到iTerm2 Color Schemes中把這個(gè)git repo下載到電腦中,然后import到iTerm2中。
安裝powerline font
因?yàn)橐恍﹖heme會(huì)用到特殊的icon,所以必須選擇支持這些特殊icon的font。這些字體統(tǒng)稱(chēng)為powerline font。
安裝powerline字體指令:
git clone https://github.com/powerline/fonts.git
cd fonts
./install.sh
rm -rf ../fonts
先執(zhí)行,才能用 homebrew 安裝字體。
brew Tap homebrew/cask-fonts
安裝
brew cask install font-sourcecodepro-nerd-font
brew 上面也有很多字型可以挑,可是使用:
brew search nerdfont
brew cask install font-hack-nerd-font
裝完后,修改 iTerm2 字體設(shè)定
Preferences > Profiles > Text > Change Font 選擇Sauce Code Powerline字體。
安裝zsh:
檢查當(dāng)前默認(rèn)的shell:
echo $0
查看機(jī)器上支持哪些shell:
cat /etc/shells
切換到zsh:
chsh -s /bin/zsh
如果沒(méi)有安裝zsh,可以執(zhí)行如下操作:
brew install zsh
sudo sh -c "echo $(which zsh) >> /etc/shells"
chsh -s $(which zsh)
iTerm2設(shè)定路徑:Preferences > Profiles > General > Command,改為
/bin/zsh
安裝oh-my-zsh:
安裝指令:
sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
安裝 zsh theme powerlevel9k
安裝好oh-my-zsh以后,默認(rèn)theme為robbyrussell,多了一些git資訊,顏色也比原生bash好看多了。
不過(guò) oh-my-zsh 內(nèi)建很多 theme,在它的 github wiki 上有很多截圖可以參考。
powerlevel9k 不只是像上面的示例顯示的一些基本資訊,還可以做到很屌的事情,比如 WiFi信號(hào)強(qiáng)度、電池電力、CPU loading、system free memory 等等在 command line
powerlevel9k 安裝方式:
1.下載
powerlevel9k 不是 oh-my-zsh 內(nèi)建的 theme ,必須另外下載:
git clone https://github.com/bhilburn/powerlevel9k.git ~/.oh-my-zsh/custom/themes/powerlevel9k
2. 設(shè)置主題
編輯你的 ~/.zshrc ,把 ZSH_THEME 設(shè)置為 powerlevel9k,并設(shè)置哪些東西可以顯示在 command line 上:
#字體設(shè)定 (注意,字體設(shè)定必須放在主題之前)
POWERLEVEL9K_MODE='nerdfont-complete'
#主題設(shè)定
ZSH_THEME="powerlevel9k/powerlevel9k"
# command line 左邊顯示的內(nèi)容
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(os_icon context dir vcs virtualenv)
# command line 右邊顯示的內(nèi)容
POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(time)
最后執(zhí)行
exec $SHELL # 或
vcs 為 version control system 的縮寫(xiě)
還有非常非常多東西可以用,請(qǐng)參考這個(gè)列表自己玩玩看https://github.com/bhilburn/powerlevel9k#available-prompt-segments