Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Improve performance by binding copycat keys just once" #152

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions copycat.tmux
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 2 additions & 4 deletions scripts/copycat_mode_bindings.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions scripts/copycat_mode_quit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line was the fix for #121 (original introduced in 5f6bfc0), but 6bcd4dc removed it.

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
1 change: 1 addition & 0 deletions scripts/copycat_mode_start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
10 changes: 5 additions & 5 deletions scripts/helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 ===
Expand Down