主要為了實作指令行顔色高亮與整個指令視窗半透明效果。
1、配色主題包下載下傳
-
1、http://iterm2colorschemes.com/
下載下傳後解壓,到iterm2中,左上角iTerm2->preferences->Profiles,右側面闆找到Colors選項,右下角展開Color Presets…,拉到最下面,選擇import,把下載下傳解壓好的配色主題包下的schemes下的所有.itermcolors檔案導入,導入完成後再展開Colors下拉清單,即可選擇不同的配色模闆。
-
2、隻下載下傳solarized配色模闆
item2裡好像自帶這個配色模闆,導入後叫Solarized Dark和Solarized Light。
http://ethanschoonover.com/solarized
找到download,下載下傳後解壓,按上面同樣方式導入iterm2-colors-solarized檔案夾下的.itermcolors檔案。
一般用Solarized Dark即可。
2、修改配置檔案
sudo vim /etc/profile
這時候如果有權限問題,sudo chmod 644 /etc/profile
在檔案中追加:
find_git_branch () {
local dir=. head
until [ "$dir" -ef / ]; do
if [ -f "$dir/.git/HEAD" ]; then
head=$(< "$dir/.git/HEAD")
if [[ $head = ref:\ refs/heads/* ]]; then
git_branch=" (${head#*/*/})"
elif [[ $head != '' ]]; then
git_branch=" → (detached)"
else
git_branch=" → (unknow)"
fi
return
fi
dir="../$dir"
done
git_branch=''
}
PROMPT_COMMAND="find_git_branch; $PROMPT_COMMAND"
black=$'\[\e[1;30m\]'
red=$'\[\e[1;31m\]'
green=$'\[\e[1;32m\]'
yellow=$'\[\e[1;33m\]'
blue=$'\[\e[1;34m\]'
magenta=$'\[\e[1;35m\]'
cyan=$'\[\e[1;36m\]'
white=$'\[\e[1;37m\]'
normal=$'\[\e[m\]'
PS1="$white[$white@$green\h$white:$cyan\W$yellow\$git_branch$white]\$ $normal"
配置立刻生效:
source /etc/profile
這時候顔色應該已經顯示了。
3、透明度
透明度,iterm2中,左上角iTerm2->preferences->Profiles,右側找到window頁籤,拖動Transparency調整.
4、安裝oh-my-zsh
- 安裝oh-my-zsh
修改zsh配置檔案
ZSH_THEME=”robbyrussell”修改為ZSH_THEME=”agnoster”
重新開機items
- 安裝字型
# clone 先克隆
git clone https://github.com/powerline/fonts.git
# install 後安裝
cd fonts
./install.sh
iterm2中,左上角iTerm2->preferences->Profiles,右側text頁籤Font和Non-ASCII Font都設定為
Meslo LG S DZ Regular for Powerline字型。
重新開機items
5、文法高亮插件
$ cd到.zshrc所在目錄
$ git clone git://github.com/zsh-users/zsh-syntax-highlighting.git
$ 打開 ~/.zshrc
# 添加下面的語句到.zshrc檔案末尾
source XXX/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
# 注意:xxx代表zsh-syntax-highlighting所在目錄
# 再次打開.zshrc檔案,在最後面添加下面内容
plugins=(zsh-syntax-highlighting)
# 啟用指令糾錯功能
ENABLE_CORRECTION="true"
6、其他設定
設定菜單欄出現位置與主題:iTerm2->preferences->Profiles->Appearance
設定iterm出現位置:iTerm2->preferences->Profiles->window
設定顯現和隐藏熱鍵(option+空格):iTerm2->preferences->Profiles->window
設定之後,通過option+空格就能切換iterm2的顯示與隐藏。
最終效果: