The setup gives you the freedom to launch long-running commands and before you say «Darn! I should have launched that with screen!» you realize that you are in a tmux session, then you can fire a new window and detach.
As simple as it may seem, this is a nice feature for reckless people as I am, and I adpoted it immediately. I was so happy with it that I decided I wanted it also on my laptop (just in case I need to ssh into it), but the script was not working with my favourite shell zsh.
set -- "$SSH_CONNECTION"
if [[ ! -z $PS1 ]]; then
if [[ ! -z $SSH_TTY ]]; then
if [[ -z $TMUX ]]; then
if [[ $1 != $3 ]]; then
if [[ ! -r ~/.notmux ]]; then
if ! tmux has-session -t remote; then
exec tmux new-session -s remote
exec tmux \
new-session -d -s remote_$$ -t remote \;\
set-option destroy-unattached on
alias detach='[[ ! -z $TMUX ]] && tmux has-session -t remote && tmux detach-client'
alias exitmux='[[ ! -z $TMUX ]] && tmux has-session -t remote && tmux detach-client \; kill-window'
alias usa='[[ ! -z $TMUX ]] && tmux has-session -t remote && eval $(tmux show-environment -t remote | grep ^SSH_AUTH_SOCK)'
Furthermore, you can put the script in a file, say
tmux.sh and source it from your
.bashrc (for bash shells) or
# Add tmux over ssh
(I have also found this very nice bash shell script checker)