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.
This commit is contained in:
Ingo Karkat
2012-01-14 15:21:53 +01:00
parent d46adadb1d
commit 7e525ee743

15
todo.sh
View File

@@ -1222,9 +1222,18 @@ note: PRIORITY must be anywhere from A to Z."
TOTAL=$( sed -n '$ =' "$TODO_FILE" ) TOTAL=$( sed -n '$ =' "$TODO_FILE" )
TDONE=$( sed -n '$ =' "$DONE_FILE" ) TDONE=$( sed -n '$ =' "$DONE_FILE" )
echo "$(date +%Y-%m-%dT%T) ${TOTAL:-0} ${TDONE:-0}" >> "$REPORT_FILE" NEWDATA="${TOTAL:-0} ${TDONE:-0}"
sed -ne '$p' "$REPORT_FILE" LASTREPORT=$(sed -ne '$p' "$REPORT_FILE")
[ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: Report file updated." 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" ) "deduplicate" )