From e6136e14b8916aae3c0d9d18bcff8a225c275afe 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 7d633cc..48a3067 100755 --- a/tests/t1200-pri.sh +++ b/tests/t1200-pri.sh @@ -74,7 +74,7 @@ EOF test_todo_session 'reprioritize' <>> 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 @@ -85,7 +85,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 f10ff37..b8ad961 100755 --- a/todo.sh +++ b/todo.sh @@ -1086,18 +1086,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 ;;