Skip to content

Commit 6d26892

Browse files
authored
Merge pull request #24 from docwhat/pr/tmux-2.4
support tmux 2.4
2 parents ae3e22b + d595cc1 commit 6d26892

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed

open.tmux

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,13 @@ set_copy_mode_open_bindings() {
8888
local key_bindings=$(get_tmux_option "$open_option" "$default_open_key")
8989
local key
9090
for key in $key_bindings; do
91-
tmux bind-key -t vi-copy "$key" copy-pipe "$open_command"
92-
tmux bind-key -t emacs-copy "$key" copy-pipe "$open_command"
91+
if tmux-is-at-least 2.4; then
92+
tmux bind-key -T copy-mode-vi "$key" send-keys -X copy-pipe-and-cancel "$open_command"
93+
tmux bind-key -T copy-mode "$key" send-keys -X copy-pipe-and-cancel "$open_command"
94+
else
95+
tmux bind-key -t vi-copy "$key" copy-pipe "$open_command"
96+
tmux bind-key -t emacs-copy "$key" copy-pipe "$open_command"
97+
fi
9398
done
9499
}
95100

@@ -98,8 +103,13 @@ set_copy_mode_open_editor_bindings() {
98103
local key_bindings=$(get_tmux_option "$open_editor_option" "$default_open_editor_key")
99104
local key
100105
for key in $key_bindings; do
101-
tmux bind-key -t vi-copy "$key" copy-pipe "$editor_command"
102-
tmux bind-key -t emacs-copy "$key" copy-pipe "$editor_command"
106+
if tmux-is-at-least 2.4; then
107+
tmux bind-key -T copy-mode-vi "$key" send-keys -X copy-pipe-and-cancel "$editor_command"
108+
tmux bind-key -T copy-mode "$key" send-keys -X copy-pipe-and-cancel "$editor_command"
109+
else
110+
tmux bind-key -t vi-copy "$key" copy-pipe "$editor_command"
111+
tmux bind-key -t emacs-copy "$key" copy-pipe "$editor_command"
112+
fi
103113
done
104114
}
105115

scripts/helpers.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,31 @@ get_engine() {
4242
local engine_var="$1"
4343
tmux show-options -g | grep -i "^@open-$engine_var" | cut -d ' ' -f2 | xargs
4444
}
45+
46+
tmux_version="$(tmux -V | cut -d ' ' -f 2)"
47+
tmux-is-at-least() {
48+
if [[ $tmux_version == $1 ]]
49+
then
50+
return 0
51+
fi
52+
53+
local IFS=.
54+
local i tver=($tmux_version) wver=($1)
55+
56+
# fill empty fields in tver with zeros
57+
for ((i=${#tver[@]}; i<${#wver[@]}; i++)); do
58+
tver[i]=0
59+
done
60+
61+
# fill empty fields in wver with zeros
62+
for ((i=${#wver[@]}; i<${#tver[@]}; i++)); do
63+
wver[i]=0
64+
done
65+
66+
for ((i=0; i<${#tver[@]}; i++)); do
67+
if ((10#${tver[i]} < 10#${wver[i]})); then
68+
return 1
69+
fi
70+
done
71+
return 0
72+
}

0 commit comments

Comments
 (0)