安裝完成后,在/bin目錄下會多出一個zsh的文件。
Mac系統默認使用dash作為終端,可以使用命令修改默認使用zsh:
chsh -s /bin/zsh
zsh完美代替bash,具體區別可查看:《Zsh和Bash區別》
iterm2的原始界面
2. 替換背景圖片
打開路徑:iterm2 -> Preferences -> Profiles -> window -> Background Image
選擇一張自己喜歡的壁紙即可
可以通過Blending調節壁紙的透明度: 透明度為0的時候,背景變為純色(黑色)
我個人比較喜歡扁平化的壁紙,喜歡的朋友可以來這里看看:
《有哪些優雅的 Windows 10 壁紙?》
3. 安裝Oh my zsh
zsh的功能極其強大,只是配置過於復雜,通過Oh my zsh
可以很快配置zsh。
這里只做簡單的配置,如需要深入了解,可以查看:《oh-my-zsh,讓你的終端從未這么爽過》
安裝方法有兩種,可以使用curl或wget,看自己環境或喜好:
# curl 安裝方式
sh -c "$(curl -fsSL https://raw.githubusercontent.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 -)"
oh-my-zsh開源地址:《oh-my-zsh》
4. 安裝PowerLine
首先先安裝pip命令:
sudo easy_install pip
pip是python的一個維護命令
安裝powerline:
pip install powerline-status --user
5. 安裝PowerFonts
在常用的位置新建一個文件夾,如:~/Desktop/OpenSource/
在OpenSource文件夾下下載PorweFonts:
# git clone
git clone https://github.com/powerline/fonts.git --depth=1
# cd to folder
cd fonts
# run install shell
./install.sh
執行結果如下:
安裝好字體庫之后,我們來設置iTerm2的字體,具體的操作是:
iTerm2 -> Preferences -> Profiles -> Text
在Font區域選中Change Font,然后找到Meslo LG字體。
6. 安裝配色方案(可跳過)
在OpenSource目錄下執行git clone
命令:
git clone https://github.com/altercation/solarized
cd solarized/iterm2-colors-solarized/
open .
在打開的finder窗口中,雙擊Solarized Dark.itermcolors和Solarized Light.itermcolors即可安裝明暗兩種配色:
再次進入iTerm2 -> Preferences -> Profiles -> Colors -> Color Presets中根據個人喜好選擇.
7. 安裝主題
在OpenSource目錄下執行git clone
命令:
git clone https://github.com/fcamblor/oh-my-zsh-agnoster-fcamblor.git
cd oh-my-zsh-agnoster-fcamblor/
./install
執行上面的命令會將主題拷貝到oh my zsh的themes.
執行命令打開zshrc配置文件,將ZSH_THEME后面的字段改為agnoster
vi ~/.zshrc
我這里簡單說一下vim的一些操作命令,不熟悉的可以看看:
鍵盤i: 進入可編輯模式,最下面顯示-- INSERT --
鍵盤esc: 退出編輯模式
shift + : : 執行命令操作
輸入wq: 保存當前更改。如果僅僅退出不保存,可以輸入q
此時command+Q或source配置文件后,iTerm2變了模樣:
https://raw.githubusercontent.com/sirius1024/pubimgs/master/blogs/iterm2/12.png
8. 安裝高亮插件
這是oh my zsh的一個插件,安裝方式與theme大同小異:
cd ~/.oh-my-zsh/custom/plugins/
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git
vi ~/.zshrc
這時我們再次打開zshrc文件進行編輯。找到plugins,此時plugins中應該已經有了git,我們需要把高亮插件也加上:
https://raw.githubusercontent.com/sirius1024/pubimgs/master/blogs/iterm2/13.png
請務必保證插件順序,zsh-syntax-highlighting必須在最后一個。
然后在文件的最后一行添加:
source ~/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
按一下esc調出vi命令,輸入:wq保存並退出vi模式。
執行命令使剛才的修改生效:
source ~/.zshrc
所有配置至此結束。下面提供另外的功能
9. 可選擇、命令補全
跟代碼高亮的安裝方式一樣,這也是一個zsh的插件,叫做zsh-autosuggestion,用於命令建議和補全。
cd ~/.oh-my-zsh/custom/plugins/
git clone https://github.com/zsh-users/zsh-autosuggestions
vi ~/.zshrc
找到plugins,加上這個插件即可:
https://raw.githubusercontent.com/sirius1024/pubimgs/master/blogs/iterm2/15.png
插件效果:
https://raw.githubusercontent.com/sirius1024/pubimgs/master/blogs/iterm2/16.png
有同學說補全命令的字體不太清晰,與背景顏色太過相近,其實可以自己調整一下字體顏色。
Preferences -> Profiles -> Colors
中有Foreground是標准字體顏色,ANSI Colors中Bright的第一個是補全的字體顏色。