File tree Expand file tree Collapse file tree 3 files changed +42
-16
lines changed Expand file tree Collapse file tree 3 files changed +42
-16
lines changed Original file line number Diff line number Diff line change @@ -11,12 +11,19 @@ extend_key() {
11
11
local key=" $1 "
12
12
local script=" $2 "
13
13
14
- # 1. 'key' is sent to tmux. This ensures the default key action is done.
15
- # 2. Script is executed.
16
- # 3. `true` command ensures an exit status 0 is returned. This ensures a
17
- # user never gets an error msg - even if the script file from step 2 is
18
- # deleted.
19
- tmux bind-key -n " $key " run-shell " tmux send-keys '$key '; $script ; true"
14
+ if tmux_is_at_least 2.4; then
15
+ # We save the previous mapping to a file in order to be able to recover
16
+ # the previous mapping when we unbind
17
+ tmux list-keys -T copy-mode-$( tmux_copy_mode) | grep -F " $key " >> /tmp/copycat_$( whoami) _recover_keys
18
+ tmux bind-key -T copy-mode-$( tmux_copy_mode) " $key " run-shell " $script "
19
+ else
20
+ # 1. 'key' is sent to tmux. This ensures the default key action is done.
21
+ # 2. Script is executed.
22
+ # 3. `true` command ensures an exit status 0 is returned. This ensures a
23
+ # user never gets an error msg - even if the script file from step 2 is
24
+ # deleted.
25
+ tmux bind-key -n " $key " run-shell " tmux send-keys '$key '; $script ; true"
26
+ fi
20
27
}
21
28
22
29
copycat_cancel_bindings () {
Original file line number Diff line number Diff line change @@ -18,8 +18,15 @@ unbind_prev_next_bindings() {
18
18
}
19
19
20
20
unbind_all_bindings () {
21
- unbind_cancel_bindings
22
- unbind_prev_next_bindings
21
+ if tmux_is_at_least 2.4; then
22
+ while read key_cmd; do
23
+ tmux $key_cmd
24
+ done < /tmp/copycat_$( whoami) _recover_keys
25
+ rm /tmp/copycat_$( whoami) _recover_keys
26
+ else
27
+ unbind_cancel_bindings
28
+ unbind_prev_next_bindings
29
+ fi
23
30
}
24
31
25
32
main () {
Original file line number Diff line number Diff line change @@ -150,14 +150,26 @@ copycat_prev_key() {
150
150
151
151
# function expected output: 'C-c Enter q'
152
152
copycat_quit_copy_mode_keys () {
153
- local commands_that_quit_copy_mode=" cancel\|copy-selection\|copy-pipe"
154
- local copy_mode=" $( tmux_copy_mode) -copy"
155
- tmux list-keys -t " $copy_mode " |
156
- \g rep " $commands_that_quit_copy_mode " |
157
- $AWK_CMD ' { print $4}' |
158
- sort -u |
159
- sed ' s/C-j//g' |
160
- xargs echo
153
+ if tmux_is_at_least 2.4; then
154
+ local commands_that_quit_copy_mode=" cancel"
155
+ local copy_mode=" copy-mode-$( tmux_copy_mode) "
156
+ tmux list-keys -T " $copy_mode " |
157
+ \g rep " $commands_that_quit_copy_mode " |
158
+ $AWK_CMD ' { print $4 }' |
159
+ sort -u |
160
+ sed ' s/C-j//g' |
161
+ xargs echo
162
+
163
+ else
164
+ local commands_that_quit_copy_mode=" cancel\|copy-selection\|copy-pipe"
165
+ local copy_mode=" $( tmux_copy_mode) -copy"
166
+ tmux list-keys -t " $copy_mode " |
167
+ \g rep " $commands_that_quit_copy_mode " |
168
+ $AWK_CMD ' { print $4 }' |
169
+ sort -u |
170
+ sed ' s/C-j//g' |
171
+ xargs echo
172
+ fi
161
173
}
162
174
163
175
# === 'private' functions ===
You can’t perform that action at this time.
0 commit comments