|
6 | 6 | setup_tmux_conf() {
|
7 | 7 | # Copy mode (vi or emacs) is automatically determined from EDITOR
|
8 | 8 | # environment variable set in test runner file `test/run-tests-within-vm`.
|
9 |
| - echo "bind-key -t vi-copy y copy-selection" > ~/.tmux.conf |
10 |
| - echo "bind-key -t emacs-copy y copy-selection" >> ~/.tmux.conf |
11 |
| - echo "set -g @copycat_search_C-t 'random string[[:digit:]]+'" >> ~/.tmux.conf |
12 |
| - echo "run-shell './copycat.tmux'" >> ~/.tmux.conf |
| 9 | + if tmux_is_at_least 2.4; then |
| 10 | + echo "bind-key -T copy-mode-vi y copy-selection-and-cancel" > ~/.tmux.conf |
| 11 | + echo "bind-key -T copy-mode-emacs y copy-selection-and-cancel" >> ~/.tmux.conf |
| 12 | + echo "set -g @copycat_search_C-t 'random string[[:digit:]]+'" >> ~/.tmux.conf |
| 13 | + echo "run-shell './copycat.tmux'" >> ~/.tmux.conf |
| 14 | + else |
| 15 | + echo "bind-key -t vi-copy y copy-selection" > ~/.tmux.conf |
| 16 | + echo "bind-key -t emacs-copy y copy-selection" >> ~/.tmux.conf |
| 17 | + echo "set -g @copycat_search_C-t 'random string[[:digit:]]+'" >> ~/.tmux.conf |
| 18 | + echo "run-shell './copycat.tmux'" >> ~/.tmux.conf |
| 19 | + fi |
13 | 20 | }
|
| 21 | +# Cache the TMUX version for speed. |
| 22 | +tmux_version="$(tmux -V | cut -d ' ' -f 2)" |
| 23 | + |
| 24 | +tmux_is_at_least() { |
| 25 | + if [[ $tmux_version == "$1" || $tmux_version == "master" ]] |
| 26 | + then |
| 27 | + return 0 |
| 28 | + fi |
| 29 | + |
| 30 | + local IFS=. |
| 31 | + local i tver=($tmux_version) wver=($1) |
| 32 | + |
| 33 | + # fill empty fields in tver with zeros |
| 34 | + for ((i=${#tver[@]}; i<${#wver[@]}; i++)); do |
| 35 | + tver[i]=0 |
| 36 | + done |
| 37 | + |
| 38 | + # fill empty fields in wver with zeros |
| 39 | + for ((i=${#wver[@]}; i<${#tver[@]}; i++)); do |
| 40 | + wver[i]=0 |
| 41 | + done |
| 42 | + |
| 43 | + for ((i=0; i<${#tver[@]}; i++)); do |
| 44 | + if ((10#${tver[i]} < 10#${wver[i]})); then |
| 45 | + return 1 |
| 46 | + fi |
| 47 | + done |
| 48 | + return 0 |
| 49 | +} |
| 50 | + |
14 | 51 | setup_tmux_conf
|
0 commit comments