Skip to content

Commit dc708f3

Browse files
committed
Emulate "readlink -f" to get real $0
1 parent f0377b8 commit dc708f3

File tree

1 file changed

+17
-29
lines changed

1 file changed

+17
-29
lines changed

src/MacVim/mvim

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,40 +8,28 @@
88
# Based on a script by Wout Mertens and suggestions from Laurent Bihanic. This
99
# version is the fault of Benji Fisher, 16 May 2005 (with modifications by Nico
1010
# Weber and Bjorn Winckler, Aug 13 2007).
11-
# First, check "All the Usual Suspects" for the location of the Vim.app bundle.
12-
# You can short-circuit this by setting the VIM_APP_DIR environment variable
13-
# or by un-commenting and editing the following line:
14-
# VIM_APP_DIR=/Applications
11+
#
1512

16-
if [ -z "$VIM_APP_DIR" ]
17-
then
18-
myDir="`dirname "$0"`"
19-
myAppDir="$myDir/../Applications"
20-
suspects=(
21-
/Applications
22-
~/Applications
23-
/Applications/vim
24-
~/Applications/vim
25-
$myDir
26-
$myDir/vim
27-
$myAppDir
28-
$myAppDir/vim
29-
/Applications/Utilities
30-
/Applications/Utilities/vim
31-
)
32-
for i in ${suspects[@]}; do
33-
if [ -x "$i/MacVim.app" ]; then
34-
VIM_APP_DIR="$i"
35-
break
36-
fi
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`
3723
done
24+
binary="`pwd -P`/../MacOS/Vim"
25+
cd $curdir
26+
else
27+
binary="`dirname "$0"`/../MacOS/Vim"
3828
fi
39-
if [ -z "$VIM_APP_DIR" ]
40-
then
41-
echo "Sorry, cannot find MacVim.app. Try setting the VIM_APP_DIR environment variable to the directory containing MacVim.app."
29+
if ! [ -x $binary ]; then
30+
echo "Sorry, cannot find Vim executable."
4231
exit 1
4332
fi
44-
binary="$VIM_APP_DIR/MacVim.app/Contents/MacOS/Vim"
4533

4634
# Next, peek at the name used to invoke this script, and set options
4735
# accordingly.

0 commit comments

Comments
 (0)