The session file is automatically deleted when tmux session is detached.
I imagine it must be helpful for users if the session file is kept in that case.
Because, in a common case, the user does not recognize the possibility that the session is better to be kept alive when opening the new windows.
How to reproduce
(1) Create session from outside of tmux session.
$ xpanes --ssh localhost
(2) Detach the session (ctrl+b and d by default)
(3) Session is alive but session file is deleted.
$ ps alx | grep tmux
1 1000 20005 1 20 0 27648 4032 poll_s Ss ? 0:00 tmux -S /home/ubuntu/.cache/xpanes/socket.19931 new-session -s xpanes-19931 -n tmp-19931 -d /usr/bin/xpanes '--ssh' '-c' 'ssh -o StrictHostKeyChecking=no {} ' '--' 'localhost'
$ ls /home/ubuntu/.cache/xpanes/socket.19931
ls: cannot access '/home/ubuntu/.cache/xpanes/socket.19931': No such file or directory
The temporal session file ~/.cache/xpanes/socket.<PID> is supposed to be used to recover the session.
So, the file may be kept in case of network disconnection or any other troubles.
On the other hand, the file is going to be deleted if the tmux session is explicitly exited because any recovery won't be required.
However, tmux also makes its own process exit when detaching (ctrl+b d).
As far as investigated, there is no way for xpanes to confirm whether the session is "explicitly exited" or "detached". This is the reason why xpanes deletes the session file.
Reported in https://github.com/greymd/tmux-xpanes/issues/114#issuecomment-561247362
The session file is automatically deleted when tmux session is detached. I imagine it must be helpful for users if the session file is kept in that case. Because, in a common case, the user does not recognize the possibility that the session is better to be kept alive when opening the new windows.
How to reproduce
(1) Create session from outside of tmux session.
(2) Detach the session (
ctrl+b
andd
by default)(3) Session is alive but session file is deleted.
Technical reason
This is caused by this
trap
. https://github.com/greymd/tmux-xpanes/blob/dda18b9283d49d757eb525161fe866fc61ef6e94/bin/xpanes#L11The temporal session file
~/.cache/xpanes/socket.<PID>
is supposed to be used to recover the session. So, the file may be kept in case of network disconnection or any other troubles. On the other hand, the file is going to be deleted if the tmux session is explicitly exited because any recovery won't be required.However, tmux also makes its own process exit when detaching (ctrl+b d). As far as investigated, there is no way for
xpanes
to confirm whether the session is "explicitly exited" or "detached". This is the reason whyxpanes
deletes the session file.