mac下iterm配色、半透明與樣式設置
主要為了實現命令行顏色高亮與整個命令窗口半透明效果。
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
- 1
這時候如果有權限問題,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
sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
修改zsh配置文件
vi ~/.zshrc
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的顯示與隱藏。
最終效果: