tmux-resurrect icon indicating copy to clipboard operation
tmux-resurrect copied to clipboard

resurrect-processes does not play well with `tmux split-window <cmd>`

Open jyn514 opened this issue 1 year ago • 3 comments

reproduction steps:

  1. open a new session of tmux
  2. run tmux split-window vim
  3. save the session (e.g.<prefix> C-s)
  4. exit the session with tmux kill-server
  5. enter a new session
  6. restore the session (e.g. <prefix> C-r)

the pane containing the command is correctly restored, but the process running inside it is not. this is especially confusing when resurrect-capture-pane-contents is enabled, as it looks like the process is running, but it's not. image

jyn514 avatar Aug 13 '24 22:08 jyn514

here is the contents of the state file:

; cat /home/jyn/.local/share/tmux/resurrect/tmux_resurrect_20240813T184703.txt
pane    3       0       1       :*      0       pop-os  :/home/jyn/src/tmux     0       zsh     :
pane    3       0       1       :*      1       pop-os  :/home/jyn/src/tmux     1       vi      :
window  3       0       :tmux (vi)      1       :*      b187,174x42,0,0[174x21,0,0,4,174x20,0,22,5]     :
state   3

it looks like pane_full_command isn't being saved properly, even though pane_command is correct?

jyn514 avatar Aug 13 '24 22:08 jyn514

it turns out the ps.sh save strategy doesn't work, because ps -a ignores processes without an associated terminal. if i replace full_command with this script:

ps  --ppid ${PANE_PID} -o args | tail -n +2

then everything works fine. i'll make a PR with that change.

jyn514 avatar Aug 13 '24 23:08 jyn514

hmm. no, it's a little more complicated than that. my fix there only works if you pass the script the PID of the tmux server. but when restoring, resurrect needs to know the PID running in that pane, it can't indiscriminately spawn every process at once. the way it normally does that is to take the output of tmux list-panes -F "#{pane_pid}" and look for all the children of that process with a controlling terminal, because that process is normally a shell. but in this case it's not a shell, it's a regular editor, so it has no children.

i am not quite sure what the correct fix is. maybe if there are no children with a controlling terminal, we can fall back to the parent process?

jyn514 avatar Aug 13 '24 23:08 jyn514