效果:
比如zshrc
加入然后重启iterm2
if [[ -n "$ITERM_SESSION_ID" ]]; then
tab-color() {
echo -ne "\033]6;1;bg;red;brightness;$1\a"
echo -ne "\033]6;1;bg;green;brightness;$2\a"
echo -ne "\033]6;1;bg;blue;brightness;$3\a"
}
tab-red() { tab-color 255 0 0 }
tab-green() { tab-color 0 255 0 }
tab-blue() { tab-color 0 0 255 }
tab-reset() { echo -ne "\033]6;1;bg;*;default\a" }
function iterm2_tab_precmd() {
tab-reset
}
function iterm2_tab_preexec() {
if [[ "$1" =~ "^ssh " ]]; then
if [[ "$1" =~ "prod" ]]; then
tab-color 255 160 160
else
if [[ "$1" =~ "staging" ]]; then
tab-color 255 204 153
else
fi
fi
else
if [[ "$1" =~ "auth" ]]; then
tab-color 255 178 102
else
if [[ "$1" =~ "cv" ]]; then
tab-color 204 255 229
else
tab-color 204 204 255
fi
fi
fi
}
autoload -U add-zsh-hook
# 注释了默认颜色
#add-zsh-hook precmd iterm2_tab_precmd
add-zsh-hook preexec iterm2_tab_preexec
fi
是根据标题文本匹配的颜色 自己可以改规则改颜色