Based upon my days and days of researching this, I may be seeking the impossible.
Situation
I have my
.bashrc
nicely configured to either spawn a newtmux
on connect, or if one exists, attach to it.I always hit Ctrl+D to exit a shell session. It's burned into my muscle memory. Unlearning it after thirty years of systems administration is also asking the impossible.
I want to be able to detach from
tmux
using just Ctrl+D, rather than having it kill my shell.
My imperfect approach
I can bind Ctrl+D to detach
in .tmux.conf
.
The problem is that I also have emacs
key-bindings burned into my muscle memory, so when I start editing a command line, I'll hit Ctrl+D to employ the GNU readline 'delete char under cursor'. Instead, the tmux
binding swallows the Ctrl+D, so I'm immediately detached. Same thing if I'm editing in emacs
.
Another flawed approach
GNU readline will take the EOF on an empty line, and then exit the shell. So I've tried trapping exit in .bashrc
instead:
trap "~/tmuxexit" EXIT
with the contents of tmuxexit
being:
tmux detach-client -s main
Which initially seemed like it worked, as hitting Ctrl+D on an empty line would report:
[detached (from session main)]
But tmux ls
reports no server running on […]
.