alias sshProdBox1=’ssh2 shiva@productionBox1.anywhere.com’
Script uses bash shell and AppleScript (http://en.wikipedia.org/wiki/AppleScript and https://developer.apple.com/library/mac/documentation/AppleScript/Conceptual/AppleScriptX/AppleScriptX.html and http://en.wikibooks.org/wiki/AppleScript_Programming ) on Mac.
On connecting to remote box background color is appropriately set – red for production, light blue for QA, gray for Dev, etc. and on disconnecting terminal is reverted back to white fonts with black background.
# Local window font is white on black background. On exiting from any ssh reset the terminal window to this config (white fonts on black screen).
HOSTNAME=`echo $@ | sed s/.*@//`
# echo $HOSTNAME, $@
if [ ${HOSTNAME} ]; then
echo “ssh to $HOSTNAME”
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 from connecting revert back to local setting – white fonts on black background
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 dev with white fonts on dark gray)
set_bg_color “{15000, 15000, 15000, 50000}”
;;