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 ;;