From 12ce8bdd65d3b5fcd6e8227eaecd5f772a90f8da Mon Sep 17 00:00:00 2001 From: Sam Chudnick Date: Sun, 11 Jun 2023 08:00:24 -0400 Subject: Configuration file updates and additions. --- .config/calcurse/hooks/post-save | 47 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100755 .config/calcurse/hooks/post-save (limited to '.config/calcurse/hooks/post-save') 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 @@ +#!/bin/sh +# +# This is an example hook. It does two things whenever you save the data files: +# +# 1. Make a commit if the calcurse directories contain a Git repository. +# 2. Synchronize with a CalDAV server if calcurse-caldav is configured. +# +# In order to install this hook, copy this file to +# $XDG_CONFIG_HOME/calcurse/hooks/ (~/.config/calcurse/hooks/) or +# ~/.calcurse/hooks/ if using ~/.calcurse. + +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 + +# 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 + +# Optionally run the CalDAV synchronization script in the background. +cd "$data_dir" || exit +if [ -d caldav ] && command -v calcurse-caldav >/dev/null; then + ( + date="$(date +'%b %d %H:%M:%S')" + echo "$date Running calcurse-caldav from the post-save hook..." + CALCURSE_CALDAV_PASSWORD=$(pass show web/radicale.chudnick.com | head -1) calcurse-caldav + echo + ) >>caldav/log 2>&1 & +fi -- cgit v1.2.3