Skip to content

Commit 7bf15ee

Browse files
committed
Convert setup files of the tests
1 parent 3d84dce commit 7bf15ee

File tree

2 files changed

+81
-7
lines changed

2 files changed

+81
-7
lines changed

test/helpers/setup_tmux_conf.sh

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,45 @@
66
setup_tmux_conf() {
77
# Copy mode (vi or emacs) is automatically determined from EDITOR
88
# 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 "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 "run-shell './copycat.tmux'" >> ~/.tmux.conf
13+
else
14+
echo "bind-key -t vi-copy y copy-selection" > ~/.tmux.conf
15+
echo "bind-key -t emacs-copy y copy-selection" >> ~/.tmux.conf
16+
echo "run-shell './copycat.tmux'" >> ~/.tmux.conf
17+
fi
1218
}
19+
20+
# Cache the TMUX version for speed.
21+
tmux_version="$(tmux -V | cut -d ' ' -f 2)"
22+
23+
tmux_is_at_least() {
24+
if [[ $tmux_version == "$1" || $tmux_version == "master" ]]
25+
then
26+
return 0
27+
fi
28+
29+
local IFS=.
30+
local i tver=($tmux_version) wver=($1)
31+
32+
# fill empty fields in tver with zeros
33+
for ((i=${#tver[@]}; i<${#wver[@]}; i++)); do
34+
tver[i]=0
35+
done
36+
37+
# fill empty fields in wver with zeros
38+
for ((i=${#wver[@]}; i<${#tver[@]}; i++)); do
39+
wver[i]=0
40+
done
41+
42+
for ((i=0; i<${#tver[@]}; i++)); do
43+
if ((10#${tver[i]} < 10#${wver[i]})); then
44+
return 1
45+
fi
46+
done
47+
return 0
48+
}
49+
1350
setup_tmux_conf

test/helpers/setup_tmux_conf_with_custom_searches.sh

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,46 @@
66
setup_tmux_conf() {
77
# Copy mode (vi or emacs) is automatically determined from EDITOR
88
# 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
1320
}
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+
1451
setup_tmux_conf

0 commit comments

Comments
 (0)