1 | #!/bin/sh |
---|
2 | # |
---|
3 | # This shell script passes all its arguments to the binary inside the Vim.app |
---|
4 | # application bundle. If you make links to this script as view, gvim, etc., |
---|
5 | # then it will peek at the name used to call it and set options appropriately. |
---|
6 | # |
---|
7 | # Based on a script by Wout Mertens and suggestions from Laurent Bihanic. |
---|
8 | # This version is the fault of Benji Fisher, 16 May 2005. |
---|
9 | |
---|
10 | # First, check "All the Usual Suspects" for the location of the Vim.app bundle. |
---|
11 | # You can short-circuit this by setting the VIM_APP_DIR environment variable |
---|
12 | # or by un-commenting and editing the following line: |
---|
13 | # VIM_APP_DIR=/Applications |
---|
14 | |
---|
15 | binary="/Applications/MacPorts/Vim.app/Contents/MacOS/Vim" |
---|
16 | |
---|
17 | # Next, peek at the name used to invoke this script, and set options |
---|
18 | # accordingly. |
---|
19 | |
---|
20 | name="`basename "$0"`" |
---|
21 | gui= |
---|
22 | opts= |
---|
23 | |
---|
24 | # GUI mode, implies forking |
---|
25 | case "$name" in g*|rg*) gui=true ;; esac |
---|
26 | |
---|
27 | # Restricted mode |
---|
28 | case "$name" in r*) opts="$opts -Z";; esac |
---|
29 | |
---|
30 | # vimdiff and view |
---|
31 | case "$name" in |
---|
32 | *vimdiff) |
---|
33 | opts="$opts -dO" |
---|
34 | ;; |
---|
35 | *view) |
---|
36 | opts="$opts -R" |
---|
37 | ;; |
---|
38 | esac |
---|
39 | |
---|
40 | # Last step: fire up vim. |
---|
41 | # GUI mode will always create a new Vim instance, because Vim can't have |
---|
42 | # more than one graphic window yet. |
---|
43 | # The program should fork by default when started in GUI mode, but it does |
---|
44 | # not; we work around this when this script is invoked as "gvim" or "rgview" |
---|
45 | # etc., but not when it is invoked as "vim -g". |
---|
46 | if [ "$gui" ]; then |
---|
47 | # Note: this isn't perfect, because any error output goes to the |
---|
48 | # terminal instead of the console log. |
---|
49 | # But if you use open instead, you will need to fully qualify the |
---|
50 | # path names for any filenames you specify, which is hard. |
---|
51 | if [[ "$1" == "-" ]]; then |
---|
52 | cat | exec "$binary" -g $opts ${1:+"$@"} & |
---|
53 | else |
---|
54 | exec "$binary" -g $opts ${1:+"$@"} & |
---|
55 | fi |
---|
56 | else |
---|
57 | exec "$binary" $opts ${1:+"$@"} |
---|
58 | fi |
---|