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)
This commit is contained in:
Ingo Karkat
2011-05-10 12:44:34 +02:00
committed by Gina Trapani
parent 6e740f748e
commit 32c84781d2
2 changed files with 18 additions and 13 deletions

View File

@@ -55,7 +55,7 @@ TODO: 3 of 3 tasks shown
>>> todo.sh pri 2 A >>> todo.sh pri 2 A
2 (A) notice the sunflowers 2 (A) notice the sunflowers
TODO: 2 prioritized (A). TODO: 2 re-prioritized from (C) to (A).
>>> todo.sh -p list >>> todo.sh -p list
2 (A) notice the sunflowers 2 (A) notice the sunflowers
@@ -66,7 +66,7 @@ TODO: 3 of 3 tasks shown
>>> todo.sh pri 2 a >>> todo.sh pri 2 a
2 (A) notice the sunflowers 2 (A) notice the sunflowers
TODO: 2 prioritized (A). TODO: 2 already prioritized (A).
>>> todo.sh -p listpri >>> todo.sh -p listpri
2 (A) notice the sunflowers 2 (A) notice the sunflowers

27
todo.sh
View File

@@ -1091,18 +1091,23 @@ note: PRIORITY must be anywhere from A to Z."
[[ "$item" = +([0-9]) ]] || die "$errmsg" [[ "$item" = +([0-9]) ]] || die "$errmsg"
[[ "$newpri" = @([A-Z]) ]] || die "$errmsg" [[ "$newpri" = @([A-Z]) ]] || die "$errmsg"
sed -e $item"s/^(.) //" -e $item"s/^/($newpri) /" "$TODO_FILE" > /dev/null 2>&1 oldpri=$(sed -ne $item's/^(\(.\)) .*/\1/p' "$TODO_FILE")
if [ "$oldpri" != "$newpri" ]; then
if [ "$?" -eq 0 ]; then
#it's all good, continue
sed -i.bak -e $item"s/^(.) //" -e $item"s/^/($newpri) /" "$TODO_FILE" sed -i.bak -e $item"s/^(.) //" -e $item"s/^/($newpri) /" "$TODO_FILE"
if [ $TODOTXT_VERBOSE -gt 0 ]; then fi
NEWTODO=$(sed "$item!d" "$TODO_FILE") if [ $TODOTXT_VERBOSE -gt 0 ]; then
echo "$item $NEWTODO" NEWTODO=$(sed "$item!d" "$TODO_FILE")
echo "TODO: $item prioritized ($newpri)." echo "$item $NEWTODO"
fi if [ "$oldpri" != "$newpri" ]; then
else if [ "$oldpri" ]; then
die "$errmsg" 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 fi
;; ;;