Skip to content

Instantly share code, notes, and snippets.

@romanki
Created June 13, 2019 09:56
Show Gist options
  • Save romanki/ae98160ec92f88a4acc4cc120d6dc2b2 to your computer and use it in GitHub Desktop.
Save romanki/ae98160ec92f88a4acc4cc120d6dc2b2 to your computer and use it in GitHub Desktop.
iTerm2 automatic color switching for different k8s contexts with kubectx
function reset_tab() {
echo -e "\033]50;SetProfile=Default\a"
}
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 contextcolor() {
if [[ -n "$ITERM_SESSION_ID" ]]; then
if [[ "$*" =~ "monitoring" ]]; then
printf "\e]1337;SetBadgeFormat=%s\a" $(echo -n "\(session.name)" | base64)
printf "\e]1337;SetColors=bg=281f10\a"
color orange
elif [[ "$*" =~ "features" ]]; then
printf "\e]1337;SetBadgeFormat=%s\a" $(echo -n "\(session.name)" | base64)
printf "\e]1337;SetColors=bg=0f212a\a"
color blue
elif [[ "$*" =~ "production" ]]; then
printf "\e]1337;SetBadgeFormat=%s\a" $(echo -n "\(session.name)" | base64)
printf "\e]1337;SetColors=bg=300000\a"
color red
fi
fi
kubectx $*
}
compdef _kubectx tabc=kubectx
alias kubectx="contextcolor"
##### 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