Last active
March 10, 2024 00:32
-
-
Save wadey/1140259 to your computer and use it in GitHub Desktop.
Change iTerm2 tab color when using SSH
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Usage: | |
# source iterm2.zsh | |
# iTerm2 tab color commands | |
# https://iterm2.com/documentation-escape-codes.html | |
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 | |
tab-color 160 255 160 | |
fi | |
else | |
tab-color 160 160 255 | |
fi | |
} | |
autoload -U add-zsh-hook | |
add-zsh-hook precmd iterm2_tab_precmd | |
add-zsh-hook preexec iterm2_tab_preexec | |
fi |
How do I use this?
thanks for sharing this! nice job. If you put some comments to explain some lines, that would be great.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Its like tab bar's color is brighter of the given color and not same color as the title bar. When the color is set it is assigned on the both title bar and tab bar but tab bar always makes the color much bright
For example for:
tab-color 160 160 255