eolas/_scripts/auto_save.sh

30 lines
851 B
Bash
Raw Normal View History

2022-12-07 07:30:05 +00:00
#!/bin/bash
2023-01-21 12:18:17 +00:00
# This script automatically commits/pull changes to the remote repository with a generic commit message.
2022-12-07 07:30:05 +00:00
2023-01-21 12:18:17 +00:00
# It is aliased to `cs-update` in .zshrc
NOTES_PATH="/home/thomas/repos/computer_science"
SPACE_TO_UNDERSCORE="/home/thomas/repos/computer_science/_scripts/space_to_underscore_filename.sh"
CLEAN_IMAGE_DIRECTORY="/home/thomas/repos/computer_science/_scripts/clean_image_directory.sh"
2022-12-07 07:30:05 +00:00
cd "$NOTES_PATH"
# Loop through directories and convert spaces in filenames to underscores
2022-12-10 12:00:05 +00:00
source ${SPACE_TO_UNDERSCORE}
2023-01-21 13:06:01 +00:00
source ${CLEAN_IMAGE_DIRECTORY}
2022-12-07 07:30:05 +00:00
git pull
2023-01-21 13:07:01 +00:00
2023-01-21 13:07:56 +00:00
CHANGES_EXIST="$(git status --porcelain | wc -l)"
2022-12-07 07:30:05 +00:00
# If no changes, exit. Else commit and push with timestamp
if [ "$CHANGES_EXIST" -eq 0 ]; then
exit 0
fi
2023-01-21 13:50:01 +00:00
git pull | grep -v "Already up to date."
2022-12-07 07:30:05 +00:00
git add .
2022-12-09 08:30:05 +00:00
git commit -q -m "Autosave: $(date +"%Y-%m-%d %H:%M:%S")"
2023-01-21 13:48:23 +00:00
git push -q