From 581dea70d15483b56e174d8debd13a5af701692e Mon Sep 17 00:00:00 2001 From: "martin f. krafft" Date: Fri, 14 Jun 2013 10:31:01 +0200 Subject: [PATCH] Generalise determination of hacking directory path Bash needs a special case to determine the dirname of the sourced path (the hacking dir), but in all other cases, using $0 allows the script to be sourced also from within the hacking directory, not only from its parent. Signed-off-by: martin f. krafft --- hacking/env-setup | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/hacking/env-setup b/hacking/env-setup index 338e768686..8eb45370ab 100755 --- a/hacking/env-setup +++ b/hacking/env-setup @@ -3,11 +3,12 @@ # modifies environment for running Ansible from checkout # When run using source as directed, $0 gets set to bash, so we must use $BASH_SOURCE -if [ -n "$BASH_SOURCE" ] ; then - HACKING_DIR=`dirname $BASH_SOURCE` -else - HACKING_DIR="$PWD/hacking" -fi +case "$0" in + (bash) + HACKING_DIR=${BASH_SOURCE%/*};; + (*) + HACKING_DIR=${0%/*};; +esac # The below is an alternative to readlink -fn which doesn't exist on OS X # Source: http://stackoverflow.com/a/1678636 FULL_PATH=`python -c "import os; print(os.path.realpath('$HACKING_DIR'))"`