You can use exec
when running tmux. It will give full control to the job you are starting, once that process exits (be it tmux
, echo
or ls
) the shell will exit.
From man zshbuiltins
exec ... Replace the current shell with an external command rather than forking.
if [[ -z $TMUX && -n $SSH_TTY ]]; then
me=$(whoami)
if tmux has-session -t $me 2>/dev/null; then
exec tmux -2 attach-session -t $me
else
exec tmux -2 new-session -s $me
fi
fi
the other alternative is to place a shell-script that starts or joins tmux, and ask ssh
to run that instead of your shell.
`alias tmux-ssh="ssh user@target-host -t /home/foo/my-tmux-script`
(the script must obviously be located at your remote host)