Skip to content

Instantly share code, notes, and snippets.

@shivamy
Last active August 29, 2015 14:07
Show Gist options
  • Save shivamy/3c36e1dd58a7b7a0541e to your computer and use it in GitHub Desktop.
Save shivamy/3c36e1dd58a7b7a0541e to your computer and use it in GitHub Desktop.
Terminal background color change for remote ssh
#!/bin/bash
# Notes:
# Local window font is white on black background. On exiting from any ssh active terminal window resets to this config.
# Remote ssh terminal is chosen with type of server connected - Prod has reddish bg, dev vm has gray bg, etc.
HOSTNAME=`echo $@ | sed s/.*@//`
# echo $HOSTNAME, $@
if [ ${HOSTNAME} ]; then
echo "ssh to $HOSTNAME"
sleep 1
else
echo "Missing ssh host. Exiting."
exit 1
fi
set_bg_color () {
# color values are in '{R, G, B, A}' format, all 16-bit unsigned integers (0-65535)
osascript -e "tell application \"Terminal\" to set background color of window 1 to $1"
}
set_font_color () {
osascript -e "tell application \"Terminal\" " \
-e "tell selected tab of front window" \
-e "set normal text color to $1" \
-e "end tell" \
-e "end tell"
}
on_exit () {
set_bg_color "{0, 0, 0, 50000}" # Black bg
set_font_color "{65000, 65000, 65000, 50000}" # White font
}
trap on_exit EXIT
# Main
case $HOSTNAME in
# My VM with white fonts on dark gray
dev-vm.x.org)
set_bg_color "{15000, 15000, 15000, 50000}"
;;
# Prod "ER" systems
prod1-er.x.org)
set_bg_color "{40000, 8000, 8000, 50000}"
set_font_color "{0, 0, 0, 50000}"
;;
prod2-er.x.org)
set_bg_color "{40000, 8000, 8000, 50000}"
set_font_color "{0, 0, 0, 50000}"
;;
# Prod "EDW" systems
prod1-edw.x.org)
set_bg_color "{40000, 10000, 10000, 50000}"
set_font_color "{65000, 65000, 65000, 50000}"
;;
prod2-edw.x.org)
set_bg_color "{40000, 10000, 10000, 50000}"
set_font_color "{65000, 65000, 65000, 50000}"
;;
# QA black fonts on light blue
qa-er.x.org)
set_bg_color "{45000, 50000, 65000, 50000}"
set_font_color "{0, 0, 0, 50000}"
;;
qa-er.x.org)
set_bg_color "{45000, 50000, 65000, 50000}"
set_font_color "{0, 0, 0, 50000}"
;;
esac
# Now ssh to remote
/usr/bin/ssh "$@"
# Color combination examples:
# set_bg_color "{65535, 65535, 65535, 50000}" # White
# set_bg_color "{65535, 65535, 65535, 50000}" # White
# set_bg_color "{40000, 40000, 40000, 50000}" # Light Gray
# set_bg_color "{0, 0, 0, 50000}" # Black
# set_bg_color "{10000, 0, 0, -16373}" # WineRed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment