]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Resolve arc location through symlinks-of-symlinks, etc
authorepriestley <git@epriestley.com>
Thu, 22 Mar 2012 01:04:35 +0000 (18:04 -0700)
committerepriestley <git@epriestley.com>
Thu, 22 Mar 2012 01:04:35 +0000 (18:04 -0700)
Summary:
Stole this from stackoverflow; seems to work?

http://stackoverflow.com/questions/59895/can-a-bash-script-tell-what-directory-its-stored-in

Test Plan: Ran a symlink to bin/arc.

Reviewers: btrahan, zeeg

Reviewed By: btrahan

CC: aran, epriestley
Maniphest Tasks: T124

Differential Revision: https://secure.phabricator.com/D1968

bin/arc

diff --git a/bin/arc b/bin/arc
index bf49fa398215a095ee5e667b747b2240cc78b7a9..8ca8af85cdb66860f9794731b498b400b9884424 100755 (executable)
--- a/bin/arc
+++ b/bin/arc
@@ -1,7 +1,15 @@
-#!/bin/sh
+#!/bin/bash
 
 # NOTE: This file is a wrapper script instead of a symlink so it will work in
 # the Git Bash environment in Windows.
 
-exec `dirname $0`/../scripts/arcanist.php $@
+# Do bash magic to resolve the real location of this script through aliases,
+# symlinks, etc.
+SOURCE="${BASH_SOURCE[0]}";
+while [ -h "$SOURCE" ]; do
+  SOURCE="$(readlink "$SOURCE")";
+done;
+DIR="$(cd -P "$(dirname "$SOURCE")" && pwd)"
+
+exec $DIR/../scripts/arcanist.php $@