Here is few lines you need to add to your .bashrc/.zshrc/.whatevershellrc:
if [[ -z "$TMUX" ]] && [ "$SSH_CONNECTION" != "" ]; then
tmux attach-session -t mysession || tmux new-session -s mysession
fi
These lines check if tmux session mysession
is exist then we tmux attach-session
is executed. Otherwise new session with mysession
name is created.
Replace mysession
to something more meaningful.