diff --git a/copycat.tmux b/copycat.tmux index be59a59..47c23b0 100755 --- a/copycat.tmux +++ b/copycat.tmux @@ -62,14 +62,9 @@ set_copycat_git_special_binding() { done } -set_copycat_mode_bindings() { - "$CURRENT_DIR/scripts/copycat_mode_bindings.sh" -} - main() { set_start_bindings set_copycat_search_binding set_copycat_git_special_binding - set_copycat_mode_bindings } main diff --git a/scripts/copycat_mode_bindings.sh b/scripts/copycat_mode_bindings.sh index 20d5725..cbcd5f3 100755 --- a/scripts/copycat_mode_bindings.sh +++ b/scripts/copycat_mode_bindings.sh @@ -14,11 +14,9 @@ fi extend_key() { local key="$1" local script="$2" - local copy_mode - copy_mode=$(tmux_copy_mode_string) + local cmd - # 1. The default command for 'key' is sent to tmux. This ensures the - # default key action is done. + # 1. 'cmd' or 'key' is sent to tmux. This ensures the default key action is done. # 2. Script is executed. # 3. `true` command ensures an exit status 0 is returned. This ensures # a user never gets an error msg - even if the script file from step 2 diff --git a/scripts/copycat_mode_quit.sh b/scripts/copycat_mode_quit.sh index b0b2a2b..8b291e1 100755 --- a/scripts/copycat_mode_quit.sh +++ b/scripts/copycat_mode_quit.sh @@ -4,11 +4,35 @@ CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" source "$CURRENT_DIR/helpers.sh" +unbind_cancel_bindings() { + local cancel_mode_bindings=$(copycat_quit_copy_mode_keys) + local key + for key in $cancel_mode_bindings; do + tmux unbind-key -n "$key" + done +} + +unbind_prev_next_bindings() { + tmux unbind-key -n "$(copycat_next_key)" + tmux unbind-key -n "$(copycat_prev_key)" +} + +unbind_all_bindings() { + grep -v copycat <"${TMPDIR:-/tmp}/copycat_$(whoami)_recover_keys" | while read -r key_cmd; do + sh -c "tmux $key_cmd" + done < /dev/stdin + rm "${TMPDIR:-/tmp}/copycat_$(whoami)_recover_keys" +} + main() { if in_copycat_mode; then reset_copycat_position unset_copycat_mode copycat_decrease_counter + # removing all bindings only if no panes are in copycat mode + if copycat_counter_zero; then + unbind_all_bindings + fi fi } main diff --git a/scripts/copycat_mode_start.sh b/scripts/copycat_mode_start.sh index b14f596..7c0c209 100755 --- a/scripts/copycat_mode_start.sh +++ b/scripts/copycat_mode_start.sh @@ -14,6 +14,7 @@ main() { local pattern="$1" if supported_tmux_version_ok; then $CURRENT_DIR/copycat_generate_results.sh "$pattern" # will `exit 0` if no results + $CURRENT_DIR/copycat_mode_bindings.sh $CURRENT_DIR/copycat_jump.sh 'next' fi } diff --git a/scripts/helpers.sh b/scripts/helpers.sh index 63fbd2d..edc8abb 100644 --- a/scripts/helpers.sh +++ b/scripts/helpers.sh @@ -42,11 +42,11 @@ tmux_copy_mode() { } tmux_copy_mode_string() { - if [ $(tmux_copy_mode) == 'vi' ]; then - echo copy-mode-vi - else - echo copy-mode - fi + if [ $(tmux_copy_mode) == 'vi' ]; then + echo copy-mode-vi + else + echo copy-mode + fi } # === copycat mode specific helpers ===