#!/bin/zsh
# 10 0 * * *      ~/bin/when-cron.sh | sendmail -t

CACHEFILE=/tmp/$(id -un)-when
[ -e $CACHEFILE ] || touch $CACHEFILE
TEMPFILE=$(mktemp)

when --noheader --future=60 > $TEMPFILE

if ! diff $CACHEFILE $TEMPFILE >/dev/null ; then
	mv $TEMPFILE $CACHEFILE
	{
		echo "From: michael@xmw.de"
		echo "To: michael@xmw.de"
		echo "Subject: when calendar update"
		echo
		cat $CACHEFILE
	} | sendmail -t
else
	rm $TEMPFILE
fi
