tmux-resurrect
tmux-resurrect copied to clipboard
Command capture bug in linux_procfs save strategy
For example, run:
vim --cmd "set pythonthreehome=/usr/bin/python3" /tmp/a
Then check ps:
ps -auwwx | grep vim
deguzim 52230 0.3 0.0 164936 12452 pts/0 S+ 17:47 0:00 vim --cmd set pythonthreehome=/usr/bin/python3 /tmp/a
They ideally need to use /proc/<PID>/cmdline:
$ for i in /proc/5348*/
do
basename "$i"
< $i/cmdline xargs -0 zsh -c 'printf "\t%q" "$0" "$@"'
printf '\n'
done
Or just one PID:
cat /proc/53482/cmdline | xargs -0 zsh -c 'printf "\t%q" "$0" "$@"'
Output:
53482
vim --cmd set\ pythonthreehome=/apollo/env/envImprovement/python3.8 /tmp/a
This is a valid command:
vim --cmd set\ pythonthreehome=/apollo/env/envImprovement/python3.8 /tmp/a
man printf
%q ARGUMENT is printed in a format that can be reused as shell input, escaping non-print‐ able characters with the proposed POSIX $'' syntax.
Try using linux_procfs strategy for saving commands:
set @resurrect-save-command-strategy "linux_procfs"
All the available strategies are in save_command_strategies/ dir in the repo.
I just realized we don't have any docs for this... if you have some time to briefly explain the steps you did to try this, a PR would be welcome.
I saved again and see now it's the command without args
pane work 1 :project-tests 0 :- 0 :/workplace/deguzim/project/src/project 1 vim :
pane work 1 :project-tests 0 :- 1 :/workplace/deguzim/project/src/project 0 zsh :
With that "linux_procfs" outputs, isn't quite right it seems. Can you test what I have below? Would you accept a PR?
upsteam:
$ cat /proc/40353/cmdline | xargs -0 printf "%q "
printf: %q: invalid conversion specification
$ cat /proc/40353/cmdline
vim--cmdset pythonthreehome=/apollo/env/envImprovement/python3.8/home/deguzim/.tmux.conf%
Proposed:
$ cat /proc/40353/cmdline | xargs -0 bash -c 'printf "%q " "$0" "$@"'
vim --cmd set\ pythonthreehome=/apollo/env/envImprovement/python3.8 /home/deguzim/.tmux.conf
This 100% did the trick for me locally:
14 full_command() {
15 [[ -z "$COMMAND_PID" ]] && exit 0
~ 16 #cat /proc/${COMMAND_PID}/cmdline | xargs -0 printf "%q "
+ 17 cat /proc/${COMMAND_PID}/cmdline | xargs -0 bash -c 'printf "%q " "$0" "$@"'
18 }
%q: escape/substitution
$0: command basename (e.g. vim)
$@: the rest of the full command
The original command doesn't save the full args.
When I did a restore after tmux kill-server && rm -rf /tmp/tmux-*, it worked perfect.
Note that this will not work:
cat /proc/${COMMAND_PID}/cmdline | xargs -0 printf "%q " "$0" "$@"
Some reasoning for this subshell usage can be found here: https://unix.stackexchange.com/a/567021
Hi,
I'm not on Linux so I can't test this easily.
Yes, a PR for this is welcome.
Just please document why bash -c with those printf interpolations is used. A link to that stackexchange topic in the comments should suffice.
submitted https://github.com/tmux-plugins/tmux-resurrect/pull/450
We just merged #450, so I think this one can be closed.