Skip to content

Instantly share code, notes, and snippets.

@simonmichael
Last active August 11, 2021 16:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simonmichael/b41e435a4c9f3c36b31fde10e7cbe817 to your computer and use it in GitHub Desktop.
Save simonmichael/b41e435a4c9f3c36b31fde10e7cbe817 to your computer and use it in GitHub Desktop.
elaborate cron/make rules for periodically, automatically, cleanly git-committing (hledger) files, with logs for troubleshooting
# autocommit financial files
# once a night, at 04:02
02 04 * * * make -C/Users/simon/finance -s autocommit
# or check every minute, doing nothing if files are unchanged
#* * * * * cd /Users/simon/finance; git diff --quiet || make -s autocommit
# Perform any auto-commits that are due, in the proper order.
autocommit: \
autocommit-time \
autocommit-txns \
autocommit-misc
# Auto-commit any timelog changes.
autocommit-time:
@echo `date` $@ >>$@.log
@( git commit -qm 'time (auto)' $(TIMEDOT) | grep -E '(^\[|file changed)' ) >>$@.log \
|| true
# Auto-commit any transaction journal changes.
autocommit-txns:
@echo `date` $@ >>$@.log
@( git commit -qm 'txns (auto)' $(JOURNAL) | grep -E '(^\[|file changed)' ) >>$@.log \
|| true
# Auto-commit any remaining dirty files if nothing much has changed in the last hour
# (excluding journal, timelog, log files, git files..)
# Run this after the more specific autocommits above.
autocommit-misc:
@echo `date` $@ >>$@.log
@[[ -z $$(find . -newermt '60 minutes ago' \! -regex '\./\.git.*' \! -name "*.log" \! -name $(TIMEDOT) \! -name $(JOURNAL) ) ]] \
&& ( git commit -am '(auto)' | grep -E '(^\[|file changed)' ) >>autocommit.log \
|| true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment