From b7ffb9669505899ee2202b0023bd3dce2ff6670e Mon Sep 17 00:00:00 2001 From: Ingo Karkat Date: Fri, 13 Jan 2012 23:46:08 +0100 Subject: [PATCH] Pull archive() in-line and delegate via recursive call, also for report. The report action should delegate to archive; it previously (half) did this via duplicated code (and forgot to defragment empty lines, so the tally could be off, and kept silent about the archiving). The do action directly invoked archive(); if the user had extended / modified the archive action via an eponymous custom action, it would not run. Therefore, always invoke archive through another call of todo.sh, so that a possible custom action is considered. --- tests/t9999-testsuite_example.sh | 2 ++ todo.sh | 33 ++++++++++++++++---------------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/tests/t9999-testsuite_example.sh b/tests/t9999-testsuite_example.sh index 24df132..9989fa9 100755 --- a/tests/t9999-testsuite_example.sh +++ b/tests/t9999-testsuite_example.sh @@ -85,10 +85,12 @@ TODO: $HOME/todo.txt archived. TODO: 5 of 5 tasks shown >>> todo.sh report +TODO: $HOME/todo.txt archived. TODO: Report file updated. 2009-02-13-04:40:00 5 1 >>> todo.sh report +TODO: $HOME/todo.txt archived. TODO: Report file updated. 2009-02-13-04:40:00 5 1 2009-02-13-04:40:00 5 1 diff --git a/todo.sh b/todo.sh index 28dd2e3..20787ba 100755 --- a/todo.sh +++ b/todo.sh @@ -357,18 +357,6 @@ getNewtodo() [ -z "$newtodo" ] && die "$(getPrefix "$2"): No updated task $item." } -archive() -{ - #defragment blank lines - sed -i.bak -e '/./!d' "$TODO_FILE" - [ $TODOTXT_VERBOSE -gt 0 ] && grep "^x " "$TODO_FILE" - grep "^x " "$TODO_FILE" >> "$DONE_FILE" - sed -i.bak '/^x /d' "$TODO_FILE" - if [ $TODOTXT_VERBOSE -gt 0 ]; then - echo "TODO: $TODO_FILE archived." - fi -} - replaceOrPrepend() { action=$1; shift @@ -935,7 +923,15 @@ case $action in ;; "archive" ) - archive;; + # defragment blank lines + sed -i.bak -e '/./!d' "$TODO_FILE" + [ $TODOTXT_VERBOSE -gt 0 ] && grep "^x " "$TODO_FILE" + grep "^x " "$TODO_FILE" >> "$DONE_FILE" + sed -i.bak '/^x /d' "$TODO_FILE" + if [ $TODOTXT_VERBOSE -gt 0 ]; then + echo "TODO: $TODO_FILE archived." + fi + ;; "del" | "rm" ) # replace deleted line with a blank line when TODOTXT_PRESERVE_LINE_NUMBERS is 1 @@ -1037,7 +1033,9 @@ case $action in done if [ $TODOTXT_AUTO_ARCHIVE = 1 ]; then - archive + # Recursively invoke the script to allow overriding of the archive + # action. + "$TODO_FULL_SH" archive fi ;; @@ -1189,9 +1187,10 @@ note: PRIORITY must be anywhere from A to Z." ;; "report" ) - #archive first - sed '/^x /!d' "$TODO_FILE" >> "$DONE_FILE" - sed -i.bak '/^x /d' "$TODO_FILE" + # archive first + # Recursively invoke the script to allow overriding of the archive + # action. + "$TODO_FULL_SH" archive NUMLINES=$( sed -n '$ =' "$TODO_FILE" ) if [ ${NUMLINES:-0} = "0" ]; then