Skip to content

Instantly share code, notes, and snippets.

@XReyRobert
Created January 4, 2026 17:12
Show Gist options
  • Select an option

  • Save XReyRobert/1551268eb38dc87e03e2d92099157a4c to your computer and use it in GitHub Desktop.

Select an option

Save XReyRobert/1551268eb38dc87e03e2d92099157a4c to your computer and use it in GitHub Desktop.
Set a new iterm2 tab color for each session
echo '
# Set iTerm2 tab/title “chrome” color (RGB values 0–255)
iterm_tabcolor() {
local colors=(
"255 0 0" # Red
"0 255 0" # Green
"0 0 255" # Blue
"255 255 0" # Yellow
"0 255 255" # Cyan
"255 0 255" # Magenta
"192 192 192" # Silver
"128 128 128" # Gray
"128 0 0" # Maroon
"128 128 0" # Olive
"0 128 0" # Dark Green
"128 0 128" # Purple
"0 128 128" # Teal
"0 0 128" # Navy
)
local color=(${(s: :)colors[$RANDOM % ${#colors[@]} + 1]})
printf '\''\033]6;1;bg;red;brightness;%d\a'\'' $color[1]
printf '\''\033]6;1;bg;green;brightness;%d\a'\'' $color[2]
printf '\''\033]6;1;bg;blue;brightness;%d\a'\'' $color[3]
}
# Reset to default
iterm_tabcolor_reset() {
printf '\''\033]6;1;bg;*;default\a'\''
}
# Set a random color for each new session
iterm_tabcolor
' >> ~/.zshrc && source ~/.zshrc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment