diff options
author | Lukas Fleischer <lfleischer@calcurse.org> | 2016-02-08 08:01:06 +0100 |
---|---|---|
committer | Lukas Fleischer <lfleischer@calcurse.org> | 2016-02-08 08:17:49 +0100 |
commit | 4ab6e75aa906ebf85cf68b5f23be003a7dae9c7a (patch) | |
tree | a316ccbce61e46b7e87860f27651dbf7822e6764 /contrib/hooks/post-save | |
parent | 616c3759a5f28f3f6229af6d5d7ea0f302cbb17c (diff) | |
download | calcurse-4ab6e75aa906ebf85cf68b5f23be003a7dae9c7a.zip |
Improve example hooks
The post-save and post-sync hooks now automatically detect whether the
data directory contains a .git/ directory and skip the commit creation
process if it does not.
The post-save hook and the new pre-load hook now also run
calcurse-caldav in the background if that script is available and the
data directory contains a caldav/ directory.
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
Diffstat (limited to 'contrib/hooks/post-save')
-rwxr-xr-x | contrib/hooks/post-save | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/contrib/hooks/post-save b/contrib/hooks/post-save index 574a721..bb582e2 100755 --- a/contrib/hooks/post-save +++ b/contrib/hooks/post-save @@ -1,14 +1,31 @@ #!/bin/sh # -# Copy this file into ~/.calcurse/hooks/ and mark it executable to -# automatically commit any changes to the calcurse data files using Git. +# This is an example hook. It does two things whenever you save the data files: +# +# 1. Make a commit if the calcurse data directory contains a Git repository. +# 2. Synchronize with a CalDAV server if calcurse-caldav is configured. +# +# In order to install this hook, copy this file to ~/.calcurse/hooks/. cd "$HOME"/.calcurse/ -# Do not make commits when synchronizing with a CalDAV server. +# Do not do anything when synchronizing with a CalDAV server. [ -f caldav/lock ] && exit -git add apts conf keys todo -if ! git diff-index --quiet --cached HEAD; then - git commit -m "Automatic commit by the post-save hook" +# If the data directory is under version control, create a Git commit. +if [ -d .git -a -x "$(which git)" ]; then + git add apts conf keys todo + if ! git diff-index --quiet --cached HEAD; then + git commit -m "Automatic commit by the post-save hook" + fi +fi + +# Optionally run the CalDAV synchronization script in the background. +if [ -d caldav -a -x "$(which calcurse-caldav)" ]; then + ( + date="$(date +'%b %d %H:%M:%S')" + echo "$date Running calcurse-caldav from the post-save hook..." + calcurse-caldav + echo + ) >>caldav/log 2>&1 & fi |