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!

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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With