From 7656a53bdf5b61b6c5100811e43def3025be1ad5 Mon Sep 17 00:00:00 2001 From: Daniel Fichtinger Date: Sun, 10 Nov 2024 03:56:54 -0500 Subject: [PATCH] Update AUTOYADMDIR to account for any location of the scripts --- autoyadm.sh | 9 ++++++--- yadmadd.sh | 8 +++++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/autoyadm.sh b/autoyadm.sh index 730697c..42e4d0d 100755 --- a/autoyadm.sh +++ b/autoyadm.sh @@ -7,6 +7,9 @@ AYE="AutoYADM Error:" AYM="AutoYADM:" +# We get the absolute path to the script's parent directory. +AUTOYADMDIR="script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + # We check not to overwrite the user's env setting if [ -z "$VAR" ]; then AUTOYADMPUSH=0 @@ -19,8 +22,8 @@ if [ -z "$HOST" ]; then fi # First we read each path from "tracked" -(while read -r path; do - # we disable ignored warning for this subshell +(while read -r relpath; do + path="$HOME/$relpath" # Execute yadm add on each real file # if the path points to a directory # This ensures symlinks are not added @@ -34,7 +37,7 @@ fi echo "$AYE Target must be a directory or a file!" exit 1 fi -done) <"$HOME/.config/yadm/tracked" +done) <"$AUTOYADMDIR/tracked" # Define the location of the ssh-agent environment sshenv="$HOME/.ssh/environment-$HOST" diff --git a/yadmadd.sh b/yadmadd.sh index b5b85a2..50ab31e 100755 --- a/yadmadd.sh +++ b/yadmadd.sh @@ -4,7 +4,9 @@ # arguments and appends them to the "tracked" # file, for use by autoyadm.sh -YADMDIR="$HOME/.config/yadm" +# We get the absolute path to the script's parent directory. +AUTOYADMDIR="script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + AYE="AutoYADM Error:" AYM="AutoYADM:" @@ -28,8 +30,8 @@ for arg in "$@"; do # convert to path relative to ~ rel=${abs#"$HOME/"} # append to tracked file - echo "$HOME/$rel" >>"$YADMDIR/tracked" - echo "$AYM Tracking $HOME/$rel" + echo "$rel" >>"$AUTOYADMDIR/tracked" + echo "$AYM Tracking $HOME/$rel as '$rel'" else echo "$AYM Path must be inside the home directory." exit 1