一.ITerm2簡(jiǎn)介
1.安裝
iTerm2 是一款完全免費(fèi)的,專為 Mac OS 用戶打造的命令行應(yīng)用。直接在官網(wǎng)上http://iterm2.com/?下載并安裝即可。
2.配置
設(shè)置ITerm為默認(rèn)終端

二.安裝 oh-my-zsh
1.查看系統(tǒng)有幾個(gè)shell
cat /etc/shells
回顯是這個(gè)
/bin/bash
/bin/csh
/bin/ksh
/bin/sh
/bin/tcsh
/bin/zsh
bash是mac中terminal自帶的shell,把它換成zsh,這個(gè)的功能要多得多。擁有語(yǔ)法高亮,命令行tab補(bǔ)全,自動(dòng)提示符,顯示Git倉(cāng)庫(kù)狀態(tài)等功能。
使用下面命令設(shè)置默認(rèn)shell
chsh -s /bin/zsh
2.安裝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)"
3.主題
安裝成功后,用vim ~/.zshrc打開(kāi)隱藏文件,修改主題為agnoster
PS:zsh主題,參考主題連接選擇自己喜歡的主題。
ZSH_THEME="agnoster"
應(yīng)用這個(gè)主題需要特殊的字體支持,否則會(huì)出現(xiàn)亂碼情況,這時(shí)我們來(lái)配置字體:
1.使用?Meslo?字體,點(diǎn)開(kāi)連接點(diǎn)擊 view raw 下載字體。
2.安裝字體到系統(tǒng)字體冊(cè)。
3.應(yīng)用字體到iTerm2下,設(shè)置自己喜歡看著舒服的字號(hào),我設(shè)置的14px(iTerm -> Preferences -> Profiles -> Text -> Change Font)。

4.設(shè)置配色方案
通過(guò)oh-my-zsh設(shè)置完主題后,使用ITerm2自帶的幾個(gè)背景色顯示看得不舒服,下載其他的顏色方案較美觀。我選用的是solarized,效果還不錯(cuò)。點(diǎn)開(kāi)官網(wǎng),下載,解壓,然后打開(kāi) iTerm2 下的偏好設(shè)置 preference ,點(diǎn)開(kāi) profiles 下的colors 選項(xiàng),點(diǎn)擊右下角的 Color Presets 選項(xiàng),選擇import ,導(dǎo)入解壓到的 solarized 文件下的Solarized Dark.itermcolors。后面對(duì)vim進(jìn)行配色的時(shí)候也會(huì)用到這個(gè)solarized
到這步我們的終端看上去已經(jīng)非常好看了,這時(shí)我們來(lái)安裝其它插件,讓終端看起來(lái)更加風(fēng)騷。
5.自動(dòng)提示命令
當(dāng)我們輸入命令時(shí),終端會(huì)自動(dòng)提示你接下來(lái)可能要輸入的命令,這時(shí)按 → 便可輸出這些命令,非常方便。
設(shè)置如下:
1.克隆倉(cāng)庫(kù)到本地 ~/.oh-my-zsh/custom/plugins 路徑下
git clone git://github.com/zsh-users/zsh-autosuggestions?$ZSH_CUSTOM/plugins/zsh-autosuggestions
2.用 vim? ~/.zshrc 打開(kāi)文件,下滑找到插件設(shè)置命令,默認(rèn)是?plugins=(git) ,我們把它修改為
plugins=(zsh-autosuggestions git)
3.重新打開(kāi)終端窗口。
4.語(yǔ)法高亮
1.使用homebrew安裝zsh-syntax-highlighting 插件。
brew?install?zsh-syntax-highlighting
2. vim ~/.zshrc配置文件,插入一行,保存退出。
source??/usr/local/Cellar/zsh-syntax-highlighting/0.6.0/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
PS:上面的路徑是brew安裝插件成功后的路徑,安裝成功會(huì)有顯示,復(fù)制記錄一下。
3.輸入命令。
source?~/.zshrc
PS:安裝homebrew包管理工具:
/usr/bin/ruby?-e?"$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
安裝完成后顯示效果

三.給ITerm中Vim配色
Vim 的配色最好和終端的配色保持一致,不然在 Terminal/iTerm2 里使用命令行 Vim 會(huì)很別扭。
首先下載solarized,上文有下載方法和地址。執(zhí)行以下命令
$ cd solarized
$ cd vim-colors-solarized/colors
$ mkdir -p ~/.vim/colors?
$ cp solarized.vim ~/.vim/colors/
$ vi ~/.vimrc
加入下面三行設(shè)置即可
syntax enable
set background=dark
colorscheme solarized
顯示效果

四.給ITerm2中l(wèi)s配色
1.下載安裝?coreutils
brew install coreutils
2.創(chuàng)建顏色配置文件
gdircolors --print-database > ~/.dir_colors
3.啟用顏色配置文件
sudo vim ~/.zshrc
添加如下即可
if brew list | grep coreutils > /dev/null ; then PATH="$(brew --prefix coreutils)/libexec/gnubin:$PATH" alias ls='ls -F --show-control-chars --color=auto' eval `gdircolors -b $HOME/.dir_colors` fi
最后,希望本文對(duì)這方面需求的小伙伴,啟到幫助的作用!
可用到的參考鏈接:
Mac下終端配置(item2 + oh-my-zsh + solarized配色方案)