Skip to content

Instantly share code, notes, and snippets.

@ernix
Last active April 22, 2025 02:28
Show Gist options
  • Save ernix/755223 to your computer and use it in GitHub Desktop.
Save ernix/755223 to your computer and use it in GitHub Desktop.
Set OSX terminal window background color per SSH hosts.
#!/bin/sh
# Set TMUX terminal pane background color per SSH hosts
# alias ssh='path/to/vsh.sh'
_ssh_tmux_background () {
[ -z "$TMUX_PANE" ] && return 0
if [ -n "$1" ]; then
hostname=$(command ssh -G "$@" | awk '$1=="hostname" { print $2; }')
case "$hostname" in
*.example.com)
# blue
style='bg=colour52'
;;
*.example.net)
# red
style='bg=colour17'
;;
esac
else
style=default
fi
tmux set-option -p -t "$TMUX_PANE" window-style "$style"
tmux set-option -p -t "$TMUX_PANE" window-active-style "$style"
}
_ssh_tmux_background "$@" # Parse Host
trap '_ssh_tmux_background' 0 1 2 3 15
command ssh "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment