我的個(gè)人博客,iTerm+zsh打造漂亮好用的終端環(huán)境
注:適用于使用MAC開(kāi)發(fā)的Developer
身為程序開(kāi)發(fā)者,很大一部分的時(shí)間是在用Command Line
做事,如果能把Command Line
調(diào)整得好用又炫酷的模樣,不只是效率提升很懂,用起來(lái)爽度也比較高芙代。
最后大概會(huì)是這個(gè)樣子:
如下安裝步:
總共有以下步驟:
- 安裝 iTerm2
- 修改 iTerm2 的 color scheme
- 安裝 powerline font
- 安裝 zsh
- 安裝 oh-my-zsh
- 安裝 zsh theme: powerlevel9k
- 設(shè)置 powerlevel9k
步驟看似很多,但是其實(shí)都很簡(jiǎn)單蠢箩。
安裝iTerm2:
安裝方式:
brew install iterm2
或者去官網(wǎng)下載安裝都可以链蕊。
安裝好以后,打開(kāi) iTerm2 檢查 Report Terminal Type 的設(shè)定谬泌,設(shè)定路徑:Preferences > Profiles > Terminal > Report Terminal Type
改為 xterm-256color
滔韵,才能在 terminal 中看得到漂亮的顏色。
修改iTerm2的color scheme
設(shè)定路徑:Preferences > Profiles > Colors > Color Presets...
里面很一些內(nèi)置的掌实,也可以到iTerm2 Color Schemes中把這個(gè)git repo下載到電腦中陪蜻,然后import到iTerm2中。
我自己是用 Tomorrow Night Eighties贱鼻,優(yōu)點(diǎn)是對(duì)比不會(huì)太強(qiáng)比較不刺眼宴卖,屏幕盯久了不會(huì)不舒服,顏色飽和度也適中邻悬,看起來(lái)質(zhì)感比較好症昏。
安裝powerline font
因?yàn)橐恍﹖heme會(huì)用到特殊的icon,所以必須選擇支持這些特殊icon的font父丰。這些字體統(tǒng)稱為powerline font肝谭。
你可以看我上面那張圖中,vcs相關(guān)的圖片,如果顯示不了會(huì)出現(xiàn)框框問(wèn)號(hào)攘烛。
支持 powerline 的字型很多魏滚,我推薦 Sauce Code Pro Nerd Font Complete
安裝powerline
字體指令:
git clone https://github.com/powerline/fonts.git
cd fonts
./install.sh
rm -rf ../fonts
# 先執(zhí)行,才能用 homebrew 安裝字體坟漱。
brew tap caskroom/fonts
# 安裝指令
brew cask install font-sourcecodepro-nerd-font
brew 上面也有很多字型可以挑鼠次,可是使用:
brew search nerd
裝完后,記得修改 iTerm2 字體設(shè)定否則不會(huì)生效芋齿。請(qǐng)改成 SauceCodePro Nerd Font 或你自己下載的字體腥寇。
設(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 上有很多截圖可以參考聂示。
切換內(nèi)建的 theme 很簡(jiǎn)單域携,直接修改你的 ~/.zshrc
,把原本 ZSH_THEME=”robbyrussell”
改成你想要的:
# 編輯 ~/.zshrc
ZSH_THEME="agnoster" # 看把 robbyrussell 改成 agnoster
任何的 zsh 設(shè)定修改過(guò)后鱼喉,還要執(zhí)行以下指令才會(huì)生效
exec $SHELL
推薦另外一個(gè)超強(qiáng)的主題秀鞭,powerlevel9k!
[圖片上傳失敗...(image-1a7073-1538380715632)]
圖片來(lái)源:https://github.com/bhilburn/powerlevel9k
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 上:
ZSH_THEME="powerlevel9k/powerlevel9k"
# command line 左邊顯示的內(nèi)容
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir)
# command line 右邊顯示的內(nèi)容
POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(time)
如果想要看vcs
(vcs 為 version control system 的縮寫):
# 編輯 ~/.zshrc
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir vcs) # 加上 "vcs"
還有非常非常多東西可以用,請(qǐng)參考這個(gè)列表自己玩玩看https://github.com/bhilburn/powerlevel9k#available-prompt-segments