iTerm2+zsh打造漂亮好用的終端環(huán)境

我的個(gè)人博客,iTerm+zsh打造漂亮好用的終端環(huán)境

注:適用于使用MAC開發(fā)的Developer

身為程序開發(fā)者,很大一部分的時(shí)間是在用Command Line做事,如果能把Command Line調(diào)整得好用又炫酷的模樣,不只是效率提升很懂,用起來爽度也比較高。

最后大概會(huì)是這個(gè)樣子:

zsh-pretty.png

如下安裝步:

總共有以下步驟:

  1. 安裝 iTerm2
  2. 修改 iTerm2 的 color scheme
  3. 安裝 powerline font
  4. 安裝 zsh
  5. 安裝 oh-my-zsh
  6. 安裝 zsh theme: powerlevel9k
  7. 設(shè)置 powerlevel9k

步驟看似很多,但是其實(shí)都很簡(jiǎn)單。

安裝iTerm2:

安裝方式:

brew install iterm2

或者去官網(wǎng)下載安裝都可以。

安裝好以后,打開 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ì)不舒服,顏色飽和度也適中,看起來質(zhì)感比較好。

安裝powerline font

因?yàn)橐恍﹖heme會(huì)用到特殊的icon,所以必須選擇支持這些特殊icon的font。這些字體統(tǒng)稱為powerline font。

你可以看我上面那張圖中,vcs相關(guān)的圖片,如果顯示不了會(huì)出現(xià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

如果沒有安裝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好看多了。

不過 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è)定修改過后,還要執(zhí)行以下指令才會(huì)生效

exec $SHELL

推薦另外一個(gè)超強(qiáng)的主題,powerlevel9k!

[圖片上傳失敗...(image-1a7073-1538380715632)]

圖片來源: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

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容