Skip to content

Commit

Permalink
Merge pull request #469 from ktprograms/restore-arguments-misc-fixes
Browse files Browse the repository at this point in the history
Restore with command arguments misc fixes
  • Loading branch information
bruno- authored Jan 31, 2023
2 parents a2ddfb9 + 299c4aa commit 6df0405
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
18 changes: 18 additions & 0 deletions docs/restoring_programs.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions scripts/process_restore_helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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
Expand Down

0 comments on commit 6df0405

Please sign in to comment.