Merge branch 'MacVim'
[MacVim/KaoriYa.git] / src / MacVim / mvim
blob653cf783ea3c468079e5ac91a8a0e9a60723476a
1 #!/bin/sh
3 # This shell script passes all its arguments to the binary inside the
4 # MacVim.app application bundle. If you make links to this script as view,
5 # gvim, etc., then it will peek at the name used to call it and set options
6 # appropriately.
8 # Based on a script by Wout Mertens and suggestions from Laurent Bihanic. This
9 # version is the fault of Benji Fisher, 16 May 2005 (with modifications by Nico
10 # Weber and Bjorn Winckler, Aug 13 2007).
11 # First, check "All the Usual Suspects" for the location of the Vim.app bundle.
12 # You can short-circuit this by setting the VIM_APP_DIR environment variable
13 # or by un-commenting and editing the following line:
14 # VIM_APP_DIR=/Applications
16 if [ -z "$VIM_APP_DIR" ]
17 then
18 myDir="`dirname "$0"`"
19 myAppDir="$myDir/../Applications"
20 for i in ~/Applications ~/Applications/vim $myDir $myDir/vim $myAppDir $myAppDir/vim /Applications /Applications/vim /Applications/Utilities /Applications/Utilities/vim; do
21 if [ -x "$i/MacVim.app" ]; then
22 VIM_APP_DIR="$i"
23 break
25 done
27 if [ -z "$VIM_APP_DIR" ]
28 then
29 echo "Sorry, cannot find MacVim.app. Try setting the VIM_APP_DIR environment variable to the directory containing MacVim.app."
30 exit 1
32 binary="$VIM_APP_DIR/MacVim.app/Contents/MacOS/Vim"
34 # Next, peek at the name used to invoke this script, and set options
35 # accordingly.
37 name="`basename "$0"`"
38 gui=
39 opts=
41 # GUI mode, implies forking
42 case "$name" in m*|g*|rm*|rg*) gui=true ;; esac
44 # Restricted mode
45 case "$name" in r*) opts="$opts -Z";; esac
47 # vimdiff, view, and ex mode
48 case "$name" in
49 *vimdiff)
50 opts="$opts -dO"
52 *view)
53 opts="$opts -R"
55 *ex)
56 opts="$opts -e"
58 esac
60 # Last step: fire up vim.
61 # The program should fork by default when started in GUI mode, but it does
62 # not; we work around this when this script is invoked as "gvim" or "rgview"
63 # etc., but not when it is invoked as "vim -g".
64 if [ "$gui" ]; then
65 # Note: this isn't perfect, because any error output goes to the
66 # terminal instead of the console log.
67 # But if you use open instead, you will need to fully qualify the
68 # path names for any filenames you specify, which is hard.
69 exec "$binary" -g $opts ${1:+"$@"}
70 else
71 exec "$binary" $opts ${1:+"$@"}