blob: e53201df58279fad132b1ea7054a85bc42d4f1b5 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001#! /bin/sh
2
3# Start Vim on a copy of the tutor file.
4
Bram Moolenaar2b570782008-05-07 15:40:33 +00005# Usage: vimtutor [-g] [xx]
6# Where optional argument -g starts vimtutor in gvim (GUI) instead of vim.
7# and xx is a language code like "es" or "nl".
Bram Moolenaar071d4272004-06-13 20:20:40 +00008# When an argument is given, it tries loading that tutor.
9# When this fails or no argument was given, it tries using 'v:lang'
10# When that also fails, it uses the English version.
11
Bram Moolenaar2b570782008-05-07 15:40:33 +000012# Vim could be called "vim" or "vi". Also check for "vimN", for people who
13# have Vim installed with its version number.
Bram Moolenaarbbe917d2016-09-21 22:41:24 +020014# We anticipate up to a future Vim 8.1 version :-).
15seq="vim vim81 vim80 vim8 vim74 vim73 vim72 vim71 vim70 vim7 vim6 vi"
Bram Moolenaar2b570782008-05-07 15:40:33 +000016if test "$1" = "-g"; then
17 # Try to use the GUI version of Vim if possible, it will fall back
18 # on Vim if Gvim is not installed.
Bram Moolenaarbbe917d2016-09-21 22:41:24 +020019 seq="gvim gvim81 gvim80 gvim8 gvim74 gvim73 gvim72 gvim71 gvim70 gvim7 gvim6 $seq"
Bram Moolenaar2b570782008-05-07 15:40:33 +000020 shift
21fi
22
Bram Moolenaar071d4272004-06-13 20:20:40 +000023xx=$1
24export xx
25
26# We need a temp file for the copy. First try using a standard command.
27tmp="${TMPDIR-/tmp}"
28TUTORCOPY=`mktemp $tmp/tutorXXXXXX || tempfile -p tutor || echo none`
29
30# If the standard commands failed then create a directory to put the copy in.
31# That is a secure way to make a temp file.
32if test "$TUTORCOPY" = none; then
33 tmpdir=$tmp/vimtutor$$
34 OLD_UMASK=`umask`
35 umask 077
36 getout=no
37 mkdir $tmpdir || getout=yes
38 umask $OLD_UMASK
39 if test $getout = yes; then
40 echo "Could not create directory for tutor copy, exiting."
41 exit 1
42 fi
43 TUTORCOPY=$tmpdir/tutorcopy
44 touch $TUTORCOPY
45 TODELETE=$tmpdir
46else
47 TODELETE=$TUTORCOPY
48fi
49
50export TUTORCOPY
51
52# remove the copy of the tutor on exit
53trap "rm -rf $TODELETE" 0 1 2 3 9 11 13 15
54
Bram Moolenaar13153492007-07-17 12:33:46 +000055for i in $seq; do
56 testvim=`which $i 2>/dev/null`
Bram Moolenaar071d4272004-06-13 20:20:40 +000057 if test -f "$testvim"; then
Bram Moolenaar13153492007-07-17 12:33:46 +000058 VIM=$i
59 break
Bram Moolenaar071d4272004-06-13 20:20:40 +000060 fi
Bram Moolenaar13153492007-07-17 12:33:46 +000061done
62
63# When no Vim version was found fall back to "vim", you'll get an error message
64# below.
65if test -z "$VIM"; then
66 VIM=vim
Bram Moolenaar071d4272004-06-13 20:20:40 +000067fi
68
69# Use Vim to copy the tutor, it knows the value of $VIMRUNTIME
70# The script tutor.vim tells Vim which file to copy
Bram Moolenaar2b570782008-05-07 15:40:33 +000071$VIM -f -u NONE -c 'so $VIMRUNTIME/tutor/tutor.vim'
Bram Moolenaar071d4272004-06-13 20:20:40 +000072
73# Start vim without any .vimrc, set 'nocompatible'
Bram Moolenaar2b570782008-05-07 15:40:33 +000074$VIM -f -u NONE -c "set nocp" $TUTORCOPY