scripts: update autosave and dep scripts

This commit is contained in:
thomasabishop 2024-02-26 19:06:05 +00:00
parent 7a4445dd9d
commit 09bc835b90
2 changed files with 14 additions and 16 deletions

View file

@ -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")"

View file

@ -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