Skip to content

Instantly share code, notes, and snippets.

@mladenp
Created July 4, 2023 15:11
Show Gist options
  • Save mladenp/02527a2704a816e00b411ba122f1b0dc to your computer and use it in GitHub Desktop.
Save mladenp/02527a2704a816e00b411ba122f1b0dc to your computer and use it in GitHub Desktop.
Iterm set random tab color
precmd() {
# sets the tab title to current dir
echo -ne "\e]1;${PWD##*/}\a"
}
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment