Tab Colors in iTerm2 v1.0

Version 1.0 of iTerm2 for OS X was recently released. They removed one of my favorite features: tab coloring. You used to be able to right click on a tab to change its color. For example, I changed the tab with my ssh connection to our production server would be red and the tab with the ssh connection to our test server would be green.

I looked into it, and there is a way to set the tab color from the command line itself. This turns out to be much more helpful because I can add the following lines to my bash profile:



alias ssh-dev="tab-green; ssh ksnyder@dev.example.com"
alias ssh-prod="tab-red; ssh ksnyder@example.com"

Now each time I want to ssh to the dev server, the tab changes to green before the ssh begins. Same for production with a red tab.

The full tab coloring script I created is below. I just threw it into ~/.bash_profile.


# iterm coloring
function tab-color() {
if [[ $# == 1 ]]
then
# convert hex to decimal
hex=$1
if [[ ${hex:0:1} == "#" ]]
then
# strip leading hash sign
hex=${hex:1:6}
fi
if [[ ${#hex} == 3 ]]
then
# handle 3-letter hex codes
hex="${hex:0:1}${hex:0:1}${hex:1:1}${hex:1:1}${hex:2:1}${hex:2:1}"
fi
r=$(printf "%d" 0x${hex:0:2})
g=$(printf "%d" 0x${hex:2:2})
b=$(printf "%d" 0x${hex:4:2})
else
r=$1
g=$2
b=$3
fi
echo -ne "\033]6;1;bg;red;brightness;$r\a"
echo -ne "\033]6;1;bg;green;brightness;$g\a"
echo -ne "\033]6;1;bg;blue;brightness;$b\a"
}
function tab-red() { tab-color 203 111 111; }
function tab-green() { tab-color 6cc276; }
function tab-yellow() { tab-color "#e8e9ac"; }
function tab-blue() { tab-color 6f8ccc; }
function tab-purple() { tab-color a789d4; }
function tab-orange() { tab-color fbbc79; }
function tab-white() { tab-color fff; }
function tab-gray() { tab-color c3c3c3c; }

Note that the tab-color function accepts colors in rgb, 6-character hex codes and 3-character hex codes.

Edit: It appears that this functionality was restored in April 2014. Thanks! 7/22/2014

2 thoughts on “Tab Colors in iTerm2 v1.0

Comments are closed.