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"
This commit is contained in:
Bruno Sutic 2020-06-14 11:33:31 +02:00
parent bd671b83dc
commit e4e21f3f48
No known key found for this signature in database
GPG Key ID: CAFA7B1B2914ED81
3 changed files with 29 additions and 1 deletions

View File

@ -28,6 +28,7 @@
- `view` added to the list of automatically restored programs - `view` added to the list of automatically restored programs
- Enable vim session strategy to work with custom session files, - Enable vim session strategy to work with custom session files,
e.g. `vim -S Session1.vim`. e.g. `vim -S Session1.vim`.
- Enable restoring command arguments for inline strategies with `*` character.
### v2.4.0, 2015-02-23 ### v2.4.0, 2015-02-23
- add "tmux-test" - add "tmux-test"

View File

@ -112,6 +112,32 @@ _get_proc_restore_element() {
echo "$1" | sed "s/.*${inline_strategy_token}//" echo "$1" | sed "s/.*${inline_strategy_token}//"
} }
# given full command: 'ruby /Users/john/bin/my_program arg1 arg2'
# and inline strategy: '~bin/my_program->my_program *'
# returns: 'arg1 arg2'
_get_command_arguments() {
local pane_full_command="$1"
local match="$2"
if _proc_starts_with_tildae "$match"; then
match="$(remove_first_char "$match")"
fi
echo "$pane_full_command" | sed "s,^.*${match}[^ ]* ,,"
}
_get_proc_restore_command() {
local pane_full_command="$1"
local proc="$2"
local match="$3"
local restore_element="$(_get_proc_restore_element "$proc")"
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}/"
else
echo "$restore_element"
fi
}
_restore_list() { _restore_list() {
local user_processes="$(get_tmux_option "$restore_processes_option" "$restore_processes")" local user_processes="$(get_tmux_option "$restore_processes_option" "$restore_processes")"
local default_processes="$(get_tmux_option "$default_proc_list_option" "$default_proc_list")" local default_processes="$(get_tmux_option "$default_proc_list_option" "$default_proc_list")"
@ -137,7 +163,7 @@ _get_inline_strategy() {
if [[ "$proc" =~ "$inline_strategy_token" ]]; then if [[ "$proc" =~ "$inline_strategy_token" ]]; then
match="$(_get_proc_match_element "$proc")" match="$(_get_proc_match_element "$proc")"
if _proc_matches_full_command "$pane_full_command" "$match"; then if _proc_matches_full_command "$pane_full_command" "$match"; then
echo "$(_get_proc_restore_element "$proc")" echo "$(_get_proc_restore_command "$pane_full_command" "$proc" "$match")"
fi fi
fi fi
done done

View File

@ -25,6 +25,7 @@ restore_processes=""
restore_process_strategy_option="@resurrect-strategy-" restore_process_strategy_option="@resurrect-strategy-"
inline_strategy_token="->" inline_strategy_token="->"
inline_strategy_arguments_token="*"
save_command_strategy_option="@resurrect-save-command-strategy" save_command_strategy_option="@resurrect-save-command-strategy"
default_save_command_strategy="ps" default_save_command_strategy="ps"