Reputation: 6013
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!
Upvotes: 4
Views: 1951
Reputation: 6526
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)
Upvotes: 4
Reputation: 374
to support random color automaticly when using color
without argument
add the following lines to ~/.profile
or ~/.zshrc
:
PRELINE="\r\033[A"
function random {
echo -e "\033]6;1;bg;red;brightness;$((1 + $RANDOM % 255))\a"$PRELINE
echo -e "\033]6;1;bg;green;brightness;$((1 + $RANDOM % 255))\a"$PRELINE
echo -e "\033]6;1;bg;blue;brightness;$((1 + $RANDOM % 255))\a"$PRELINE
}
function color {
case $1 in
green)
echo -e "\033]6;1;bg;red;brightness;57\a"$PRELINE
echo -e "\033]6;1;bg;green;brightness;197\a"$PRELINE
echo -e "\033]6;1;bg;blue;brightness;77\a"$PRELINE
;;
red)
echo -e "\033]6;1;bg;red;brightness;270\a"$PRELINE
echo -e "\033]6;1;bg;green;brightness;60\a"$PRELINE
echo -e "\033]6;1;bg;blue;brightness;83\a"$PRELINE
;;
orange)
echo -e "\033]6;1;bg;red;brightness;227\a"$PRELINE
echo -e "\033]6;1;bg;green;brightness;143\a"$PRELINE
echo -e "\033]6;1;bg;blue;brightness;10\a"$PRELINE
;;
*)
random
esac
}
#color #uncomment to enable automatically set random color when tab created
After each time a new iterm2 tab created, use command color
to automaticly give it a new/random color.
if you want the iterm2-tab color set automatically whenever it is created, then .just add color
to then end of .zshrc
/ .profile
or just after the function color
Upvotes: 4