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 | nofork= |
---|
24 | |
---|
25 | # GUI mode, implies forking |
---|
26 | case "$name" in g*|rg*) gui=true ;; esac |
---|
27 | |
---|
28 | # Restricted mode |
---|
29 | case "$name" in r*) opts="$opts -Z";; esac |
---|
30 | |
---|
31 | # vimdiff and view |
---|
32 | case "$name" in |
---|
33 | *vimdiff) |
---|
34 | opts="$opts -dO" |
---|
35 | ;; |
---|
36 | *view) |
---|
37 | opts="$opts -R" |
---|
38 | ;; |
---|
39 | esac |
---|
40 | |
---|
41 | # Should we fork? |
---|
42 | for arg in $@; do |
---|
43 | if [ "$arg" == "-f" ]; then |
---|
44 | nofork=true |
---|
45 | fi |
---|
46 | done |
---|
47 | |
---|
48 | # Last step: fire up vim. |
---|
49 | # GUI mode will always create a new Vim instance, because Vim can't have |
---|
50 | # more than one graphic window yet. |
---|
51 | # The program should fork by default when started in GUI mode, but it does |
---|
52 | # not; we work around this when this script is invoked as "gvim" or "rgview" |
---|
53 | # etc., but not when it is invoked as "vim -g". |
---|
54 | if [ "$gui" ]; then |
---|
55 | # Note: this isn't perfect, because any error output goes to the |
---|
56 | # terminal instead of the console log. |
---|
57 | # But if you use open instead, you will need to fully qualify the |
---|
58 | # path names for any filenames you specify, which is hard. |
---|
59 | if [[ "$1" == "-" ]]; then |
---|
60 | if [ "$nofork" ]; then |
---|
61 | cat | exec "$binary" -g $opts ${1:+"$@"} |
---|
62 | else |
---|
63 | cat | exec "$binary" -g $opts ${1:+"$@"} & |
---|
64 | fi |
---|
65 | else |
---|
66 | if [ "$nofork" ]; then |
---|
67 | exec "$binary" -g $opts ${1:+"$@"} |
---|
68 | else |
---|
69 | exec "$binary" -g $opts ${1:+"$@"} & |
---|
70 | fi |
---|
71 | fi |
---|
72 | else |
---|
73 | exec "$binary" $opts ${1:+"$@"} |
---|
74 | fi |
---|