aboutsummaryrefslogtreecommitdiff
path: root/dotfiles/.config/calcurse/hooks/post-save
diff options
context:
space:
mode:
Diffstat (limited to 'dotfiles/.config/calcurse/hooks/post-save')
-rwxr-xr-xdotfiles/.config/calcurse/hooks/post-save34
1 files changed, 34 insertions, 0 deletions
diff --git a/dotfiles/.config/calcurse/hooks/post-save b/dotfiles/.config/calcurse/hooks/post-save
new file mode 100755
index 0000000..d797649
--- /dev/null
+++ b/dotfiles/.config/calcurse/hooks/post-save
@@ -0,0 +1,34 @@
+#!/bin/sh
+
+data_dir="$HOME/.calcurse"
+config_dir="$HOME/.calcurse"
+
+if [ ! -d "$data_dir" ]; then
+ data_dir="${XDG_DATA_HOME:-$HOME/.local/share}/calcurse"
+ config_dir="${XDG_CONFIG_HOME:-$HOME/.config}/calcurse"
+fi
+
+cd "$data_dir" || exit
+
+# Do not do anything when synchronizing with a CalDAV server.
+[ -f caldav/lock ] && exit
+
+# Run the CalDAV synchronization script.
+if [ -d caldav ] && command -v calcurse-caldav >/dev/null; then
+ (
+ date="$(date +'%b %d %H:%M:%S')"
+ notify-send "📅 Calcurse" "Saving and syncing with caldav server..."
+ echo "$date Running calcurse-caldav from the post-save hook..."
+ timeout 60 calcurse-caldav
+ rc=$?
+ if [ $rc -eq 124 ]; then
+ notify-send "📅 Calcurse" "❌ Syncing timed out"
+ elif [ $rc -gt 0 ]; then
+ notify-send "📅 Calcurse" "❌ Syncing failed (see logs)"
+ else
+ notify-send "📅 Calcurse" "Calendar saved and synced"
+ fi
+ echo
+ rm caldav/lock
+ ) >>caldav/log 2>&1
+fi