diff --git a/CHANGELOG.md b/CHANGELOG.md index 408ebda..58b00a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,7 @@ - `view` added to the list of automatically restored programs - Enable vim session strategy to work with custom session files, e.g. `vim -S Session1.vim`. +- Enable restoring command arguments for inline strategies with `*` character. ### v2.4.0, 2015-02-23 - add "tmux-test" diff --git a/scripts/process_restore_helpers.sh b/scripts/process_restore_helpers.sh index 0b88177..49d3844 100644 --- a/scripts/process_restore_helpers.sh +++ b/scripts/process_restore_helpers.sh @@ -112,6 +112,32 @@ _get_proc_restore_element() { 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() { local user_processes="$(get_tmux_option "$restore_processes_option" "$restore_processes")" 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 match="$(_get_proc_match_element "$proc")" 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 done diff --git a/scripts/variables.sh b/scripts/variables.sh index fb3d885..3f94372 100644 --- a/scripts/variables.sh +++ b/scripts/variables.sh @@ -25,6 +25,7 @@ restore_processes="" restore_process_strategy_option="@resurrect-strategy-" inline_strategy_token="->" +inline_strategy_arguments_token="*" save_command_strategy_option="@resurrect-save-command-strategy" default_save_command_strategy="ps"