Skip to content

Commit 3417d48

Browse files
committed
Add mvim script for MacVim.app/Contents/bin/mvim
1 parent a5ebfbc commit 3417d48

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed

src/MacVim/mvim.sh

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#!/bin/sh
2+
#
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.
7+
#
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+
#
12+
13+
# Find Vim executable
14+
if [ -L $0 ]; then
15+
# readlink -f
16+
curdir=`pwd -P`
17+
self_path=$0
18+
cd `dirname $self_path`
19+
while [ -L $self_path ]; do
20+
self_path=`readlink $self_path`
21+
cd `dirname $self_path`
22+
self_path=`basename $self_path`
23+
done
24+
binary="`pwd -P`/../MacOS/Vim"
25+
cd $curdir
26+
else
27+
binary="`dirname "$0"`/../MacOS/Vim"
28+
fi
29+
if ! [ -x $binary ]; then
30+
echo "Sorry, cannot find Vim executable."
31+
exit 1
32+
fi
33+
34+
# Next, peek at the name used to invoke this script, and set options
35+
# accordingly.
36+
37+
name="`basename "$0"`"
38+
gui=
39+
opts=
40+
41+
# GUI mode, implies forking
42+
case "$name" in m*|g*|rm*|rg*) gui=true ;; esac
43+
44+
# Logged in over SSH? No gui.
45+
if [ -n "${SSH_CONNECTION}" ]; then
46+
gui=
47+
fi
48+
49+
# Restricted mode
50+
case "$name" in r*) opts="$opts -Z";; esac
51+
52+
# vimdiff, view, and ex mode
53+
case "$name" in
54+
*vimdiff)
55+
opts="$opts -dO"
56+
;;
57+
*view)
58+
opts="$opts -R"
59+
;;
60+
*ex)
61+
opts="$opts -e"
62+
;;
63+
esac
64+
65+
# Last step: fire up vim.
66+
# The program should fork by default when started in GUI mode, but it does
67+
# not; we work around this when this script is invoked as "gvim" or "rgview"
68+
# etc., but not when it is invoked as "vim -g".
69+
if [ "$gui" ]; then
70+
# Note: this isn't perfect, because any error output goes to the
71+
# terminal instead of the console log.
72+
# But if you use open instead, you will need to fully qualify the
73+
# path names for any filenames you specify, which is hard.
74+
exec "$binary" -g $opts ${1:+"$@"}
75+
else
76+
exec "$binary" $opts ${1:+"$@"}
77+
fi

0 commit comments

Comments
 (0)