From 0fa5f6d1ddf76a048dfc68f524df754c2834b93c Mon Sep 17 00:00:00 2001 From: Ingo Karkat Date: Tue, 10 May 2011 15:20:29 +0200 Subject: [PATCH] BUG: listpri picked up non-priority patterns. The regexp for the priority wasn't anchored to the beginning of the task. (As the filtering is done inside the _list pipeline, the task number has already been prepended.) Also, by passing the regexp directly to _list, a case-insensitive search was performed, so despite [A-Z], lowercase characters were picked up, too. Need to make use of post_filter_command to inject a separate, case-sensitive grep into the pipeline. Bonus: Added test for highlighting of listpri command. --- tests/t1250-listpri.sh | 71 ++++++++++++++++++++++++++++++++++++++++++ todo.sh | 13 +++++++- 2 files changed, 83 insertions(+), 1 deletion(-) create mode 100755 tests/t1250-listpri.sh diff --git a/tests/t1250-listpri.sh b/tests/t1250-listpri.sh new file mode 100755 index 00000000..b01ad733 --- /dev/null +++ b/tests/t1250-listpri.sh @@ -0,0 +1,71 @@ +#!/bin/sh + +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.sh listpri A +-- +TODO: 0 of 3 tasks shown + +>>> todo.sh -p listpri c +2 (C) notice the sunflowers +-- +TODO: 1 of 3 tasks shown +EOF + +test_todo_session 'listpri highlighting' <>> todo.sh listpri +1 (B) smell the uppercase Roses +flowers @outside +2 (C) notice the sunflowers +-- +TODO: 2 of 3 tasks shown +EOF + +cat > todo.txt <>> todo.sh -p listpri +1 (B) smell the uppercase Roses +flowers @outside +2 (C) notice the sunflowers +-- +TODO: 2 of 5 tasks shown + +>>> todo.sh -p listpri b +1 (B) smell the uppercase Roses +flowers @outside +-- +TODO: 1 of 5 tasks shown + +>>> todo.sh -p listpri c +2 (C) notice the sunflowers +-- +TODO: 1 of 5 tasks shown + +>>> todo.sh -p listpri m +-- +TODO: 0 of 5 tasks shown + +>>> todo.sh -p listpri n +-- +TODO: 0 of 5 tasks shown +EOF + +test_done diff --git a/todo.sh b/todo.sh index 239f118b..cf7c1524 100755 --- a/todo.sh +++ b/todo.sh @@ -1016,7 +1016,18 @@ case $action in "listpri" | "lsp" ) 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]" + 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 + post_filter_command="grep '^ *[0-9]\+ (${pri}) '" _list "$TODO_FILE" "$@" ;;