From 8f6070e702fdd45d0fa05e6c9df9664e3ca5a4ef Mon Sep 17 00:00:00 2001 From: Ingo Karkat Date: Sun, 10 Jul 2011 22:04:51 +0200 Subject: [PATCH] Re-applying the listpri stuff still missing from the pull requests. --- tests/t1200-pri.sh | 33 ++++++++++++++++++++------------- tests/t1250-listpri.sh | 40 ++++++++++++++++++++++++++++++++-------- todo.sh | 17 +++-------------- 3 files changed, 55 insertions(+), 35 deletions(-) diff --git a/tests/t1200-pri.sh b/tests/t1200-pri.sh index 74baccf..3d4ca70 100755 --- a/tests/t1200-pri.sh +++ b/tests/t1200-pri.sh @@ -53,6 +53,25 @@ TODO: 2 prioritized (C). -- TODO: 3 of 3 tasks shown +>>> todo.sh add "smell the coffee +wakeup" +4 smell the coffee +wakeup +TODO: 4 added. + +>>> todo.sh -p list +1 (B) smell the uppercase Roses +flowers @outside +2 (C) notice the sunflowers +4 smell the coffee +wakeup +3 stop +-- +TODO: 4 of 4 tasks shown +EOF + +cat > todo.txt <>> todo.sh pri 2 A 2 (A) notice the sunflowers TODO: 2 re-prioritized from (C) to (A). @@ -68,23 +87,11 @@ TODO: 3 of 3 tasks shown 2 (A) notice the sunflowers TODO: 2 already prioritized (A). ->>> todo.sh -p listpri -2 (A) notice the sunflowers -1 (B) smell the uppercase Roses +flowers @outside --- -TODO: 2 of 3 tasks shown - ->>> todo.sh add "smell the coffee +wakeup" -4 smell the coffee +wakeup -TODO: 4 added. - >>> todo.sh -p list 2 (A) notice the sunflowers 1 (B) smell the uppercase Roses +flowers @outside -4 smell the coffee +wakeup 3 stop -- -TODO: 4 of 4 tasks shown +TODO: 3 of 3 tasks shown EOF - test_done diff --git a/tests/t1250-listpri.sh b/tests/t1250-listpri.sh index b01ad73..0f97ec9 100755 --- a/tests/t1250-listpri.sh +++ b/tests/t1250-listpri.sh @@ -4,13 +4,6 @@ test_description='list priority functionality ' . ./test-lib.sh -test_todo_session 'listpri usage' <>> todo.sh listpri ? -usage: todo.sh listpri PRIORITY -note: PRIORITY must a single letter from A to Z. -=== 1 -EOF - cat > todo.txt < todo.txt <>> todo.sh -p listpri 1 (B) smell the uppercase Roses +flowers @outside 2 (C) notice the sunflowers @@ -68,4 +61,35 @@ TODO: 0 of 5 tasks shown TODO: 0 of 5 tasks shown EOF +cat > todo.txt <>> todo.sh -p listpri "should be" +3 (A) aaa zzz this line should be first. +5 (B) bbb yyy this line should be second. +1 (B) ccc xxx this line should be third. +-- +TODO: 3 of 6 tasks shown + +>>> todo.sh -p listpri a "should be" +3 (A) aaa zzz this line should be first. +-- +TODO: 1 of 6 tasks shown + +>>> todo.sh -p listpri b second +5 (B) bbb yyy this line should be second. +-- +TODO: 1 of 6 tasks shown + +>>> todo.sh -p listpri x "should be" +-- +TODO: 0 of 6 tasks shown +EOF + test_done diff --git a/todo.sh b/todo.sh index 54f2071..a21356e 100755 --- a/todo.sh +++ b/todo.sh @@ -923,7 +923,7 @@ case $action in todo=$(sed "$item!d" "$TODO_FILE") [ -z "$todo" ] && die "TODO: No task $item." - if sed "$item!d" "$TODO_FILE" | grep "^(.) " > /dev/null; then + if [[ "$todo" = \(?\)\ * ]]; then sed -i.bak -e $item"s/^(.) //" "$TODO_FILE" if [ $TODOTXT_VERBOSE -gt 0 ]; then NEWTODO=$(sed "$item!d" "$TODO_FILE") @@ -944,7 +944,7 @@ case $action in # Split multiple do's, if comma separated change to whitespace separated # Loop the 'do' function for each item - for item in $(echo $* | tr ',' ' '); do + for item in $(echo $* | tr ',' ' '); do [ -z "$item" ] && die "$errmsg" [[ "$item" = +([0-9]) ]] || die "$errmsg" @@ -1013,18 +1013,7 @@ case $action in "listpri" | "lsp" ) shift ## was "listpri", new $1 is priority to list or first TERM - if [ "${1:-}" ] - then - ## A priority was specified - pri=$( printf "%s\n" "$1" | tr 'a-z' 'A-Z' | grep '^[A-Z]$' ) || { - die "usage: $TODO_SH listpri PRIORITY -note: PRIORITY must a single letter from A to Z." - } - else - ## No priority specified; show all priority tasks - pri="[A-Z]" - fi - + pri=$(printf "%s\n" "$1" | tr 'a-z' 'A-Z' | grep '^[A-Z]$') && shift || pri="[A-Z]" post_filter_command="grep '^ *[0-9]\+ (${pri}) '" _list "$TODO_FILE" "$@" ;;