SSH colour

Override the ssh command so the terminal background colour changes with the host you connect to.

Install

Place ssh in ~/.bin/. Make it executable. Prepend ~/.bin/ to PATH.

chmod +x ssh

Wrapper

#!/bin/sh


HOSTNAME=`echo $@ | sed s/.*@//`


set_bg () {
  osascript -e "tell application \"Terminal\" to set background color of window 1 to $1"
}


on_exit () {
  set_bg "{25000, 0, 0, 50000}"
}
trap on_exit EXIT


case $HOSTNAME in
  prod.<domain>.com) set_bg "{45000, 0, 0, 50000}" ;;
  stage.<domain>.com) set_bg "{25000, 0, 0, 50000}" ;;
  dev.<domain>.com) set_bg "{15000, 0, 0, 50000}" ;;
*) set_bg "{0, 45000, 0, 50000}" ;;
esac


/usr/bin/ssh "$@"
Updated: 2026 Aug 19