2018年更新:
使用過程中發現 agnoster 這個主題雖然美觀,但是在實際使用過程中對使用者來說并不是很友好,個人來說 ys 主題更适合我。
更改主題:
ZSH_THEME="ys"
最近重裝了系統,于是便重新配置了一下終端,使其更符合使用者習慣。
效果如下:
![](https://img.laitimes.com/img/_0nNw4CM6IyYiwiM6ICdiwiIn5GcugzYjZTNmRDN1IDOlBDOlljZ4QWYxYjN1YTZlBzMwQDZfdWbp9CXt92Yu4GZjlGbh5SZslmZxl3Lc9CX6MHc0RHaiojIsJye.png)
擁有文法高亮,指令行tab補全,自動提示符,顯示Git倉庫狀态等功能。
安裝
首先我們下載下傳的 iTem2 這個軟體,比Mac自帶的終端更加強大。直接官網
http://iterm2.com/下載下傳并安裝即可。
配置
将iTem2設定為預設終端:
(菜單欄)iTerm2 -> Make iTerm2 Default Term
然後打開偏好設定preference,選中Keys,勾選Hotkey下的Show/hide iTerm2 with a system-wide hotkey,将熱鍵設定為command+. ,這樣你就可以通過command+. 全局熱鍵來打開或關閉iTerm2視窗,非常友善。
配色方案
我選用的是
solarized,效果還不錯。點開官網,下載下傳,解壓,然後打開 iTerm2 下的偏好設定 preference ,點開 profiles 下的colors 選項,點選右下角的 Color Presets 選項,選擇import ,導入解壓到的 solarized 檔案下的Solarized Dark.itermcolors。
安裝oh-my-zsh
github連接配接:
https://github.com/robbyrussell/oh-my-zsh使用 crul 安裝:
sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
或使用wget:
sh -c "$(wget https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"
主題
安裝成功後,用vim打開隐藏檔案 .zshrc ,修改主題為 agnoster:
ZSH_THEME="agnoster"
應用這個主題需要特殊的字型支援,否則會出現亂碼情況,這時我們來配置字型:
1.使用
Meslo字型,點開連接配接點選 view raw 下載下傳字型。
2.安裝字型到系統字型冊。
3.應用字型到iTerm2下,我自己喜歡将字号設定為14px,看着舒服(iTerm -> Preferences -> Profiles -> Text -> Change Font)。
4.重新打開iTerm2視窗,這時便可以看到效果了。
到這步我們的終端看上去已經非常好看了,這時我們來安裝其它插件,讓終端看起來更加風騷。
自動提示指令
當我們輸入指令時,終端會自動提示你接下來可能要輸入的指令,這時按 → 便可輸出這些指令,非常友善。
設定如下:
1.克隆倉庫到本地 ~/.oh-my-zsh/custom/plugins 路徑下
git clone git://github.com/zsh-users/zsh-autosuggestions $ZSH_CUSTOM/plugins/zsh-autosuggestions
2.用 vim 打開 .zshrc 檔案,找到插件設定指令,預設是 plugins=(git) ,我們把它修改為
plugins=(zsh-autosuggestions git)
3.重新打開終端視窗。
PS:當你重新打開終端的時候可能看不到變化,可能你的字型顔色太淡了,我們把其改亮一些:
移動到 ~/.oh-my-zsh/custom/plugins/zsh-autosuggestions 路徑下
cd ~/.oh-my-zsh/custom/plugins/zsh-autosuggestions
用 vim 打開 zsh-autosuggestions.zsh 檔案,修改 ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=10' ( fg=10 在我電腦上顯示良好)。
文法高亮
1.使用homebrew安裝
zsh-syntax-highlighting 插件。
brew install zsh-syntax-highlighting
2.配置.zshrc檔案,插入一行。
source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
3.輸入指令。
source ~/.zshrc
PS:安裝homebrew包管理工具:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
*這時候打開終端視窗,你的終端看起來就和我的一樣漂亮了~
*use it and enjoy it~