For work I ssh into various servers and will do various analysis jobs from within tmux sessions. When I want to end the ssh connection, I have a bad habit of running exit
immediately, when what I should to is C-b d
to detach from the session and then run exit
to close the connection.
Running exit in tmux kills the session so I'd like check if I'm in a tmux session before running exit.
I know I can use a simple -n $TMUX
check to see if I'm in a tmux session and I've tried adding the following in my .bashrc:
alias exit='if -n $TMUX then echo "You are in a tmux session" else exit fi'
This doesn't work, I just get a hanging >
prompt and I'm not sure why. I'm pretty sure part of it is that I'm running the exit command within the alias definition, so that's probably not a great circular logic there.
Any thoughts on how to accomplish this would be appreciated.