使用mac osx一年以來,自帶的Terminal終端一直都是白底黑字,食之無味,越來越缺乏新鮮感,怎么也得想個法子來刺激下眼球。
不然花那么多大洋買你回來是要哪般,難道真是為來學(xué)習(xí)工作???
怎么可能,不裝逼誰TM買蘋果。。。好吧,其實(shí)為來工作學(xué)習(xí),裝逼純屬業(yè)余。

完成配置后的終端具備功能:
- 語法高亮
- 命令行tab補(bǔ)全
- 自動提示符
- 顯示Git倉庫狀態(tài)等功能
- cmd+r 快速清空代碼面板,跟終端輸入clear一樣的效果
安裝步驟
1. 下載iTerm2
2. 解壓后安裝iTerm2并打開
-
iTerm2 -> Make iTerm2 Default Term
將iTerm2設(shè)置為默認(rèn)終端 -
打開偏好設(shè)置preference,選中Keys,勾選Hotkey下的Show/hide iTerm2 with a system-wide hotkey,將熱鍵設(shè)置為 ?+. ,這樣你就可以通過 ?+. 全局熱鍵來打開或關(guān)閉iTerm2窗口,非常方便
設(shè)置Hotkey
3. 配色方案
選用 solarized,下載解壓,然后打開 iTerm2 下的偏好設(shè)置 preference ,點(diǎn)開 profiles 下的colors 選項,點(diǎn)擊右下角的 Color Presets 選項,選擇import ,導(dǎo)入解壓到的 solarized 文件下的Solarized Dark.itermcolors

4. 安裝oh-my-zsh
github:https://github.com/robbyrussell/oh-my-zsh
官方提供 curl 和 wget 兩種安裝方式
curl 安裝:
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 -)"
5. 配置主題
安裝oh-my-zsh成功后
用 vim 編輯隱藏文件 .zshrc, 終端輸入
vi ~/.zshrc
ZSH_THEME="agnoster"將zsh主題修改為“agnoster”應(yīng)用“agnoster”主題需要特殊的字體支持,否則會出現(xiàn)亂碼情況,
使用 Meslo 字體,點(diǎn)開鏈接點(diǎn)擊 view raw 下載字體安裝字體到系統(tǒng)字體冊
-
在iTerm2中應(yīng)用字體 iTerm -> Preferences -> Profiles -> Text -> Change Font)
iTerm2應(yīng)用字體 重新打開iTerm2窗口(或新打開一個iTerm2窗口)即可以看到字體效果
6. 自動提示與命令補(bǔ)全
比iTerm2自帶的更強(qiáng)大的命令提示與補(bǔ)全
克隆倉庫到本地 ~/.oh-my-zsh/custom/plugins 路徑下
git clone git://github.com/zsh-users/zsh-autosuggestions $ZSH_CUSTOM/plugins/zsh-autosuggestions用 vim 編輯 .zshrc 文件,找到插件設(shè)置命令,默認(rèn)是
plugins=(git),我們把它修改為plugins=(zsh-autosuggestions git)
PS:當(dāng)你重新打開終端時可能看不到變化,可能你的字體顏色太淡了,我們把其改亮一些:
cd ~/.oh-my-zsh/custom/plugins/zsh-autosuggestions- 用 vim 編輯 zsh-autosuggestions.zsh 文件,修改
ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=10'
7. 語法高亮效果
- 使用homebrew包管理工具安裝 zsh-syntax-highlighting 插件
brew install zsh-syntax-highlighting
如果電腦上還沒有安裝homebrew,請先安裝homebrew
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" - 配置.zshrc文件,插入一行
source /xxx/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
(注意: /xxx/ 代表.zshrc所在的路徑) - 加載.zshrc配置
source ~/.zshrc - 重新打開iTerm2窗口(或新打開一個iTerm2窗口)即可以看到效果
擴(kuò)展
- iTerm2 默認(rèn)使用dash改用zsh解決方法:
chsh -s /bin/zsh - iTerm2 zsh切換回原來的dash:
chsh -s /bin/bash - 卸載
oh my zsh,在命令行輸入:uninstall_oh_my_zsh - 路徑前綴的XX@XX太長,縮短問題:
編輯~/.oh-my-zsh/themes/agnoster.zsh-theme主體文件,將里面的build_prompt下的prompt_context字段在前面加#注釋掉即可
作者:以樂之名
本文原創(chuàng),有不當(dāng)?shù)牡胤綒g迎指出。轉(zhuǎn)載請指明出處。


