From 91126e38aadf3d21440788d61e12034c5423e494 Mon Sep 17 00:00:00 2001 From: Paul Mansfield Date: Thu, 25 Jun 2009 00:14:00 +0100 Subject: [PATCH] Issue fix: Multiple do items Can now do multiple items in one go. Either comma seperated list or a whitespace seperated list --- tests/t1500-do.sh | 72 +++++++++++++++++++++++++++++++++++++++++++++++ todo.sh | 33 +++++++++++++--------- 2 files changed, 91 insertions(+), 14 deletions(-) create mode 100755 tests/t1500-do.sh diff --git a/tests/t1500-do.sh b/tests/t1500-do.sh new file mode 100755 index 0000000..c9b9a76 --- /dev/null +++ b/tests/t1500-do.sh @@ -0,0 +1,72 @@ +#!/bin/sh + +test_description='do functionality +' +. ./test-lib.sh + +#DATE=`date '+%Y-%m-%d'` + +test_todo_session 'do usage' <>> todo.sh do B B +usage: todo.sh do ITEM# +=== 1 +EOF + +cat > todo.txt <>> todo.sh list +2 notice the sunflowers +4 remove1 +5 remove2 +6 remove3 +7 remove4 +1 smell the uppercase Roses +flowers @outside +3 stop +-- +TODO: 7 of 7 tasks shown from $HOME/todo.txt + +>>> todo.sh do 7,6 +7: x 2009-02-13 remove4 +TODO: 7 marked as done. +6: x 2009-02-13 remove3 +TODO: 6 marked as done. +x 2009-02-13 remove3 +x 2009-02-13 remove4 +TODO: $HOME/todo.txt archived. + +>>> todo.sh -p list +2 notice the sunflowers +4 remove1 +5 remove2 +1 smell the uppercase Roses +flowers @outside +3 stop +-- +TODO: 5 of 5 tasks shown from $HOME/todo.txt + +>>> todo.sh do 5 4 +5: x 2009-02-13 remove2 +TODO: 5 marked as done. +4: x 2009-02-13 remove1 +TODO: 4 marked as done. +x 2009-02-13 remove1 +x 2009-02-13 remove2 +TODO: $HOME/todo.txt archived. + +>>> todo.sh -p list +2 notice the sunflowers +1 smell the uppercase Roses +flowers @outside +3 stop +-- +TODO: 3 of 3 tasks shown from $HOME/todo.txt +EOF + +test_done diff --git a/todo.sh b/todo.sh index fabbdb8..3d2108c 100755 --- a/todo.sh +++ b/todo.sh @@ -675,27 +675,32 @@ case $action in "do" ) errmsg="usage: $TODO_SH do ITEM#" - item=$2 - [ -z "$item" ] && die "$errmsg" - [[ "$item" = +([0-9]) ]] || die "$errmsg" + # shift so we get arguments to the do request + shift; - todo=$(sed "$item!d" "$TODO_FILE") - [ -z "$todo" ] && die "$item: No such todo." - - now=`date '+%Y-%m-%d'` - # remove priority once item is done - sed -i.bak $item"s/^(.) //" "$TODO_FILE" - sed -i.bak $item"s|^|&x $now |" "$TODO_FILE" - newtodo=$(sed "$item!d" "$TODO_FILE") - [ $TODOTXT_VERBOSE -gt 0 ] && echo "$item: $newtodo" - [ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: $item marked as done." + # Split multiple do's, if comma seperated change to whitespace sepereated + # Loop the 'do' function for each item + for item in `echo $* | tr ',' ' '`; do + [ -z "$item" ] && die "$errmsg" + [[ "$item" = +([0-9]) ]] || die "$errmsg" + + todo=$(sed "$item!d" "$TODO_FILE") + [ -z "$todo" ] && die "$item: No such todo." + now=`date '+%Y-%m-%d'` + # remove priority once item is done + sed -i.bak $item"s/^(.) //" "$TODO_FILE" + sed -i.bak $item"s|^|&x $now |" "$TODO_FILE" + newtodo=$(sed "$item!d" "$TODO_FILE") + [ $TODOTXT_VERBOSE -gt 0 ] && echo "$item: $newtodo" + [ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: $item marked as done." + done + if [ $TODOTXT_AUTO_ARCHIVE = 1 ]; then archive fi cleanup ;; - "help" ) help ;;