blob: 8f2054bae0f1e4a35de1eb771e4d72bc9916f438 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
#!/bin/sh
#
# This is a library of subroutines mostly intended for test scripts.
#
fail()
{
printf "$@" 2>&1
exit 99
}
skip()
{
printf "$@" 2>&1
exit 77
}
sleepf()
{
(sleep .1 || sleep 1) > /dev/null 2>&1
}
seq_function()
{
if [ $# -lt 1 ] || [ $# -gt 3 ]; then
echo "bad args" >&2
fi
first=$1
incr=1
last=0
case $# in
3)
incr=$2
last=$3
;;
2)
last=$2
;;
1)
;;
esac
while :; do
printf '%d\n' "$first"
first=$(( first + incr ))
if [ "$first" -gt "$last" ]; then
break
fi
done
}
if ! seq 1 > /dev/null 2>&1; then
seq()
{
seq_function "$@"
}
fi
chr()
{
printf '%b' "\\0$(printf %03o "$1")"
}
# If the locale is not set to a UTF-8 locale, set it to en_US.UTF-8
# or C.UTF-8.
set_locale()
{
# Test for a usable locale.
if ./is-utf8-locale 2> /dev/null; then
return 0
fi
# Attempt to find/set a usable locale.
unset LANG LC_CTYPE LC_COLLATE LC_MESSAGES LC_MONETARY LC_NUMERIC LC_TIME LC_ALL
for i in en_US.UTF-8 en_US.utf8 C.UTF-8; do
if env LC_ALL=$i ./is-utf8-locale 2> /dev/null; then
export LC_ALL=$i
return 0
fi
done
# Fail.
return 1
}
# Tmux check.
tmux_check()
{
need_major="$1"; shift
need_minor="$1"; shift
# OpenBSD tmux does not have '-V'.
if [ "$(uname -s)" = "OpenBSD" ]; then
openbsd_major="$(uname -r)"
openbsd_major="${openbsd_major%%.*}"
if [ "${openbsd_major}" -ge 6 ]; then
return 0
fi
fi
version=$(tmux -V)
if [ $? != 0 ]; then
error "tmux unavailable\n"
return 1
fi
if [ "$version" = "tmux master" ]; then
return 0
fi
version=${version##tmux }
version_major=${version%%.*}
version_minor=${version##*.}
if [ "$version_major" -lt "$need_major" ] ||
{ [ "$version_major" -eq "$need_major" ] && [ "$version_minor" -lt "$need_minor" ]; }; then
printf "tmux version %s too old\n" "$version" >&2
return 1
fi
# Finally, check that tmux actually works to some degree.
#
# Use a different socket name. On Cygwin, this tmux server is
# slow to exit, and the actual test tmux can attach to it, causing
# problems with missing environment variables.
tmux_check_socket=$(mktemp -d /tmp/mosh-tmux-check.XXXXXXXX)
tmux -f /dev/null -S "${tmux_check_socket}/s" -C new-session true
rv=$?
rm ${tmux_check_socket}/s
rmdir ${tmux_check_socket}
return $rv
}
|