#!/bin/sh
# "todo loop"
# pesco 2018-2019, isc license

test -z "$TODO" && TODO=~/.todo
test -z "$DONE" && DONE=~/.log

t=0
while [ $t -eq 0 ] || sleep 1
do
	s=$(stat -f %m "$TODO") || exit 1

	if [ $s -gt $t ]
	then
		clear
		painlist "$@" < "$TODO"
	fi

	if [ -e "$DONE" ]
	then
		r=$(stat -f %m "$DONE")
		s=$(($r > $s ? $r : $s))
		if [ $s -gt $t ]
		then
			x=$(egrep '>[1-9](x[1-9])*<' "$DONE" | painlist -s "$@" |
			    sed -E -e 's/total(  )?/done	/')
			printf '\r\033[38;2;255;222;0m%s\033[m ' "$x" # gold
		fi
	fi

	t=$s
done
