Change tmux colors when running ssh

Menu

This post on Stackoverflow describes a function which changes tmux colors when connecting to another machine with ssh…. Extremely useful!

Here is my adaptation, where shairN is an alias for the remote machine I want to connect to:

function ssh_tmux_color () {
    if [ -n "$TMUX" ]; then
        case "$1" in
            shair0)
                tmux selectp -P 'fg=color117,bg=color237'
                ;;
            shair1)
                tmux selectp -P 'fg=color208,bg=color237'
                ;;
            shair2)
                tmux selectp -P 'fg=color11,bg=color237'
                ;;
        esac
    fi
    ssh "$@"
    tmux selectp -P default
}
alias ssh=ssh_tmux_color