From 81143eb7542d625c13cf01c0929d9644fa9378df Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Sat, 24 Feb 2018 14:31:48 -0300 Subject: Set dir and base names depending on the way the program was called --- infection | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/infection b/infection index e7d514e..fa364b0 100755 --- a/infection +++ b/infection @@ -5,8 +5,6 @@ # Parameters BASENAME="`basename $0`" -DIRNAME="$(cd `dirname $0` &> /dev/null && pwd)" -SHORTNAME="$(echo $DIRNAME | sed -e "s|$HOME/||")" EXCLUDES="--exclude=local --exclude=stowpkg/tree" DATE="`date +%Y%m%d%I%M%S`" BACKUPS="$HOME/.backups/$DATE" @@ -22,14 +20,23 @@ function infection_usage { # Initialize function infection_init { + # Set dir and base names depending on the way the program was called (symlink or direct) + if [ "$(cd `dirname $0` &> /dev/null && dirname `pwd`)" == "inception" ]; then + DIRNAME="$(cd `dirname $0/..` &> /dev/null && pwd)" + else + DIRNAME="$(cd `dirname $0` &> /dev/null && pwd)" + fi + + SHORTNAME="$(echo $DIRNAME | sed -e "s|$HOME/||")" + ( # Check if we were called correctly. Program should be called # from the toplevel repository symlink and not from it's own # repository - if [ ! -d "$DIRNAME/inception" ]; then - echo "Please call me using $DIRNAME/infection" - exit 1 - fi + #if [ ! -d "$DIRNAME/inception" ]; then + # echo "Please call me using $DIRNAME/infection" + # exit 1 + #fi # Check if repo is inside $HOME if [ "$DIRNAME" != "$HOME/$SHORTNAME" ]; then -- cgit v1.2.3