aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/caldav
diff options
context:
space:
mode:
authorNitroretro <nitroretro@protonmail.com>2019-12-19 22:42:54 +0200
committerLukas Fleischer <lfleischer@calcurse.org>2019-12-23 13:16:39 -0500
commit992cf45dc92b6aba36b47b496dbb0dc443aa200f (patch)
tree98b2c499618254e4e3094b5cc673a002b24bcfe5 /contrib/caldav
parent023ca554936148e2b5a71f93ce7b849fba98182e (diff)
downloadcalcurse-992cf45dc92b6aba36b47b496dbb0dc443aa200f.tar.gz
calcurse-992cf45dc92b6aba36b47b496dbb0dc443aa200f.zip
Use $XDG_{CONFIG,DATA}_HOME in hooks
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
Diffstat (limited to 'contrib/caldav')
-rwxr-xr-xcontrib/caldav/hooks/post-sync30
1 files changed, 23 insertions, 7 deletions
diff --git a/contrib/caldav/hooks/post-sync b/contrib/caldav/hooks/post-sync
index 372d260..62ebe11 100755
--- a/contrib/caldav/hooks/post-sync
+++ b/contrib/caldav/hooks/post-sync
@@ -8,12 +8,28 @@
# $XDG_CONFIG_HOME/calcurse/caldav/hooks/ (~/.config/calcurse/caldav/hooks/) or
# ~/.calcurse/caldav/hooks/ if using ~/.calcurse.
-cd "$HOME"/.calcurse/
+data_dir="$HOME/.calcurse"
+config_dir="$HOME/.calcurse"
-# 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-sync hook"
- fi
+if [ ! -d "$data_dir" ]; then
+ data_dir="${XDG_DATA_HOME:-$HOME/.local/share}/calcurse"
+ config_dir="${XDG_CONFIG_HOME:-$HOME/.config}/calcurse"
fi
+
+# Do not do anything when synchronizing with a CalDAV server.
+[ -f "$data_dir/caldav/lock" ] && exit
+
+# If the directory is under version control, create a Git commit.
+commit_dir() {
+ cd "$1" >/dev/null 2>&1 || return
+ shift
+ if [ -d .git ] && command -v git >/dev/null; then
+ git add "$@"
+ if ! git diff-index --quiet --cached HEAD; then
+ git commit -m "Automatic commit by the post-save hook"
+ fi
+ fi
+}
+
+commit_dir "$data_dir" apts todo
+commit_dir "$config_dir" conf keys