2

Every terminal window I open automatically attaches to a new tmux session. Closing the shell inside such a tmux session should detach the tmux client for the terminal window to close. This can be done by setting this option:

set -g detach-on-destroy on

However, when I kill the current session from the session overview (Ctrl+b,w,x,y), the tmux client also detaches. Instead, I would like it to stay attached so I can select another session from the session overview.

The question is, how can I have tmux detach when the session exits because the process it's running (i.e. the shell) exits but stay attached when the session is killed from the session overview?

1

You might be able to do this by having detach-on-destroy off but putting detach-client in the pane-exited hook.

  • Thanks, that sounds promising. Do you have an example how this might look like? – danijar May 15 at 3:44
  • This works for me, but you won't be able to use remain-on-exit normally at the same time: set -g remain-on-exit on set -g pane-died 'if -F "#{&&:#{==:#{session_windows},1},#{==:#{window_panes},1}}" "killp; detach" "killp"' set -g detach-on-destroy off – Nicholas Marriott May 15 at 14:46
1

Here it is a bit more readably:

set -g remain-on-exit on
set -g pane-died 'if -F "#{&&:#{==:#{session_windows},1},#{==:#{window_panes},1}}" "killp; detach" "killp"'
set -g detach-on-destroy off

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.