annotate src/vimtutor @ 30:bf9fabc0ae84 almost-works

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