brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: set -g detach-on-destroy off moves you to another session when one ends

Tmux
~/tips/tip-tmux-detach-on-destroy

set -g detach-on-destroy off

Switches a tmux client to another session when its session closes, instead of detaching.

When the last window of a session closes, tmux detaches me and I land back in the plain shell, even with other sessions still running. I would rather be moved to one of them.

That is the default behaviour of detach-on-destroy. Switch it in ~/.tmux.conf:

set -g detach-on-destroy off

The manual says: if on (the default), the client is detached when the session it is attached to is destroyed. If off, the client is switched to the most recently active of the remaining sessions. The other values are no-detached, which detaches only if there are no detached sessions and otherwise switches to the most recently active one, and previous or next, which switch to the previous or next session in alphabetical order.

This fits a setup with one session per project. With three sessions called api, blog and notes, closing blog sends you straight to whichever of the other two you used last. To end a session from inside it:

tmux kill-session

The same command run with -t blog from another terminal ends that session instead.

The caveat: with off you only leave tmux when the last session is gone, so a stray exit in the final window of a session no longer drops you to the shell. Detach with Ctrl-b d when that is what you want.

Further reading: tmux manual (detach-on-destroy)

More Tmux tips tmux new -d -s report -x 200 -y 50 'top' tmux wait-for build-done set -g allow-passthrough on tmux kill-server Ctrl-b [ All Tmux tips (125) All topics

Link