天天看點

MAC上iTerm 2安裝與使用

MAC上iTerm 2安裝與使用

logo2x.jpg

更新日志

  • 2018-05-20 Mac安裝powerline 權限問題

一、前言

iTerm2是MAC下最好用的終端工具,并且還是免費的。iTerm2 是配置完畢開箱即用的 tmux,有标簽變色、智能選中等特色功能。在日常開發中,我們難免會與終端指令打交道,比如使用Git,CocoaPods,Homebrew,Hexo等,下面開始介紹自定義終端樣式吧!

二、目錄

  • 下載下傳安裝iTerm 2
  • 安裝powerline
  • 安裝oh-my-zsh
  • 安裝字型庫fonts
  • 導入配色
  • 主題設定
  • 添加指令高亮效果zsh-syntax-highlighting
  • 快捷鍵
  • 問題解決

三、下載下傳安裝iTerm 2

  • GitHub

四、安裝powerline

//沒有安裝pip先安裝pip
sudo easy_install pip

//之後安裝powerline(這裡可能會報錯,可以參考問題解決)
pip install powerline-status           

複制

五、安裝oh-my-zsh

curl -L https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh | sh           

複制

六、安裝字型庫fonts

//克隆字型庫到本地
git clone https://github.com/powerline/fonts.git

//安裝字型
cd fonts
./install.sh           

複制

安裝成功之後輸出:

➜  fonts git:(master) ./install.sh
Copying fonts...
Powerline fonts installed to /Users/WENBO/Library/Fonts           

複制

七、導入配色

  • 首先到GitHub下載下傳solarized
git clone https://github.com/altercation/solarized           

複制

  • 解壓zip檔案,進入solarized/iterm2-colors-solarized

    檔案,輕按兩下Solarized Dark.itermcolors和Solarized Light.itermcolors進行安裝導入,如下圖所示

MAC上iTerm 2安裝與使用

install-solarized.png

  • 進入系統偏好設定,profiles->Colors選擇剛剛導入的配色方案即可
MAC上iTerm 2安裝與使用

螢幕快照 2018-02-12 下午4.07.41.png

八、主題設定

  • 使用agnoster,下載下傳安裝:
//克隆主題到本地
git clone  https://github.com/fcamblor/oh-my-zsh-agnoster-fcamblor

//安裝主題
cd oh-my-zsh-agnoster-fcamblor
./install           

複制

  • 安裝成功之後,編輯~/.zshrc檔案,将ZSH_THEME改為agnoster
# Set name of the theme to load. Optionally, if you set this to "random"
# it'll load a random theme each time that oh-my-zsh is loaded.
# See https://github.com/robbyrussell/oh-my-zsh/wiki/Themes
ZSH_THEME="agnoster"           

複制

九、添加指令高亮效果zsh-syntax-highlighting

  • 下載下傳檔案
//克隆項目到本地
git clone git://github.com/zsh-users/zsh-syntax-highlighting.git           

複制

  • 編輯.zshrc檔案,在最後添加如下内容
source /Users/WENBO/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
plugins=(zsh-syntax-highlighting)           

複制

注意

/Users/WENBO是*.zshrc檔案所在路徑,這裡替換成你自己的就好了           

複制

  • 設定成功之後,效果如下:
MAC上iTerm 2安裝與使用

螢幕快照 2018-02-12 下午4.55.25.png

十、快捷鍵

自己也才安裝,先記錄下來吧。

說明 快捷鍵
建立标簽 command + t
關閉标簽 command + w
切換标簽 command + 數字 command + 左右方向鍵
切換全屏 command + enter
查找 command +f
垂直分屏 command + d
水準分屏 command + shift + d
切換螢幕 command + option + 方向鍵 command + [ 或 command + ]
檢視曆史指令 command + ;
檢視剪貼闆曆史 command + shift + h
清除目前行 ctrl + u
到行首 ctrl + a
到行尾 ctrl + e
前進後退 ctrl + f/b (相當于左右方向鍵)
上一條指令 ctrl + p
搜尋指令曆史 ctrl + r
删除目前光标的字元 ctrl + d
删除光标之前的字元 ctrl + h
删除光标之前的單詞 ctrl + w
删除到文本末尾 ctrl + k
交換光标處文本 ctrl + t
清屏1 command + r
清屏2 ctrl + l

十一、問題解決

  • brew link python報錯
sudo mkdir /usr/local/Frameworks
sudo chown $(whoami):admin /usr/local/Frameworks           

複制

之後執行,連結成功

brew link python           

複制

  • 安裝powerline報錯Permission denied,原因是沒有安裝python,,通過homebrew安裝python
brew install python           

複制

  • 指令顯示?号,如下圖所示:
MAC上iTerm 2安裝與使用

螢幕快照 2018-02-12 下午4.38.27.png

解決辦法:進入Preference->Profiles->Text,做如下配置即可:

MAC上iTerm 2安裝與使用

螢幕快照 2018-02-12 下午4.59.18.png

  • Mac安裝powerline 權限問題,報錯如下
MAC上iTerm 2安裝與使用

螢幕快照 2018-05-20 下午3.57.18.png

解決辦法:

pip install powerline-status --user -U           

複制

十二、結語

在掘金上發現了這款終端工具,自己平時也有用到終端工具,于是就嘗試給自己的MAC裝上這款軟體,在安裝過程中還是遇到一些問題,不過最後都解決了。如果你也愛好終端指令操作,可以嘗試DIY你喜歡的終端樣式哦。

參考文章

  • iTerm 2 && Oh My Zsh【DIY教程——親身體驗過程】
  • Mac終端iTerm2配置