From 32c84781d29078bb0f0e25305adc7d645533c9ef Mon Sep 17 00:00:00 2001 From: Ingo Karkat Date: Tue, 10 May 2011 12:44:34 +0200 Subject: [PATCH] pri: Check for existing priority and adapt message. The existing check (as with depri) didn't do much good. Instead, fetch the existing priority and use that information to print more specific messages: - TODO: 42 re-prioritized from (C) to (A) - TODO: 42 already prioritized (A) --- tests/t1200-pri.sh | 4 ++-- todo.sh | 27 ++++++++++++++++----------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/tests/t1200-pri.sh b/tests/t1200-pri.sh index c504ef0..74baccf 100755 --- a/tests/t1200-pri.sh +++ b/tests/t1200-pri.sh @@ -55,7 +55,7 @@ TODO: 3 of 3 tasks shown >>> todo.sh pri 2 A 2 (A) notice the sunflowers -TODO: 2 prioritized (A). +TODO: 2 re-prioritized from (C) to (A). >>> todo.sh -p list 2 (A) notice the sunflowers @@ -66,7 +66,7 @@ TODO: 3 of 3 tasks shown >>> todo.sh pri 2 a 2 (A) notice the sunflowers -TODO: 2 prioritized (A). +TODO: 2 already prioritized (A). >>> todo.sh -p listpri 2 (A) notice the sunflowers diff --git a/todo.sh b/todo.sh index ca98318..3e2ae6a 100755 --- a/todo.sh +++ b/todo.sh @@ -1091,18 +1091,23 @@ note: PRIORITY must be anywhere from A to Z." [[ "$item" = +([0-9]) ]] || die "$errmsg" [[ "$newpri" = @([A-Z]) ]] || die "$errmsg" - sed -e $item"s/^(.) //" -e $item"s/^/($newpri) /" "$TODO_FILE" > /dev/null 2>&1 - - if [ "$?" -eq 0 ]; then - #it's all good, continue + oldpri=$(sed -ne $item's/^(\(.\)) .*/\1/p' "$TODO_FILE") + if [ "$oldpri" != "$newpri" ]; then sed -i.bak -e $item"s/^(.) //" -e $item"s/^/($newpri) /" "$TODO_FILE" - if [ $TODOTXT_VERBOSE -gt 0 ]; then - NEWTODO=$(sed "$item!d" "$TODO_FILE") - echo "$item $NEWTODO" - echo "TODO: $item prioritized ($newpri)." - fi - else - die "$errmsg" + fi + if [ $TODOTXT_VERBOSE -gt 0 ]; then + NEWTODO=$(sed "$item!d" "$TODO_FILE") + echo "$item $NEWTODO" + if [ "$oldpri" != "$newpri" ]; then + if [ "$oldpri" ]; then + echo "TODO: $item re-prioritized from ($oldpri) to ($newpri)." + else + echo "TODO: $item prioritized ($newpri)." + fi + fi + fi + if [ "$oldpri" = "$newpri" ]; then + echo "TODO: $item already prioritized ($newpri)." fi ;;