Skip to content

Instantly share code, notes, and snippets.

@romanki
Last active September 3, 2023 23:51
Show Gist options
  • Save romanki/c2b267541d6fbf9c09bdf9a44dd5c6d6 to your computer and use it in GitHub Desktop.
Save romanki/c2b267541d6fbf9c09bdf9a44dd5c6d6 to your computer and use it in GitHub Desktop.
iTerm2 automatic colors depending of environment.
# Usage:
# Script is prepared for zsh,
# put it to ~/.oh-my-zsh/custom/colors.zsh
function reset_tab() {
echo -e "\033]50;SetProfile=Default\a"
trap - INT EXIT
}
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"
;;
blue)
echo -e "\033]6;1;bg;red;brightness;66\a"
echo -e "\033]6;1;bg;green;brightness;134\a"
echo -e "\033]6;1;bg;blue;brightness;244\a"
;;
grey)
echo -e "\033]6;1;bg;red;brightness;89\a"
echo -e "\033]6;1;bg;green;brightness;96\a"
echo -e "\033]6;1;bg;blue;brightness;99\a"
;;
esac
}
function colorssh() {
if [[ -n "$ITERM_SESSION_ID" ]]; then
trap "reset_tab" INT EXIT
if [[ "$*" =~ "aws" ]]; then
printf "\e]1337;SetBadgeFormat=%s\a" $(echo -n "\(session.name)" | base64)
printf "\e]1337;SetColors=bg=281f10\a"
color orange
elif [[ "$*" =~ "prod" ]]; then
printf "\e]1337;SetBadgeFormat=%s\a" $(echo -n "\(session.name)" | base64)
printf "\e]1337;SetColors=bg=300000\a"
color red
elif [[ "$*" =~ "gcp" ]]; then
printf "\e]1337;SetBadgeFormat=%s\a" $(echo -n "\(session.name)" | base64)
printf "\e]1337;SetColors=bg=0f212a\a"
color blue
elif [[ "$*" =~ "openshift" ]]; then
printf "\e]1337;SetBadgeFormat=%s\a" $(echo -n "\(session.name)" | base64)
printf "\e]1337;SetColors=bg=222b2b\a"
color grey
fi
fi
ssh $*
}
compdef _ssh tabc=ssh
alias ssh="colorssh"
##### BG colors #####
# grey 222b2b
# blue 0f212a
# dark-yellow 281f10
# yellow 45331f
# red 300000
# badge color 941f1f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment