diff --git a/bin/autogit b/bin/autogit new file mode 100755 index 0000000..c4f23ff --- /dev/null +++ b/bin/autogit @@ -0,0 +1,21 @@ +#!/bin/sh + +### Add org file changes to git repo + +for REPO in $1 +do + echo "repository: $REPO" + eval "cd $REPO" + # check for errors + if ! git fsck --strict > /dev/null 2>&1; then + notify-send "Org git commit failed." + fi + # remove deleted files + git ls-files --deleted -z | xargs -0 git rm >/dev/null 2>&1 + # add new files + git add . >/dev/null 2>&1 + git commit -m "$(date)" + # push + git push origin master +done +echo Done diff --git a/etc/conf.org b/etc/conf.org index 6a19522..a7480a5 100644 --- a/etc/conf.org +++ b/etc/conf.org @@ -341,6 +341,17 @@ If FRONT is t, do to the front of current values instead of the back." (--each (where-is-internal f keymap nil nil) (define-key keymap it nil))) + + +(defun nd/run-at-hour-minute (hh mm rep cmd &rest args) + "Run CMD starting at next integral HH and MM repeating every REP seconds. + +For example, to run every hour at 45 minutes HH would be 1 and MM would be 45." + (let* ((m (* mm 60)) + (h (* hh 3600)) + (now (float-time)) + (next (- (+ m (* h (ceiling (/ (- now m) h)))) now))) + (apply #'run-at-time next rep cmd args))) #+END_SRC ** interactive #+BEGIN_SRC emacs-lisp @@ -1719,14 +1730,21 @@ Additionally, using specialized file variables makes it much easier and faster t (org-x-get-reference-files :maxlevel . 9))) #+END_SRC *** autosave -Save all org buffers 1 minute before the hour. +Save all org buffers 1 minute before the hour, then commit whatever I saved. #+BEGIN_SRC emacs-lisp (defun nd/org-save-all-org-buffers () "Save org buffers without confirmation or message (unlike default)." (save-some-buffers t (lambda () (derived-mode-p 'org-mode))) (when (featurep 'org-id) (org-id-locations-save))) -(run-at-time "00:59" 3600 #'nd/org-save-all-org-buffers) +(defun nd/org-commit-repos () + "Commit org git repos automatically" + (let* ((journal-path (f-join org-directory "journal")) + (cmd (format "autogit \"%s\" \"%s\"" org-directory journal-path))) + (async-shell-command cmd))) + +(nd/run-at-hour-minute 1 59 3600 #'nd/org-save-all-org-buffers) +(nd/run-at-hour-minute 1 0 3600 #'nd/org-commit-repos) #+END_SRC *** stateless configuration =org-ml= provides stateless functions for operating on org buffers.