Last active
August 11, 2021 16:34
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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` $@ >>[email protected] | |
@( git commit -qm 'time (auto)' $(TIMEDOT) | grep -E '(^\[|file changed)' ) >>[email protected] \ | |
|| true | |
# Auto-commit any transaction journal changes. | |
autocommit-txns: | |
@echo `date` $@ >>[email protected] | |
@( git commit -qm 'txns (auto)' $(JOURNAL) | grep -E '(^\[|file changed)' ) >>[email protected] \ | |
|| 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` $@ >>[email protected] | |
@[[ -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