#!/bin/sh n=0 while IFS= read -r _; do n=$((n + 1)) done if [ "$n" -gt 0 ]; then { lockfile="$HOME/.task/sync_hook.lock" errfile="$HOME/.task/sync_hook.err" lerrfile="$HOME/.task/sync_hook.errl" logfile="$HOME/.task/sync_hook.log" flock "$lockfile" sh -c ' task sync >>"$1" 2>"$2" status=$? if [ "$status" -ne 0 ]; then echo "Taskwarrior sync failed at $(date)" >>"$2" if command -v sendmail >/dev/null 2>&1; then { echo "To: daniel@ficd.ca" echo "From: daniel@ficd.ca" echo "Subject: Taskwarrior Sync Failed on $(hostname)" echo "Date: $(date -R)" echo "" echo "task sync failed at $(date)" echo "" cat "$2" } | sendmail -t fi cat "$2" >>"$3" if command -v notify-send >/dev/null 2>&1; then notify-send --urgency=critical "taskwarrior sync failed" fi exit 1 fi ' sh "$logfile" "$lerrfile" "$errfile" "$(hostname)" } >/dev/null 2>&1