From 617d377b01b34e6256514ac1f5cd593d3f5d309d Mon Sep 17 00:00:00 2001 From: Ingo Karkat Date: Tue, 10 May 2011 15:54:50 +0200 Subject: [PATCH] ENH: Allow listpri filtering via TERM. This even simplified the argument handling, since there can be no invalid priority any more; all other strings are taken as TERMs. And the check for empty ${1:-} was superfluous, anyway. Apart from these simplifications, it's basically just passing $@ to _list. --- tests/t1250-listpri.sh | 40 ++++++++++++++++++++++++++++++++-------- todo.sh | 24 +++++++----------------- 2 files changed, 39 insertions(+), 25 deletions(-) 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 f24b638..1931366 100755 --- a/todo.sh +++ b/todo.sh @@ -58,7 +58,7 @@ shorthelp() listall|lsa [TERM...] listcon|lsc listfile|lf SRC [TERM...] - listpri|lsp [PRIORITY] + listpri|lsp [PRIORITY] [TERM...] listproj|lsprj move|mv ITEM# DEST [SRC] prepend|prep ITEM# "TEXT TO PREPEND" @@ -143,10 +143,11 @@ help() sorted by priority with line numbers. If TERM specified, lists all lines that contain TERM in SRC file. - listpri [PRIORITY] - lsp [PRIORITY] + listpri [PRIORITY] [TERM...] + lsp [PRIORITY] [TERM...] Displays all tasks prioritized PRIORITY. If no PRIORITY specified, lists all prioritized tasks. + If TERM specified, lists only prioritized tasks that contain TERM. listproj lsprj @@ -1009,22 +1010,11 @@ case $action in ;; "listpri" | "lsp" ) - shift ## was "listpri", new $1 is priority to list - - 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 + shift ## was "listpri", new $1 is priority to list or first TERM + 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" + _list "$TODO_FILE" "$@" ;; "move" | "mv" )