File tree Expand file tree Collapse file tree 5 files changed +29
-46
lines changed Expand file tree Collapse file tree 5 files changed +29
-46
lines changed Original file line number Diff line number Diff line change @@ -62,9 +62,14 @@ set_copycat_git_special_binding() {
62
62
done
63
63
}
64
64
65
+ set_copycat_mode_bindings () {
66
+ " $CURRENT_DIR /scripts/copycat_mode_bindings.sh"
67
+ }
68
+
65
69
main () {
66
70
set_start_bindings
67
71
set_copycat_search_binding
68
72
set_copycat_git_special_binding
73
+ set_copycat_mode_bindings
69
74
}
70
75
main
Original file line number Diff line number Diff line change 14
14
extend_key () {
15
15
local key=" $1 "
16
16
local script=" $2 "
17
- local cmd
17
+ local copy_mode
18
+ copy_mode=$( tmux_copy_mode_string)
18
19
19
- # 1. 'cmd' or 'key' is sent to tmux. This ensures the default key action is done.
20
+ # 1. The default command for 'key' is sent to tmux. This ensures the
21
+ # default key action is done.
20
22
# 2. Script is executed.
21
- # 3. `true` command ensures an exit status 0 is returned. This ensures a
22
- # user never gets an error msg - even if the script file from step 2 is
23
- # deleted.
24
- # We fetch the current behavior of the 'key' mapping in
25
- # variable 'cmd'
26
- cmd=$( tmux list-keys -T $( tmux_copy_mode_string) | $AWK_CMD ' $4 == "' $key ' "' | $AWK_CMD ' { $1=""; $2=""; $3=""; $4=""; sub(" ", " "); print }' )
27
- # If 'cmd' is already a copycat command, we do nothing
28
- if echo " $cmd " | grep -q copycat; then
29
- return
30
- fi
31
- # We save the previous mapping to a file in order to be able to recover
32
- # the previous mapping when we unbind
33
- tmux list-keys -T $( tmux_copy_mode_string) | $AWK_CMD ' $4 == "' $key ' "' >> " ${TMPDIR:-/ tmp} /copycat_$( whoami) _recover_keys"
34
- tmux bind-key -T $( tmux_copy_mode_string) " $key " run-shell " tmux $cmd ; $script ; true"
23
+ # 3. `true` command ensures an exit status 0 is returned. This ensures
24
+ # a user never gets an error msg - even if the script file from step 2
25
+ # is deleted.
26
+ tmux list-keys -T " $copy_mode " |
27
+ " $AWK_CMD " '
28
+ /copycat/ { next }
29
+ $3 == "' " $copy_mode " ' " && $4 == "' " $key " ' " {
30
+ $1=""
31
+ $2=""
32
+ $3=""
33
+ $4=""
34
+ gsub(";", "\\;", $0)
35
+ cmd=$0
36
+ system("tmux bind-key -T ' " $copy_mode " ' ' " $key " ' run-shell \"tmux " cmd "; ' " $script " ' ; true\"")
37
+ }'
35
38
}
36
39
37
40
copycat_cancel_bindings () {
Original file line number Diff line number Diff line change @@ -4,35 +4,11 @@ CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
4
4
5
5
source " $CURRENT_DIR /helpers.sh"
6
6
7
- unbind_cancel_bindings () {
8
- local cancel_mode_bindings=$( copycat_quit_copy_mode_keys)
9
- local key
10
- for key in $cancel_mode_bindings ; do
11
- tmux unbind-key -n " $key "
12
- done
13
- }
14
-
15
- unbind_prev_next_bindings () {
16
- tmux unbind-key -n " $( copycat_next_key) "
17
- tmux unbind-key -n " $( copycat_prev_key) "
18
- }
19
-
20
- unbind_all_bindings () {
21
- grep -v copycat < " ${TMPDIR:-/ tmp} /copycat_$( whoami) _recover_keys" | while read -r key_cmd; do
22
- sh -c " tmux $key_cmd "
23
- done < /dev/stdin
24
- rm " ${TMPDIR:-/ tmp} /copycat_$( whoami) _recover_keys"
25
- }
26
-
27
7
main () {
28
8
if in_copycat_mode; then
29
9
reset_copycat_position
30
10
unset_copycat_mode
31
11
copycat_decrease_counter
32
- # removing all bindings only if no panes are in copycat mode
33
- if copycat_counter_zero; then
34
- unbind_all_bindings
35
- fi
36
12
fi
37
13
}
38
14
main
Original file line number Diff line number Diff line change @@ -14,7 +14,6 @@ main() {
14
14
local pattern=" $1 "
15
15
if supported_tmux_version_ok; then
16
16
$CURRENT_DIR /copycat_generate_results.sh " $pattern " # will `exit 0` if no results
17
- $CURRENT_DIR /copycat_mode_bindings.sh
18
17
$CURRENT_DIR /copycat_jump.sh ' next'
19
18
fi
20
19
}
Original file line number Diff line number Diff line change @@ -42,11 +42,11 @@ tmux_copy_mode() {
42
42
}
43
43
44
44
tmux_copy_mode_string () {
45
- if [ $( tmux_copy_mode) == ' vi' ]; then
46
- echo copy-mode-vi
47
- else
48
- echo copy-mode
49
- fi
45
+ if [ $( tmux_copy_mode) == ' vi' ]; then
46
+ echo copy-mode-vi
47
+ else
48
+ echo copy-mode
49
+ fi
50
50
}
51
51
52
52
# === copycat mode specific helpers ===
You can’t perform that action at this time.
0 commit comments