blob: 2fbb1371fb3c46d12445f30abd162f429842a4ee [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
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
10xx=$1
11export xx
12
13# We need a temp file for the copy. First try using a standard command.
14tmp="${TMPDIR-/tmp}"
15TUTORCOPY=`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.
19if 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
33else
34 TODELETE=$TUTORCOPY
35fi
36
37export TUTORCOPY
38
39# remove the copy of the tutor on exit
40trap "rm -rf $TODELETE" 0 1 2 3 9 11 13 15
41
42# Vim could be called "vim" or "vi". Also check for "vim6", for people who
43# have Vim 5.x installed as "vim" and Vim 6.0 as "vim6".
44testvim=`which vim6 2>/dev/null`
45if test -f "$testvim"; then
46 VIM=vim6
47else
48 testvim=`which vim`
49 if test -f "$testvim"; then
50 VIM=vim
51 else
52 VIM=vi
53 fi
54fi
55
56# Use Vim to copy the tutor, it knows the value of $VIMRUNTIME
57# The script tutor.vim tells Vim which file to copy
58$VIM -u NONE -c 'so $VIMRUNTIME/tutor/tutor.vim'
59
60# Start vim without any .vimrc, set 'nocompatible'
61$VIM -u NONE -c "set nocp" $TUTORCOPY