summaryrefslogtreecommitdiff
path: root/.config/calcurse/hooks/post-save
diff options
context:
space:
mode:
Diffstat (limited to '.config/calcurse/hooks/post-save')
-rwxr-xr-x.config/calcurse/hooks/post-save47
1 files changed, 47 insertions, 0 deletions
diff --git a/.config/calcurse/hooks/post-save b/.config/calcurse/hooks/post-save
new file mode 100755
index 0000000..8836316
--- /dev/null
+++ b/.config/calcurse/hooks/post-save
@@ -0,0 +1,47 @@
1#!/bin/sh
2#
3# This is an example hook. It does two things whenever you save the data files:
4#
5# 1. Make a commit if the calcurse directories contain a Git repository.
6# 2. Synchronize with a CalDAV server if calcurse-caldav is configured.
7#
8# In order to install this hook, copy this file to
9# $XDG_CONFIG_HOME/calcurse/hooks/ (~/.config/calcurse/hooks/) or
10# ~/.calcurse/hooks/ if using ~/.calcurse.
11
12data_dir="$HOME/.calcurse"
13config_dir="$HOME/.calcurse"
14
15if [ ! -d "$data_dir" ]; then
16 data_dir="${XDG_DATA_HOME:-$HOME/.local/share}/calcurse"
17 config_dir="${XDG_CONFIG_HOME:-$HOME/.config}/calcurse"
18fi
19
20# Do not do anything when synchronizing with a CalDAV server.
21[ -f "$data_dir/caldav/lock" ] && exit
22
23# If the directory is under version control, create a Git commit.
24commit_dir() {
25 cd "$1" >/dev/null 2>&1 || return
26 shift
27 if [ -d .git ] && command -v git >/dev/null; then
28 git add "$@"
29 if ! git diff-index --quiet --cached HEAD; then
30 git commit -m "Automatic commit by the post-save hook"
31 fi
32 fi
33}
34
35commit_dir "$data_dir" apts todo
36commit_dir "$config_dir" conf keys
37
38# Optionally run the CalDAV synchronization script in the background.
39cd "$data_dir" || exit
40if [ -d caldav ] && command -v calcurse-caldav >/dev/null; then
41 (
42 date="$(date +'%b %d %H:%M:%S')"
43 echo "$date Running calcurse-caldav from the post-save hook..."
44 CALCURSE_CALDAV_PASSWORD=$(pass show web/radicale.chudnick.com | head -1) calcurse-caldav
45 echo
46 ) >>caldav/log 2>&1 &
47fi