From 45aa8feef656804b252ddb0d4b73ca944229e606 Mon Sep 17 00:00:00 2001 From: Thomas Faughnan Date: Tue, 20 Sep 2022 18:30:28 -0400 Subject: [PATCH 1/6] ps.sh: fix ps arguments to work for busybox Use the format specifier 'ppid,args' instead of 'ppid command'. POSIX allows either spaces or commas as separators, but busybox only allows commas. Furthermore, 'args' is recognized by POSIX[0] while 'command' is not. On implementations of ps that do recognize 'command', it is simply an alias for 'args', e.g. Debian[1] and FreeBSD[2]. [0]: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/ps.html [1]: https://manpages.debian.org/bullseye/procps/ps.1.en.html [2]: https://www.freebsd.org/cgi/man.cgi?query=ps --- save_command_strategies/ps.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/save_command_strategies/ps.sh b/save_command_strategies/ps.sh index 544426c..15bb5aa 100755 --- a/save_command_strategies/ps.sh +++ b/save_command_strategies/ps.sh @@ -11,7 +11,7 @@ exit_safely_if_empty_ppid() { } full_command() { - ps -ao "ppid command" | + ps -ao "ppid,args" | sed "s/^ *//" | grep "^${PANE_PID}" | cut -d' ' -f2- From dd36a4561b0bb41987cccc299c85475012d8cf8b Mon Sep 17 00:00:00 2001 From: Lu Xu Date: Sat, 22 Oct 2022 14:21:51 +0800 Subject: [PATCH 2/6] use XDG_DATA_HOME for resurrect-dir path --- scripts/helpers.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/helpers.sh b/scripts/helpers.sh index dd8d0ca..20d87dc 100644 --- a/scripts/helpers.sh +++ b/scripts/helpers.sh @@ -1,4 +1,8 @@ -default_resurrect_dir="$HOME/.tmux/resurrect" +if [ -d "$HOME/.tmux/resurrect" ]; then + default_resurrect_dir="$HOME/.tmux/resurrect" +else + default_resurrect_dir="${XDG_DATA_HOME:-$HOME/.local/share}"/tmux/resurrect +fi resurrect_dir_option="@resurrect-dir" SUPPORTED_VERSION="1.9" From 4941cdb07498fd095f0d1d029113de1ddd4fc67c Mon Sep 17 00:00:00 2001 From: kt programs Date: Mon, 30 Jan 2023 10:33:50 +0800 Subject: [PATCH 3/6] _get_command_arguments: make trailing space optional When pane_full_command has no arguments, the regex doesn't find argv[0] as there is no trailing space. For example, if pane_full_command was "vim" and the restore option was "~Vim->vim *", the command "vim vim" would get executed instead of just "vim". Make the trailing space optional to match having only the command without arguments. --- scripts/process_restore_helpers.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/process_restore_helpers.sh b/scripts/process_restore_helpers.sh index 49d3844..8bf5a78 100644 --- a/scripts/process_restore_helpers.sh +++ b/scripts/process_restore_helpers.sh @@ -121,7 +121,7 @@ _get_command_arguments() { if _proc_starts_with_tildae "$match"; then match="$(remove_first_char "$match")" fi - echo "$pane_full_command" | sed "s,^.*${match}[^ ]* ,," + echo "$pane_full_command" | sed "s,^.*${match}[^ ]* *,," } _get_proc_restore_command() { From b8ff2ea08be920e626ad4ba158746e564dfc71b4 Mon Sep 17 00:00:00 2001 From: kt programs Date: Mon, 30 Jan 2023 10:31:13 +0800 Subject: [PATCH 4/6] _get_proc_restore_command: use "," as sed delimiter When command_arguments contains a path, there are too many delimiters for sed, which causes it to not replace properly. The result of this is that the original command gets executed without remapping and/or expanding the arguments. --- scripts/process_restore_helpers.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/process_restore_helpers.sh b/scripts/process_restore_helpers.sh index 8bf5a78..546dfe1 100644 --- a/scripts/process_restore_helpers.sh +++ b/scripts/process_restore_helpers.sh @@ -132,7 +132,7 @@ _get_proc_restore_command() { if [[ "$restore_element" =~ " ${inline_strategy_arguments_token}" ]]; then # replaces "%" with command arguments local command_arguments="$(_get_command_arguments "$pane_full_command" "$match")" - echo "$restore_element" | sed "s/${inline_strategy_arguments_token}/${command_arguments}/" + echo "$restore_element" | sed "s,${inline_strategy_arguments_token},${command_arguments}," else echo "$restore_element" fi From 299c4aa8ce95ed26520e06f09120d6a319999ac6 Mon Sep 17 00:00:00 2001 From: kt programs Date: Mon, 30 Jan 2023 10:46:24 +0800 Subject: [PATCH 5/6] docs: add info on asterisk (*) restore option --- docs/restoring_programs.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/docs/restoring_programs.md b/docs/restoring_programs.md index c142fe5..6d316d6 100644 --- a/docs/restoring_programs.md +++ b/docs/restoring_programs.md @@ -28,6 +28,10 @@ contains space-separated list of additional programs to restore. set -g @resurrect-processes 'some_program "grunt->grunt development"' +- Use `*` to expand the arguments from the saved command when restoring: + + set -g @resurrect-processes 'some_program "~rails server->rails server *"' + - Don't restore any programs: set -g @resurrect-processes 'false' @@ -96,6 +100,20 @@ command name". Full (long) process name is now ignored and you'll see just `rails server` in the command line when the program is restored. +> What is asterisk `*` and why is it used? + +(Please read the above clarifications about tilde `~` and arrow `->`). + +Continuing with the `rails server` example, you might have added flags for e.g. +verbose logging, but with the above configuration, the flags would be lost. + +To preserve the command arguments when restoring, use the asterisk `*`: (**note**: there **must** be a space before `*`) + + set -g @resurrect-processes '"~rails server->rails server *"' + +This option says: "when this process is restored use `rails server` as the +command name, but preserve its arguments". + > Now I understand the tilde and the arrow, but things still don't work for me Here's the general workflow for figuring this out: From 4c1c0dcf85691625c9e8f8040cf23701eebf5ee0 Mon Sep 17 00:00:00 2001 From: George Guimares Date: Sun, 5 Mar 2023 20:58:11 -0600 Subject: [PATCH 6/6] Updated description of default session location. - Include alternate location - Include reference to `${XDB_DATA_HOME}` env variable --- docs/restoring_previously_saved_environment.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/restoring_previously_saved_environment.md b/docs/restoring_previously_saved_environment.md index caee1d8..8e845ac 100644 --- a/docs/restoring_previously_saved_environment.md +++ b/docs/restoring_previously_saved_environment.md @@ -1,7 +1,8 @@ # Restoring previously saved environment None of the previous saves are deleted (unless you explicitly do that). All save -files are kept in `~/.tmux/resurrect/` directory.
+files are kept in `~/.tmux/resurrect/` directory, or `~/.local/share/tmux/resurrect` +(unless `${XDG_DATA_HOME}` says otherwise).
Here are the steps to restore to a previous point in time: - make sure you start this with a "fresh" tmux instance