Skip to content

Commit 09cc8c9

Browse files
zzzyxwvutchrisbra
authored andcommitted
patch 9.1.0838: vimtutor is bash-specific
Problem: vimtutor is bash-specific (after 17c71da) Solution: port back to POSIX sh (Aliaksei Budavei). Signed-off-by: Aliaksei Budavei <[email protected]> Signed-off-by: Christian Brabandt <[email protected]>
1 parent ac2bb9d commit 09cc8c9

File tree

2 files changed

+81
-70
lines changed

2 files changed

+81
-70
lines changed

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,8 @@ static char *(features[]) =
704704

705705
static int included_patches[] =
706706
{ /* Add new patch number below this line */
707+
/**/
708+
838,
707709
/**/
708710
837,
709711
/**/

src/vimtutor

Lines changed: 79 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/bin/sh
22

33
# Start Vim on a copy of the tutor file.
44

@@ -11,8 +11,7 @@
1111

1212
# Vim could be called "vim" or "vi". Also check for "vimN", for people who
1313
# have Vim installed with its version number.
14-
# We anticipate up to a future Vim 8.1 version :-).
15-
seq="vim vim81 vim80 vim8 vim74 vim73 vim72 vim71 vim70 vim7 vim6 vi"
14+
seq="vim vim91 vim90 vim81 vim80 vim8 vim74 vim73 vim72 vim71 vim70 vim7 vim6 vi"
1615

1716
usage()
1817
{
@@ -31,94 +30,104 @@ usage()
3130

3231
listOptions()
3332
{
34-
declare -A language
35-
language[bar]=Bavarian
36-
language[bg]=Bulgarian
37-
language[ca]=Catalan
38-
language[cs]=Czech
39-
language[da]=Danish
40-
language[de]=German
41-
language[el]=Greek
42-
language[en]=English\(default\)
43-
language[eo]=Esperanto
44-
language[es]=Spanish
45-
language[fr]=French
46-
language[hr]=Croatian
47-
language[hu]=Hungarian
48-
language[it]=Italian
49-
language[ja]=Japanese
50-
language[ko]=Korean
51-
language[lv]=Latvian
52-
language[nb]=Bokmål
53-
language[nl]=Dutch
54-
language[no]=Norwegian
55-
language[pl]=Polish
56-
language[pt]=Portuguese
57-
language[ru]=Russian
58-
language[sk]=Slovak
59-
language[sr]=Serbian
60-
language[sv]=Swedish
61-
language[tr]=Turkish
62-
language[uk]=English
63-
language[vi]=Vietnamese
64-
language[zh]=Chinese
65-
66-
echo "==OPTIONS======================================================================================="
67-
echo "Chapter: 1"
68-
for code in bar bg ca cs da de el en eo es fr hr hu it ja ko lv nb nl no pl pt ru sk sr sv tr uk vi zh
69-
do
70-
printf "\tLang: %s => %s\n" ${code} ${language[${code}]}
71-
done
72-
echo "Chapter: 2"
73-
for code in en
74-
do
75-
printf "\tLang: %s => %s\n" ${code} ${language[${code}]}
76-
done
77-
echo "================================================================================================"
33+
echo "==OPTIONS======================================================================================="
34+
echo "Chapter: 1"
35+
printf "\tLang: %-3s => %s\n" \
36+
bar Bavarian \
37+
bg Bulgarian \
38+
ca Catalan \
39+
cs Czech \
40+
da Danish \
41+
de German \
42+
el Greek \
43+
en English\(default\) \
44+
eo Esperanto \
45+
es Spanish \
46+
fr French \
47+
hr Croatian \
48+
hu Hungarian \
49+
it Italian \
50+
ja Japanese \
51+
ko Korean \
52+
lv Latvian \
53+
nb Bokmål \
54+
nl Dutch \
55+
no Norwegian \
56+
pl Polish \
57+
pt Portuguese \
58+
ru Russian \
59+
sk Slovak \
60+
sr Serbian \
61+
sv Swedish \
62+
tr Turkish \
63+
uk English \
64+
vi Vietnamese \
65+
zh Chinese
66+
67+
echo "Chapter: 2"
68+
printf "\tLang: %-3s => %s\n" \
69+
en English\(default\)
70+
echo "================================================================================================"
7871
}
7972

8073
validateLang()
8174
{
82-
if [[ $xx =~ ^[^a-z]*$ ]]; then echo "Error: iso639 code must contain only [a-z]" && exit 1; fi
83-
if [ ${#xx} == 2 ] || [ ${#xx} == 3 ]; then :; else echo "Error: iso639 code must be 2 or 3 characters only" && exit 1; fi
75+
case "$xx" in
76+
'' | *[!a-z]* )
77+
echo "Error: iso639 code must contain only [a-z]"
78+
exit 1
79+
esac
80+
81+
case "${#xx}" in
82+
[23] )
83+
;;
84+
* )
85+
echo "Error: iso639 code must be 2 or 3 characters only"
86+
exit 1
87+
esac
88+
8489
export xx
8590
}
8691

8792
validateChapter()
8893
{
89-
if [[ $cc =~ ^[0-9]*$ ]]; then :; else echo "Error: chapter argument must contain digits only" && exit 1; fi
90-
if [ $cc == "0" ]; then echo "Error: chapter must be non-zero" && exit 1; fi
91-
if [ $cc == "00" ]; then echo "Error: chapter must be non-zero" && exit 1; fi
94+
case "$cc" in
95+
'' | *[!0-9]* )
96+
echo "Error: chapter argument must contain digits only"
97+
exit 1
98+
;;
99+
0 | 00 )
100+
echo "Error: chapter must be non-zero"
101+
exit 1
102+
esac
103+
92104
export CHAPTER="$cc"
93105
}
94106

95-
shopt -s extglob
96107
while [ "$1" != "" ]; do
97-
case $1 in
108+
case "$1" in
98109
-g | --gui ) seq="gvim gvim91 gvim90 gvim81 gvim80 gvim8 gvim74 gvim73 gvim72 gvim71 gvim70 gvim7 gvim6 $seq"
99110
;;
100111
-l | --language ) shift
101-
xx=$1
112+
xx="$1"
102113
validateLang
103114
;;
104-
-l[a-z][a-z]?([a-z]) ) xx=${1#*l}
105-
validateLang
115+
-l[a-z][a-z][a-z] | -l[a-z][a-z] )
116+
export xx="${1#*l}"
106117
;;
107-
--language[a-z][a-z]?([a-z]) ) xx=${1#*e}
108-
validateLang
118+
--language[a-z][a-z][a-z] | --language[a-z][a-z] )
119+
export xx="${1#*e}"
109120
;;
110-
[a-z][a-z]?([a-z]) ) xx=$1
111-
validateLang
121+
[a-z][a-z][a-z] | [a-z][a-z] ) export xx="$1"
112122
;;
113123
-c | --chapter ) shift
114-
cc=$1
124+
cc="$1"
115125
validateChapter
116126
;;
117-
-c[0-9]?([0-9]) ) cc=${1#*c}
118-
validateChapter
127+
-c[1-9][0-9] | -c[1-9] ) export CHAPTER="${1#*c}"
119128
;;
120-
--chapter[0-9]?([0-9]) ) cc=${1#*r}
121-
validateChapter
129+
--chapter[1-9][0-9] | --chapter[1-9] )
130+
export CHAPTER="${1#*r}"
122131
;;
123132
-h | --help ) usage
124133
exit
@@ -129,8 +138,8 @@ while [ "$1" != "" ]; do
129138
"" ) ;;
130139
* ) usage
131140
exit 1
132-
esac
133-
shift
141+
esac
142+
shift
134143
done
135144

136145

@@ -161,10 +170,10 @@ fi
161170
export TUTORCOPY
162171

163172
# remove the copy of the tutor on exit
164-
trap "rm -rf $TODELETE" 0 1 2 3 9 11 13 15
173+
trap "rm -rf $TODELETE" EXIT HUP INT QUIT SEGV PIPE TERM
165174

166175
for i in $seq; do
167-
testvim=$(which $i 2>/dev/null)
176+
testvim=$(command -v "$i" 2>/dev/null)
168177
if test -f "$testvim"; then
169178
VIM=$i
170179
break

0 commit comments

Comments
 (0)