Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to get iTerm2 to color each new tab with a different color (using Oh My Zsh on Mac)?

I like having different colored tabs in iTerm2 to quickly know what each tab refers to. I can, of course, set them manually each time I open them, or download a script that will allow me to do that from the terminal itself (see pic for an example -- I've manually changed each tab's color). I was wondering whether there was a way (built in to iTerm2 or through an Oh My Zsh script) to simply have iTerm2 use a new (possibly random) color for the tab automatically on opening the tab? I have googled and can't find anything except a way to have SSH have a different tab color. Thanks for any help!

enter image description here

like image 302
Cerulean Avatar asked Oct 14 '25 20:10

Cerulean


1 Answers

Add this to your .bashrc/.zshrc/.whateverrc file to get a random tab color every time you open a new tab in iTerm2:

function tabcolor {
  echo -n -e "\033]6;1;bg;red;brightness;$1\a"
  echo -n -e "\033]6;1;bg;green;brightness;$2\a"
  echo -n -e "\033]6;1;bg;blue;brightness;$3\a"
}

tabcolor $(jot -r 1 0 255) $(jot -r 1 0 255) $(jot -r 1 0 255)
like image 147
Varun Sukheja Avatar answered Oct 19 '25 13:10

Varun Sukheja