Skip to content

Commit e4e21f3

Browse files
committed
Restore command args for inline strategies with '*'
Example inline strategy: "~/bin/my_program->my_program *" for full command: "ruby /Users/john/bin/my_program arg1 arg2" restores command: "my_program arg1 arg2"
1 parent bd671b8 commit e4e21f3

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
- `view` added to the list of automatically restored programs
2929
- Enable vim session strategy to work with custom session files,
3030
e.g. `vim -S Session1.vim`.
31+
- Enable restoring command arguments for inline strategies with `*` character.
3132

3233
### v2.4.0, 2015-02-23
3334
- add "tmux-test"

scripts/process_restore_helpers.sh

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,32 @@ _get_proc_restore_element() {
112112
echo "$1" | sed "s/.*${inline_strategy_token}//"
113113
}
114114

115+
# given full command: 'ruby /Users/john/bin/my_program arg1 arg2'
116+
# and inline strategy: '~bin/my_program->my_program *'
117+
# returns: 'arg1 arg2'
118+
_get_command_arguments() {
119+
local pane_full_command="$1"
120+
local match="$2"
121+
if _proc_starts_with_tildae "$match"; then
122+
match="$(remove_first_char "$match")"
123+
fi
124+
echo "$pane_full_command" | sed "s,^.*${match}[^ ]* ,,"
125+
}
126+
127+
_get_proc_restore_command() {
128+
local pane_full_command="$1"
129+
local proc="$2"
130+
local match="$3"
131+
local restore_element="$(_get_proc_restore_element "$proc")"
132+
if [[ "$restore_element" =~ " ${inline_strategy_arguments_token}" ]]; then
133+
# replaces "%" with command arguments
134+
local command_arguments="$(_get_command_arguments "$pane_full_command" "$match")"
135+
echo "$restore_element" | sed "s/${inline_strategy_arguments_token}/${command_arguments}/"
136+
else
137+
echo "$restore_element"
138+
fi
139+
}
140+
115141
_restore_list() {
116142
local user_processes="$(get_tmux_option "$restore_processes_option" "$restore_processes")"
117143
local default_processes="$(get_tmux_option "$default_proc_list_option" "$default_proc_list")"
@@ -137,7 +163,7 @@ _get_inline_strategy() {
137163
if [[ "$proc" =~ "$inline_strategy_token" ]]; then
138164
match="$(_get_proc_match_element "$proc")"
139165
if _proc_matches_full_command "$pane_full_command" "$match"; then
140-
echo "$(_get_proc_restore_element "$proc")"
166+
echo "$(_get_proc_restore_command "$pane_full_command" "$proc" "$match")"
141167
fi
142168
fi
143169
done

scripts/variables.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ restore_processes=""
2525
restore_process_strategy_option="@resurrect-strategy-"
2626

2727
inline_strategy_token="->"
28+
inline_strategy_arguments_token="*"
2829

2930
save_command_strategy_option="@resurrect-save-command-strategy"
3031
default_save_command_strategy="ps"

0 commit comments

Comments
 (0)