Programmatically set the color of a tab in iTerm2?
Solution 1
That's possible and you should read iterm escape codes for details.
^[]6;1;bg;red;brightness;N^G
I tried to setup the color of the terminal when I do ssh
(.ssh/config) and it worked but surprise, when I close the ssh session, it will not call the script again, in order to restore the title/color.
Added a feature request to auto-colored tabs - do not forget to star it, or add your comments (patches are also welcome!)
Solution 2
I added this function to my ~/.profile file:
function color {
case $1 in
green)
echo -e "\033]6;1;bg;red;brightness;57\a"
echo -e "\033]6;1;bg;green;brightness;197\a"
echo -e "\033]6;1;bg;blue;brightness;77\a"
;;
red)
echo -e "\033]6;1;bg;red;brightness;270\a"
echo -e "\033]6;1;bg;green;brightness;60\a"
echo -e "\033]6;1;bg;blue;brightness;83\a"
;;
orange)
echo -e "\033]6;1;bg;red;brightness;227\a"
echo -e "\033]6;1;bg;green;brightness;143\a"
echo -e "\033]6;1;bg;blue;brightness;10\a"
;;
esac
}
After adding this function you have to open a new terminal session. Now you can enter:
$ color green
or
$ color orange
to change the Tab color.
I use Photoshop to compose colors:
This color picker values can be converted to the following commands (Just insert the R -> red, G -> green, B -> blue values into the right line after "brightness;" to get a different color):
echo -e "\033]6;1;bg;red;brightness;57\a"
echo -e "\033]6;1;bg;green;brightness;197\a"
echo -e "\033]6;1;bg;blue;brightness;77\a"
Solution 3
To reset the tab color after exiting the ssh session use:
function ssh {
command ssh $@
echo -e "\033]6;1;bg;red;brightness;176\a"
echo -e "\033]6;1;bg;green;brightness;181\a"
echo -e "\033]6;1;bg;blue;brightness;175\a"
}
Related videos on Youtube
John Kramlich
Updated on September 18, 2022Comments
-
John Kramlich almost 2 years
My daily workflow includes me
- Launching iTerm2
- Creating 3 tabs
- Setting one tab each to red, orange and yellow
- Changing to a specific path in each tab
I would like to script this process; shell, applescript, etc. However, I cannot seem to find a hook that allows me to change the tab color. Is this possible? Here is a screen shot with an example of what I am trying to achieve.
-
peth over 12 yearsDoesn't Set window title and tab chrome background color help?
-
Aaron about 11 yearsI write an ssh wrapper script in my ~/bin which makes the tab color changes (and other things like custom background with server names) and uses an EXIT trap to change them back.
-
lfender6445 over 9 yearsAaron, would you mind sharing your script?
-
davidhq over 9 yearsYou can also do that:
function ssh { command ssh $@; # RESET BACK -> don't know how yet! help needed here }
-
davidhq over 9 yearsSomehow I found out... I pasted it as another answer
-
alper over 2 yearsWhat should we do to change active tab's color?
-
Sridhar Sarnobat over 2 yearsWow this is useful (but not intuitive).