So when I open a new terminal (I use terminator on Arch Linux), I have it configured to either open a new tmux
session if one doesn't exist, or attach to an existing one. When I type exit
at the prompt, it quits the tmux session. I have to type exit
again to quit the terminal. What I want is that typing exit
once will quit the terminal, but leave tmux
running, so the next time I open the terminal it will reattach to the previous tmux
session. Essentially, this is the equivalent of clicking the exit button for the window manager, but I want this functionality when typing exit
.
EDIT:
This is something like what I want:
alias exit='if [[ $TMUX = "" ]]; then exit; else tmux detach; exit; fi'
but the issue is the exit
after the tmux detach
should get called in the terminal containing the tmux session, not the tmux session itself.
exit
is not atmux
command; it's a shell command.tmux
only exits if you terminate the command (usually, a shell) in the last pane of the last window. It sounds like you just want to detach from the current session, in which case you should use the appropriatetmux
command or key binding.exit
isn't a tmux command. I want to detach from the session and exit the terminal (not the session), but I want to use theexit
command in a tmux session to do that. I think it should be possible with some bash-fu.exit
to not exit a shell. Anyway, as long as you havetmux
be the actual command that the terminal runs (as opposed to startingtmux
as a child of a shell started by the terminal), detaching will cause the last program running in the shell to exit and, assuming your terminal is configured to do so, automatically close the window.