Ticket #14620: gvim

File gvim, 1.7 KB (added by itsme@…, 17 years ago)

gvim wrapper script with stdin support

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=
23
24# GUI mode, implies forking
25case "$name" in g*|rg*) gui=true ;; esac
26
27# Restricted mode
28case "$name" in r*) opts="$opts -Z";; esac
29
30# vimdiff and view
31case "$name" in
32        *vimdiff)
33                opts="$opts -dO"
34                ;;
35        *view)
36                opts="$opts -R"
37                ;;
38esac
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".
46if [ "$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.
51if [[ "$1" == "-" ]]; then
52        cat | exec "$binary" -g $opts ${1:+"$@"} &
53else
54        exec "$binary" -g $opts ${1:+"$@"} &
55fi
56else
57        exec "$binary" $opts ${1:+"$@"}
58fi