From 7e525ee7438d254526add0ae62d04225259b9b55 Mon Sep 17 00:00:00 2001 From: Ingo Karkat Date: Sat, 14 Jan 2012 15:21:53 +0100 Subject: [PATCH] ENH: Only add new data to report. When the last reported values are identical to the current values, do not append the same information (just with a new timestamp) to the report. Instead, just print the last report line. With this, the report action can be scheduled periodically (e.g. via cron) without artificially inflating the report file. --- todo.sh | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/todo.sh b/todo.sh index 6c34003..10b1246 100755 --- a/todo.sh +++ b/todo.sh @@ -1222,9 +1222,18 @@ note: PRIORITY must be anywhere from A to Z." TOTAL=$( sed -n '$ =' "$TODO_FILE" ) TDONE=$( sed -n '$ =' "$DONE_FILE" ) - echo "$(date +%Y-%m-%dT%T) ${TOTAL:-0} ${TDONE:-0}" >> "$REPORT_FILE" - sed -ne '$p' "$REPORT_FILE" - [ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: Report file updated." + NEWDATA="${TOTAL:-0} ${TDONE:-0}" + LASTREPORT=$(sed -ne '$p' "$REPORT_FILE") + LASTDATA=${LASTREPORT#* } # Strip timestamp. + if [ "$LASTDATA" = "$NEWDATA" ]; then + echo "$LASTREPORT" + [ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: Report file is up-to-date." + else + NEWREPORT="$(date +%Y-%m-%dT%T) ${NEWDATA}" + echo "${NEWREPORT}" >> "$REPORT_FILE" + echo "${NEWREPORT}" + [ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: Report file updated." + fi ;; "deduplicate" )