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 #!/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="${EOLAS_PATH}/scripts/tidy_filenames.sh"
tidy_filenames="/home/thomas/repos/eolas/scripts/tidy_filenames.sh" purge_images="${EOLAS_PATH}/scripts/purge_images.sh"
purge_images="/home/thomas/repos/eolas/scripts/purge_images.sh"
cd $EOLAS_DIR cd $EOLAS_DIR
echo "Standardising file-names..."
source ${tidy_filenames} source ${tidy_filenames}
echo "Removing unused images..."
source ${purge_images} source ${purge_images}
echo "Checking for changes..."
git pull >/dev/null 2>&1 git pull >/dev/null 2>&1
changes_exist="$(git status --porcelain | wc -l)" changes_exist="$(git status --porcelain | wc -l)"
# If no changes, exit. Else commit and push with timestamp # If no changes, exit. Else commit and push with timestamp
if [ "$changes_exist" -eq 0 ]; then if [ "$changes_exist" -eq 0 ]; then
echo "No changes" echo "No changes, exiting"
exit 0 exit 0
fi fi
echo "Updating remote..."
git pull >/dev/null 2>&1 git pull >/dev/null 2>&1
git add . git add .
git commit -q -m "Autosave: $(date +"%Y-%m-%d %H:%M:%S")" 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 # 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 find "${EOLAS_PATH}/img" -type f | while read filename; do
# Search for the image in the markdown files in the EOLAS_DIR directory # Check each .md file in ZK for image
search_result=$(rg "${filename##*/}" "${EOLAS_PATH}/zk" --type markdown) search_result=$(rg "${filename##*/}" "${EOLAS_PATH}/zk" --type markdown)
# If the image is not found in any file, delete it
# If the image is not found in any file
if [ -z "$search_result" ]; then if [ -z "$search_result" ]; then
unused_images=true
echo "Deleted unused image: ${filename##*/}" echo "Deleted unused image: ${filename##*/}"
# rm $filename rm $filename
fi fi
done done
if [[ $unused_images == false ]]; then
echo "Nothing to purge: all images currently in use."
fi