Ticket #16537: gvim

File gvim, 2.1 KB (added by miki@…, 16 years ago)

Fix for honoring "-f" switch (no fork)

Line 
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
15binary="/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
20name="`basename "$0"`"
21gui=
22opts=
23nofork=
24
25# GUI mode, implies forking
26case "$name" in g*|rg*) gui=true ;; esac
27
28# Restricted mode
29case "$name" in r*) opts="$opts -Z";; esac
30
31# vimdiff and view
32case "$name" in
33        *vimdiff)
34                opts="$opts -dO"
35                ;;
36        *view)
37                opts="$opts -R"
38                ;;
39esac
40
41# Should we fork?
42for arg in $@; do
43    if [ "$arg" == "-f" ]; then
44        nofork=true
45    fi
46done
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".
54if [ "$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
72else
73        exec "$binary" $opts ${1:+"$@"}
74fi