Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1 | #! /bin/sh |
| 2 | |
| 3 | # Start Vim on a copy of the tutor file. |
| 4 | |
| 5 | # Usage: vimtutor [xx], where xx is a language code like "es" or "nl". |
| 6 | # When an argument is given, it tries loading that tutor. |
| 7 | # When this fails or no argument was given, it tries using 'v:lang' |
| 8 | # When that also fails, it uses the English version. |
| 9 | |
| 10 | xx=$1 |
| 11 | export xx |
| 12 | |
| 13 | # We need a temp file for the copy. First try using a standard command. |
| 14 | tmp="${TMPDIR-/tmp}" |
| 15 | TUTORCOPY=`mktemp $tmp/tutorXXXXXX || tempfile -p tutor || echo none` |
| 16 | |
| 17 | # If the standard commands failed then create a directory to put the copy in. |
| 18 | # That is a secure way to make a temp file. |
| 19 | if test "$TUTORCOPY" = none; then |
| 20 | tmpdir=$tmp/vimtutor$$ |
| 21 | OLD_UMASK=`umask` |
| 22 | umask 077 |
| 23 | getout=no |
| 24 | mkdir $tmpdir || getout=yes |
| 25 | umask $OLD_UMASK |
| 26 | if test $getout = yes; then |
| 27 | echo "Could not create directory for tutor copy, exiting." |
| 28 | exit 1 |
| 29 | fi |
| 30 | TUTORCOPY=$tmpdir/tutorcopy |
| 31 | touch $TUTORCOPY |
| 32 | TODELETE=$tmpdir |
| 33 | else |
| 34 | TODELETE=$TUTORCOPY |
| 35 | fi |
| 36 | |
| 37 | export TUTORCOPY |
| 38 | |
| 39 | # remove the copy of the tutor on exit |
| 40 | trap "rm -rf $TODELETE" 0 1 2 3 9 11 13 15 |
| 41 | |
Bram Moolenaar | 1315349 | 2007-07-17 12:33:46 +0000 | [diff] [blame] | 42 | # Vim could be called "vim" or "vi". Also check for "vimN", for people who |
| 43 | # have Vim installed with its version number. |
| 44 | # We anticipate up to a future Vim 8 version :-). |
| 45 | seq="vim vim8 vim75 vim74 vim73 vim72 vim71 vim70 vim7 vim6 vi" |
| 46 | for i in $seq; do |
| 47 | testvim=`which $i 2>/dev/null` |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 48 | if test -f "$testvim"; then |
Bram Moolenaar | 1315349 | 2007-07-17 12:33:46 +0000 | [diff] [blame] | 49 | VIM=$i |
| 50 | break |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 51 | fi |
Bram Moolenaar | 1315349 | 2007-07-17 12:33:46 +0000 | [diff] [blame] | 52 | done |
| 53 | |
| 54 | # When no Vim version was found fall back to "vim", you'll get an error message |
| 55 | # below. |
| 56 | if test -z "$VIM"; then |
| 57 | VIM=vim |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 58 | fi |
| 59 | |
| 60 | # Use Vim to copy the tutor, it knows the value of $VIMRUNTIME |
| 61 | # The script tutor.vim tells Vim which file to copy |
| 62 | $VIM -u NONE -c 'so $VIMRUNTIME/tutor/tutor.vim' |
| 63 | |
| 64 | # Start vim without any .vimrc, set 'nocompatible' |
| 65 | $VIM -u NONE -c "set nocp" $TUTORCOPY |