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.
This commit is contained in:
Ingo Karkat
2012-01-13 23:46:08 +01:00
parent 67e0d9dd98
commit b7ffb96695
2 changed files with 18 additions and 17 deletions

View File

@@ -85,10 +85,12 @@ TODO: $HOME/todo.txt archived.
TODO: 5 of 5 tasks shown TODO: 5 of 5 tasks shown
>>> todo.sh report >>> todo.sh report
TODO: $HOME/todo.txt archived.
TODO: Report file updated. TODO: Report file updated.
2009-02-13-04:40:00 5 1 2009-02-13-04:40:00 5 1
>>> todo.sh report >>> todo.sh report
TODO: $HOME/todo.txt archived.
TODO: Report file updated. TODO: Report file updated.
2009-02-13-04:40:00 5 1 2009-02-13-04:40:00 5 1
2009-02-13-04:40:00 5 1 2009-02-13-04:40:00 5 1

31
todo.sh
View File

@@ -357,18 +357,6 @@ getNewtodo()
[ -z "$newtodo" ] && die "$(getPrefix "$2"): No updated task $item." [ -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() replaceOrPrepend()
{ {
action=$1; shift action=$1; shift
@@ -935,7 +923,15 @@ case $action in
;; ;;
"archive" ) "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" ) "del" | "rm" )
# replace deleted line with a blank line when TODOTXT_PRESERVE_LINE_NUMBERS is 1 # replace deleted line with a blank line when TODOTXT_PRESERVE_LINE_NUMBERS is 1
@@ -1037,7 +1033,9 @@ case $action in
done done
if [ $TODOTXT_AUTO_ARCHIVE = 1 ]; then if [ $TODOTXT_AUTO_ARCHIVE = 1 ]; then
archive # Recursively invoke the script to allow overriding of the archive
# action.
"$TODO_FULL_SH" archive
fi fi
;; ;;
@@ -1190,8 +1188,9 @@ note: PRIORITY must be anywhere from A to Z."
"report" ) "report" )
# archive first # archive first
sed '/^x /!d' "$TODO_FILE" >> "$DONE_FILE" # Recursively invoke the script to allow overriding of the archive
sed -i.bak '/^x /d' "$TODO_FILE" # action.
"$TODO_FULL_SH" archive
NUMLINES=$( sed -n '$ =' "$TODO_FILE" ) NUMLINES=$( sed -n '$ =' "$TODO_FILE" )
if [ ${NUMLINES:-0} = "0" ]; then if [ ${NUMLINES:-0} = "0" ]; then