Added scripts

This commit is contained in:
Daniel Fichtinger 2024-11-10 02:53:06 -05:00
parent 52fa79bd8d
commit 8ea9f8f1e9
3 changed files with 112 additions and 0 deletions

37
yadmadd.sh Executable file
View file

@ -0,0 +1,37 @@
#!/bin/bash
# This script takes file or directories as
# arguments and appends them to the "tracked"
# file, for use by autoyadm.sh
YADMDIR="$HOME/.config/yadm"
AYE="AutoYADM Error:"
AYM="AutoYADM:"
# We check if any arguments have been provided
if [ $# -eq 0 ]; then
echo "$AYE $0 <file_or_directory> [<file_or_directory> ...]"
exit 1
fi
# We loop through arguments
for arg in "$@"; do
# check if current arg is a real path
if [ ! -e "$arg" ]; then
echo "$AYE '$arg' is not a valid path."
continue
fi
# get its absolute path
abs=$(realpath "$arg")
# check if it's inside home dir
if [[ "$abs" == "$HOME"* ]]; then
# convert to path relative to ~
rel=${abs#"$HOME/"}
# append to tracked file
echo "$HOME/$rel" >>"$YADMDIR/tracked"
echo "$AYM Tracking $HOME/$rel"
else
echo "$AYM Path must be inside the home directory."
exit 1
fi
done