2024-11-04 19:43:22 +01:00
|
|
|
#!/bin/sh
|
2004-06-13 20:20:40 +00:00
|
|
|
|
|
|
|
# Start Vim on a copy of the tutor file.
|
|
|
|
|
2008-05-07 15:40:33 +00:00
|
|
|
# Usage: vimtutor [-g] [xx]
|
|
|
|
# Where optional argument -g starts vimtutor in gvim (GUI) instead of vim.
|
|
|
|
# and xx is a language code like "es" or "nl".
|
2004-06-13 20:20:40 +00:00
|
|
|
# When an argument is given, it tries loading that tutor.
|
|
|
|
# When this fails or no argument was given, it tries using 'v:lang'
|
|
|
|
# When that also fails, it uses the English version.
|
|
|
|
|
2008-05-07 15:40:33 +00:00
|
|
|
# Vim could be called "vim" or "vi". Also check for "vimN", for people who
|
|
|
|
# have Vim installed with its version number.
|
2024-11-04 19:43:22 +01:00
|
|
|
seq="vim vim91 vim90 vim81 vim80 vim8 vim74 vim73 vim72 vim71 vim70 vim7 vim6 vi"
|
2024-11-03 20:47:53 +01:00
|
|
|
|
|
|
|
usage()
|
|
|
|
{
|
|
|
|
echo "==USAGE========================================================================================="
|
|
|
|
echo "${0##*/} [-(-l)anguage ISO639] [-(-c)hapter) NUMBER] [-(-g)ui] | [-(-h)elp] | [--list]"
|
|
|
|
printf "\twhere:\n"
|
|
|
|
printf "\t\tISO639 (default=en) is a 2 or 3 character language code\n"
|
|
|
|
printf "\t\tNUMBER (default=01) is one or two digits representing the chapter number\n"
|
|
|
|
printf "\texamples:\n"
|
|
|
|
printf "\t\tvimtutor -l es -c 2 -g\n"
|
|
|
|
printf "\t\tvimtutor --language de --chapter 02\n"
|
|
|
|
printf "\t\tvimtutor fr\n"
|
|
|
|
echo "More information at 'man vimtutor'"
|
|
|
|
echo "================================================================================================"
|
|
|
|
}
|
|
|
|
|
|
|
|
listOptions()
|
|
|
|
{
|
2024-11-04 19:43:22 +01:00
|
|
|
echo "==OPTIONS======================================================================================="
|
|
|
|
echo "Chapter: 1"
|
|
|
|
printf "\tLang: %-3s => %s\n" \
|
|
|
|
bar Bavarian \
|
|
|
|
bg Bulgarian \
|
|
|
|
ca Catalan \
|
|
|
|
cs Czech \
|
|
|
|
da Danish \
|
|
|
|
de German \
|
|
|
|
el Greek \
|
|
|
|
en English\(default\) \
|
|
|
|
eo Esperanto \
|
|
|
|
es Spanish \
|
|
|
|
fr French \
|
|
|
|
hr Croatian \
|
|
|
|
hu Hungarian \
|
|
|
|
it Italian \
|
|
|
|
ja Japanese \
|
|
|
|
ko Korean \
|
|
|
|
lv Latvian \
|
|
|
|
nb Bokmål \
|
|
|
|
nl Dutch \
|
|
|
|
no Norwegian \
|
|
|
|
pl Polish \
|
|
|
|
pt Portuguese \
|
|
|
|
ru Russian \
|
|
|
|
sk Slovak \
|
|
|
|
sr Serbian \
|
|
|
|
sv Swedish \
|
|
|
|
tr Turkish \
|
|
|
|
uk English \
|
|
|
|
vi Vietnamese \
|
|
|
|
zh Chinese
|
|
|
|
|
|
|
|
echo "Chapter: 2"
|
|
|
|
printf "\tLang: %-3s => %s\n" \
|
|
|
|
en English\(default\)
|
|
|
|
echo "================================================================================================"
|
2024-11-03 20:47:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
validateLang()
|
|
|
|
{
|
2024-11-04 19:43:22 +01:00
|
|
|
case "$xx" in
|
|
|
|
'' | *[!a-z]* )
|
|
|
|
echo "Error: iso639 code must contain only [a-z]"
|
|
|
|
exit 1
|
|
|
|
esac
|
|
|
|
|
|
|
|
case "${#xx}" in
|
|
|
|
[23] )
|
|
|
|
;;
|
|
|
|
* )
|
|
|
|
echo "Error: iso639 code must be 2 or 3 characters only"
|
|
|
|
exit 1
|
|
|
|
esac
|
|
|
|
|
2024-11-03 20:47:53 +01:00
|
|
|
export xx
|
|
|
|
}
|
|
|
|
|
|
|
|
validateChapter()
|
|
|
|
{
|
2024-11-04 19:43:22 +01:00
|
|
|
case "$cc" in
|
|
|
|
'' | *[!0-9]* )
|
|
|
|
echo "Error: chapter argument must contain digits only"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
0 | 00 )
|
|
|
|
echo "Error: chapter must be non-zero"
|
|
|
|
exit 1
|
|
|
|
esac
|
|
|
|
|
2024-11-03 20:47:53 +01:00
|
|
|
export CHAPTER="$cc"
|
|
|
|
}
|
|
|
|
|
|
|
|
while [ "$1" != "" ]; do
|
2024-11-04 19:43:22 +01:00
|
|
|
case "$1" in
|
2024-11-03 20:47:53 +01:00
|
|
|
-g | --gui ) seq="gvim gvim91 gvim90 gvim81 gvim80 gvim8 gvim74 gvim73 gvim72 gvim71 gvim70 gvim7 gvim6 $seq"
|
|
|
|
;;
|
|
|
|
-l | --language ) shift
|
2024-11-04 19:43:22 +01:00
|
|
|
xx="$1"
|
2024-11-03 20:47:53 +01:00
|
|
|
validateLang
|
|
|
|
;;
|
2024-11-04 19:43:22 +01:00
|
|
|
-l[a-z][a-z][a-z] | -l[a-z][a-z] )
|
|
|
|
export xx="${1#*l}"
|
2024-11-03 20:47:53 +01:00
|
|
|
;;
|
2024-11-04 19:43:22 +01:00
|
|
|
--language[a-z][a-z][a-z] | --language[a-z][a-z] )
|
|
|
|
export xx="${1#*e}"
|
2024-11-03 20:47:53 +01:00
|
|
|
;;
|
2024-11-04 19:43:22 +01:00
|
|
|
[a-z][a-z][a-z] | [a-z][a-z] ) export xx="$1"
|
2024-11-03 20:47:53 +01:00
|
|
|
;;
|
|
|
|
-c | --chapter ) shift
|
2024-11-04 19:43:22 +01:00
|
|
|
cc="$1"
|
2024-11-03 20:47:53 +01:00
|
|
|
validateChapter
|
|
|
|
;;
|
2024-11-04 19:43:22 +01:00
|
|
|
-c[1-9][0-9] | -c[1-9] ) export CHAPTER="${1#*c}"
|
2024-11-03 20:47:53 +01:00
|
|
|
;;
|
2024-11-04 19:43:22 +01:00
|
|
|
--chapter[1-9][0-9] | --chapter[1-9] )
|
|
|
|
export CHAPTER="${1#*r}"
|
2024-11-03 20:47:53 +01:00
|
|
|
;;
|
|
|
|
-h | --help ) usage
|
|
|
|
exit
|
|
|
|
;;
|
|
|
|
--list ) listOptions
|
|
|
|
exit
|
|
|
|
;;
|
|
|
|
"" ) ;;
|
|
|
|
* ) usage
|
|
|
|
exit 1
|
2024-11-04 19:43:22 +01:00
|
|
|
esac
|
|
|
|
shift
|
2024-11-03 20:47:53 +01:00
|
|
|
done
|
2008-05-07 15:40:33 +00:00
|
|
|
|
2004-06-13 20:20:40 +00:00
|
|
|
|
|
|
|
# We need a temp file for the copy. First try using a standard command.
|
|
|
|
tmp="${TMPDIR-/tmp}"
|
|
|
|
TUTORCOPY=`mktemp $tmp/tutorXXXXXX || tempfile -p tutor || echo none`
|
|
|
|
|
|
|
|
# If the standard commands failed then create a directory to put the copy in.
|
|
|
|
# That is a secure way to make a temp file.
|
|
|
|
if test "$TUTORCOPY" = none; then
|
|
|
|
tmpdir=$tmp/vimtutor$$
|
|
|
|
OLD_UMASK=`umask`
|
|
|
|
umask 077
|
|
|
|
getout=no
|
|
|
|
mkdir $tmpdir || getout=yes
|
|
|
|
umask $OLD_UMASK
|
|
|
|
if test $getout = yes; then
|
|
|
|
echo "Could not create directory for tutor copy, exiting."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
TUTORCOPY=$tmpdir/tutorcopy
|
|
|
|
touch $TUTORCOPY
|
|
|
|
TODELETE=$tmpdir
|
|
|
|
else
|
|
|
|
TODELETE=$TUTORCOPY
|
|
|
|
fi
|
|
|
|
|
|
|
|
export TUTORCOPY
|
|
|
|
|
|
|
|
# remove the copy of the tutor on exit
|
2024-11-04 19:43:22 +01:00
|
|
|
trap "rm -rf $TODELETE" EXIT HUP INT QUIT SEGV PIPE TERM
|
2004-06-13 20:20:40 +00:00
|
|
|
|
2007-07-17 12:33:46 +00:00
|
|
|
for i in $seq; do
|
2024-11-04 19:43:22 +01:00
|
|
|
testvim=$(command -v "$i" 2>/dev/null)
|
2021-08-29 21:55:35 +02:00
|
|
|
if test -f "$testvim"; then
|
|
|
|
VIM=$i
|
|
|
|
break
|
|
|
|
fi
|
2007-07-17 12:33:46 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
# When no Vim version was found fall back to "vim", you'll get an error message
|
|
|
|
# below.
|
|
|
|
if test -z "$VIM"; then
|
2021-08-29 21:55:35 +02:00
|
|
|
VIM=vim
|
2004-06-13 20:20:40 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Use Vim to copy the tutor, it knows the value of $VIMRUNTIME
|
|
|
|
# The script tutor.vim tells Vim which file to copy
|
2024-11-03 20:47:53 +01:00
|
|
|
|
2008-05-07 15:40:33 +00:00
|
|
|
$VIM -f -u NONE -c 'so $VIMRUNTIME/tutor/tutor.vim'
|
2004-06-13 20:20:40 +00:00
|
|
|
|
2018-04-12 20:36:43 +02:00
|
|
|
# Start vim without any .vimrc, set 'nocompatible' and 'showcmd'
|
2021-08-29 21:55:35 +02:00
|
|
|
$VIM -f -u NONE -c "set nocp showcmd" "$TUTORCOPY"
|