一棺禾、iTerm2簡(jiǎn)介
iTerm 2 is a terminal emulator for Mac OS X that does amazing things.
1. 安裝
官網(wǎng)下載:http://iterm2.com/
Term2 是一款完全免費(fèi)的恼布,專為 Mac OS 用戶打造的命令行應(yīng)用。直接在官網(wǎng)上下載册踩。
下載的是壓縮文件,解壓后是執(zhí)行程序文件效拭,你可以直接雙擊暂吉,或者直接將它拖到 Applications 目錄下。
或者你可以直接使用 Homebrew 進(jìn)行安裝:
brew cask install iterm2
2. 配置
-
設(shè)置ITerm2為默認(rèn)終端
設(shè)置ITerm2為默認(rèn)終端 配置iTerm2主題
iTerm2 最常用的主題是 Solarized Dark theme缎患,下載地址:http://ethanschoonover.com/solarized
下載的是壓縮文件慕的,你先解壓一下,然后打開(kāi) iTerm2挤渔,按Command + ,
鍵肮街,打開(kāi) Preferences 配置界面,然后Profiles -> Colors -> Color Presets -> Import
判导,選擇剛才解壓的solarized->iterm2-colors-solarized->Solarized Dark.itermcolors
文件嫉父,導(dǎo)入成功,最后選擇 Solarized Dark 主題眼刃,就可以了绕辖。
新版本中該字體已經(jīng)存在,不需要導(dǎo)入可直接選擇擂红。
二仪际、安裝 oh-my-zsh
1. 查看系統(tǒng)有幾個(gè)shell
cat /etc/shells
# List of acceptable shells for chpass(1).
# Ftpd will not allow users to connect who are not using
# one of these shells.
/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蹦玫,bash和zsh切換
# 切換到bash
chsh -s /bin/bash
# 切換到zsh
chsh -s /bin/zsh
記得輸入切換命令后赎婚,要重新打開(kāi)終端terminal才生效哦雨饺!
1.1 安裝最新版本 zsh
github安裝地址:https://github.com/robbyrussell/oh-my-zsh/wiki/Installing-ZSH
在 macOS 中,已經(jīng)自帶了 /bin/zsh
惑淳,但是它未必是最新版本额港。
可以通過(guò)執(zhí)行 echo $SHELL
查看 當(dāng)前所使用的是哪個(gè)版本的shells,(所有shells 可在/etc/shells 中查看 )
- macOS下安裝
brew install zsh zsh-completions
由于是用brew安裝歧焦,所以新版 zsh 文件是在 /usr/local/bin/zsh
-
/etc/shells
配置中追加/usr/local/bin/zsh
移斩,添加后內(nèi)容如下:
/bin/bash
/bin/csh
/bin/ksh
/bin/sh
/bin/tcsh
/bin/zsh
# 追加 brew 安裝的最新版本zsh
/usr/local/bin/zsh
如果不在/etc/shells
配置文件中添加 /usr/local/bin/zsh
,那在執(zhí)行chsh
時(shí)會(huì)報(bào)錯(cuò)绢馍,提示 non-standard shell向瓷。
- 切換 新 zsh
chsh -s /usr/local/bin/zsh
2. 安裝oh-my-zsh
官網(wǎng)地址:https://ohmyz.sh/
github地址:https://github.com/robbyrussell/oh-my-zsh
- 使用
curl
安裝:
sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
- 使用
wget
安裝:
sh -c "$(wget -O- https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
- zsh 設(shè)置為當(dāng)前用戶的默認(rèn) Shell
chsh -s /bin/zsh
3. 配置oh-my-zsh主題
github主題使用地址:https://github.com/robbyrussell/oh-my-zsh/wiki/Themes
zsh主題列表:https://github.com/robbyrussell/oh-my-zsh/tree/master/themes/
安裝成功后,用戶$HOME
目錄下會(huì)出現(xiàn) .zshrc
文件舰涌,用 vim ~/.zshrc
打開(kāi)隱藏文件猖任,將主題配置修改為 agnoster
,修改如下
ZSH_THEME="agnoster"
PS:
agnoster
是比較常用的 zsh 主題之一瓷耙,你可以挑選你喜歡的主題 zsh主題列表
4. Powerline 字體下載安裝
Powerline下載:https://github.com/powerline/fonts
iTerm2 改為主題之后朱躺,會(huì)出現(xiàn)亂碼的情況。需要安裝 Powerline 字體來(lái)解決搁痛。
# clone 先克隆
git clone https://github.com/powerline/fonts.git
# install 后安裝
cd fonts
./install.sh
可以按照以上命令進(jìn)行 powerline 全部字體安裝长搀,也可以選擇部份字體安裝;而我選擇 Meslo 一個(gè)字體安裝
- 下載 Meslo 字體下載
- 雙擊字體鸡典,安裝到 Mac OS 系統(tǒng)字體冊(cè)
安裝完字體庫(kù)之后源请,打開(kāi) iTerm2,按 Command + ,
鍵彻况,打開(kāi) Preferences 配置界面谁尸,然后 Profiles -> Text -> Font -> Chanage Font
,選擇 Meslo LG M Regular for Powerline 字體纽甘。
當(dāng)然良蛮,如果你覺(jué)得默認(rèn)的 12px
字體大小不合適,可以自己進(jìn)行修改贷腕。
5. 設(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)騷允蜈。
6. 語(yǔ)法高亮
6.1 Oh-my-zsh下高亮安裝方法【推薦】
github上說(shuō)明地址:https://github.com/zsh-users/zsh-syntax-highlighting/blob/master/INSTALL.md
- Clone this repository in oh-my-zsh's plugins directory:
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
- Activate the plugin in
~/.zshrc
:
plugins=( [plugins...] zsh-syntax-highlighting)
- Restart zsh (such as by opening a new instance of your terminal emulator).
6.2 使用 Homebrew 安裝zsh-syntax-highlighting
插件:
brew install zsh-syntax-highlighting
- 安裝成功之后,編輯
vim ~/.zshrc
文件蒿柳,在最后一行增加下面配置:
source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
# 其它地方配置參考
# source /usr/local/Cellar/zsh-syntax-highlighting/0.6.0/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
- 執(zhí)行
source ~/.zshrc
使生效
7. 自動(dòng)提示命令
當(dāng)我們輸入命令時(shí)饶套,終端會(huì)自動(dòng)提示你接下來(lái)可能要輸入的命令,這時(shí)按 →
便可輸出這些命令垒探,非常方便妓蛮。
- 先克隆
zsh-autosuggestions
項(xiàng)目,到本地~/.oh-my-zsh/custom/plugins
路徑下:
git clone git://github.com/zsh-users/zsh-autosuggestions $ZSH_CUSTOM/plugins/zsh-autosuggestions
git clone https://github.com/zsh-users/zsh-autosuggestions.git $ZSH_CUSTOM/plugins/zsh-autosuggestions
- 然后編輯
vim ~/.zshrc
文件圾叼,找到plugins
配置蛤克,增加zsh-autosuggestions
插件。默認(rèn)是 plugins=(git)
plugins=(zsh-autosuggestions git)
有時(shí)候因?yàn)樽詣?dòng)提示命令的顏色和背景顏色很相似夷蚊,以至于自動(dòng)填充沒(méi)有效果咖耘,我們可以手動(dòng)更改下自動(dòng)填充的顏色配置,我修改的顏色值為:#586e75
撬码,示例:
注:上面聲明語(yǔ)法高亮儿倒,如果配置不生效的話,在plugins配置呜笑,再增加
zsh-syntax-highlighting
插件試試夫否。
8. iTerm2 隱藏用戶名和主機(jī)名
有時(shí)候我們的用戶名和主機(jī)名太長(zhǎng),比如我的xishuai@xishuaideMacBook-Pro
叫胁,終端顯示的時(shí)候會(huì)很不好看凰慈,我們可以手動(dòng)去除。
編輯 vim ~/.zshrc
文件驼鹅,增加 DEFAULT_USER="xishuai"
配置微谓,可在文本最好追加
我們可以通過(guò)whoami
命令,查看當(dāng)前用戶
9. iTerm2 快速隱藏和顯示
這個(gè)功能也非常使用输钩,就是通過(guò)快捷鍵豺型,可以快速的隱藏和打開(kāi) iTerm2,
示例配置(Commond + .
):
iTerm2 快捷命令
快捷命令說(shuō)明:
命令 | 說(shuō)明 |
---|---|
command + t | 新建標(biāo)簽 |
command + w | 關(guān)閉標(biāo)簽 |
command + 數(shù)字 command + 左右方向鍵 | 切換標(biāo)簽 |
command + enter | 切換全屏 |
command + f | 查找 |
command + d | 垂直分屏 |
command + shift + d | 水平分屏 |
command + option + 方向鍵 command + [ 或 command + ] | 切換屏幕 |
command + ; | 查看歷史命令 |
command + shift + h | 查看剪貼板歷史 |
ctrl + u | 清除當(dāng)前行 |
ctrl + l | 清屏 |
ctrl + a | 到行首 |
ctrl + e | 到行尾 |
ctrl + f/b | 前進(jìn)后退 |
ctrl + p | 上一條命令 |
ctrl + r | 搜索命令歷史 |
oh-my-zsh插件
github插件使用地址:https://github.com/robbyrussell/oh-my-zsh/wiki/Plugins
通過(guò)編輯 ~/.zshrc
文件來(lái)啟用所需的插件
plugins=(rails git ruby)
參考資料:
https://www.cnblogs.com/xishuai/p/mac-iterm2.html
http://www.reibang.com/p/405956cdaca6