diff --git a/scripts/auto_save.sh b/scripts/auto_save.sh index ed560d1..1c34be6 100755 --- a/scripts/auto_save.sh +++ b/scripts/auto_save.sh @@ -1,26 +1,30 @@ #!/bin/bash -# Automatically commits/pull changes to the remote repository with a generic commit message. +# Automatically commits/pull changes to the remote ZK repository. -# ZK_PAT="/home/thomas/repos/eolas" -tidy_filenames="/home/thomas/repos/eolas/scripts/tidy_filenames.sh" -purge_images="/home/thomas/repos/eolas/scripts/purge_images.sh" +tidy_filenames="${EOLAS_PATH}/scripts/tidy_filenames.sh" +purge_images="${EOLAS_PATH}/scripts/purge_images.sh" cd $EOLAS_DIR +echo "Standardising file-names..." source ${tidy_filenames} + +echo "Removing unused images..." source ${purge_images} +echo "Checking for changes..." git pull >/dev/null 2>&1 changes_exist="$(git status --porcelain | wc -l)" # If no changes, exit. Else commit and push with timestamp if [ "$changes_exist" -eq 0 ]; then - echo "No changes" + echo "No changes, exiting" exit 0 fi +echo "Updating remote..." git pull >/dev/null 2>&1 git add . git commit -q -m "Autosave: $(date +"%Y-%m-%d %H:%M:%S")" diff --git a/scripts/purge_images.sh b/scripts/purge_images.sh index d9c122a..554666e 100755 --- a/scripts/purge_images.sh +++ b/scripts/purge_images.sh @@ -2,20 +2,14 @@ # If there are images in img/ that are not being used by the Zettelkasten, delete them -unused_images=false +# Loop through /img directory find "${EOLAS_PATH}/img" -type f | while read filename; do - # Search for the image in the markdown files in the EOLAS_DIR directory - search_result=$(rg "${filename##*/}" "${EOLAS_PATH}/zk" --type markdown) - - # If the image is not found in any file + # Check each .md file in ZK for image + search_result=$(rg "${filename##*/}" "${EOLAS_PATH}/zk" --type markdown) + # If the image is not found in any file, delete it if [ -z "$search_result" ]; then - unused_images=true echo "Deleted unused image: ${filename##*/}" - # rm $filename + rm $filename fi done -if [[ $unused_images == false ]]; then - echo "Nothing to purge: all images currently in use." -fi -