Compare commits

..

1 Commits

Author SHA1 Message Date
Ingo Karkat
99dc4dce9f Simplified check for done task.
Use simple comparison with slice of string (already used e.g. in _list()) instead of grep -c pipeline.
2011-05-12 14:17:05 +02:00
4 changed files with 37 additions and 71 deletions

View File

@@ -53,28 +53,9 @@ TODO: 2 prioritized (C).
-- --
TODO: 3 of 3 tasks shown TODO: 3 of 3 tasks shown
>>> todo.sh add "smell the coffee +wakeup"
4 smell the coffee +wakeup
TODO: 4 added.
>>> todo.sh -p list
1 (B) smell the uppercase Roses +flowers @outside
2 (C) notice the sunflowers
4 smell the coffee +wakeup
3 stop
--
TODO: 4 of 4 tasks shown
EOF
cat > todo.txt <<EOF
(B) smell the uppercase Roses +flowers @outside
(C) notice the sunflowers
stop
EOF
test_todo_session 'reprioritize' <<EOF
>>> todo.sh pri 2 A >>> todo.sh pri 2 A
2 (A) notice the sunflowers 2 (A) notice the sunflowers
TODO: 2 re-prioritized from (C) to (A). TODO: 2 prioritized (A).
>>> todo.sh -p list >>> todo.sh -p list
2 (A) notice the sunflowers 2 (A) notice the sunflowers
@@ -85,12 +66,25 @@ 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 already prioritized (A). TODO: 2 prioritized (A).
>>> todo.sh -p listpri >>> todo.sh -p listpri
2 (A) notice the sunflowers 2 (A) notice the sunflowers
1 (B) smell the uppercase Roses +flowers @outside 1 (B) smell the uppercase Roses +flowers @outside
-- --
TODO: 2 of 3 tasks shown TODO: 2 of 3 tasks shown
>>> todo.sh add "smell the coffee +wakeup"
4 smell the coffee +wakeup
TODO: 4 added.
>>> todo.sh -p list
2 (A) notice the sunflowers
1 (B) smell the uppercase Roses +flowers @outside
4 smell the coffee +wakeup
3 stop
--
TODO: 4 of 4 tasks shown
EOF EOF
test_done test_done

View File

@@ -81,6 +81,6 @@ test_todo_session 'fail multiple do attempts' <<EOF
TODO: 3 marked as done. TODO: 3 marked as done.
>>> todo.sh -a do 3 >>> todo.sh -a do 3
TODO: 3 is already marked done. 3 is already marked done
EOF EOF
test_done test_done

View File

@@ -68,30 +68,4 @@ TODO: 2 deprioritized.
TODO: 3 of 3 tasks shown TODO: 3 of 3 tasks shown
EOF EOF
cat > todo.txt <<EOF
(B) smell the uppercase Roses +flowers @outside
(A) notice the sunflowers
stop
EOF
test_todo_session 'depriority of unprioritized task' <<EOF
>>> todo.sh -p list
2 (A) notice the sunflowers
1 (B) smell the uppercase Roses +flowers @outside
3 stop
--
TODO: 3 of 3 tasks shown
>>> todo.sh depri 3 2
TODO: 3 is not prioritized.
2 notice the sunflowers
TODO: 2 deprioritized.
>>> todo.sh -p list
1 (B) smell the uppercase Roses +flowers @outside
2 notice the sunflowers
3 stop
--
TODO: 3 of 3 tasks shown
EOF
test_done test_done

34
todo.sh
View File

@@ -324,8 +324,8 @@ replaceOrPrepend()
cleaninput $input cleaninput $input
# Retrieve existing priority and prepended date # Retrieve existing priority and prepended date
priority=$(sed -e "$item!d" -e $item's/^\((.) \)\{0,1\}\([0-9]\{2,4\}-[0-9]\{2\}-[0-9]\{2\} \)\{0,1\}.*/\1/' "$TODO_FILE") priority=$(sed -e "$item!d" -e $item's/^\(([A-Z]) \)\{0,1\}\([0-9]\{2,4\}-[0-9]\{2\}-[0-9]\{2\} \)\{0,1\}.*/\1/' "$TODO_FILE")
prepdate=$(sed -e "$item!d" -e $item's/^\((.) \)\{0,1\}\([0-9]\{2,4\}-[0-9]\{2\}-[0-9]\{2\} \)\{0,1\}.*/\2/' "$TODO_FILE") prepdate=$(sed -e "$item!d" -e $item's/^\(([A-Z]) \)\{0,1\}\([0-9]\{2,4\}-[0-9]\{2\}-[0-9]\{2\} \)\{0,1\}.*/\2/' "$TODO_FILE")
if [ "$prepdate" -a "$action" = "replace" ] && [ "$(echo "$input"|sed -e 's/^\([0-9]\{2,4\}-[0-9]\{2\}-[0-9]\{2\}\)\{0,1\}.*/\1/')" ]; then if [ "$prepdate" -a "$action" = "replace" ] && [ "$(echo "$input"|sed -e 's/^\([0-9]\{2,4\}-[0-9]\{2\}-[0-9]\{2\}\)\{0,1\}.*/\1/')" ]; then
# If the replaced text starts with a date, it will replace the existing # If the replaced text starts with a date, it will replace the existing
@@ -921,7 +921,10 @@ case $action in
todo=$(sed "$item!d" "$TODO_FILE") todo=$(sed "$item!d" "$TODO_FILE")
[ -z "$todo" ] && die "TODO: No task $item." [ -z "$todo" ] && die "TODO: No task $item."
if sed "$item!d" "$TODO_FILE" | grep "^(.) " > /dev/null; then sed -e $item"s/^(.) //" "$TODO_FILE" > /dev/null 2>&1
if [ "$?" -eq 0 ]; then
#it's all good, continue
sed -i.bak -e $item"s/^(.) //" "$TODO_FILE" sed -i.bak -e $item"s/^(.) //" "$TODO_FILE"
if [ $TODOTXT_VERBOSE -gt 0 ]; then if [ $TODOTXT_VERBOSE -gt 0 ]; then
NEWTODO=$(sed "$item!d" "$TODO_FILE") NEWTODO=$(sed "$item!d" "$TODO_FILE")
@@ -929,7 +932,7 @@ case $action in
echo "TODO: $item deprioritized." echo "TODO: $item deprioritized."
fi fi
else else
echo "TODO: $item is not prioritized." die "$errmsg"
fi fi
done done
;; ;;
@@ -950,7 +953,7 @@ case $action in
[ -z "$todo" ] && die "TODO: No task $item." [ -z "$todo" ] && die "TODO: No task $item."
# Check if this item has already been done # Check if this item has already been done
if [ `echo $todo | grep -c "^x "` -eq 0 ] ; then if [ "${todo:0:2}" != "x " ]; then
now=`date '+%Y-%m-%d'` now=`date '+%Y-%m-%d'`
# remove priority once item is done # remove priority once item is done
sed -i.bak $item"s/^(.) //" "$TODO_FILE" sed -i.bak $item"s/^(.) //" "$TODO_FILE"
@@ -961,7 +964,7 @@ case $action in
echo "TODO: $item marked as done." echo "TODO: $item marked as done."
fi fi
else else
echo "TODO: $item is already marked done." echo "$item is already marked done"
fi fi
done done
@@ -1020,7 +1023,7 @@ case $action in
} }
else else
## No priority specified; show all priority tasks ## No priority specified; show all priority tasks
pri="[A-Z]" pri="[[:upper:]]"
fi fi
pri="($pri)" pri="($pri)"
@@ -1086,23 +1089,18 @@ 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"
oldpri=$(sed -ne $item's/^(\(.\)) .*/\1/p' "$TODO_FILE") sed -e $item"s/^(.) //" -e $item"s/^/($newpri) /" "$TODO_FILE" > /dev/null 2>&1
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"
fi
if [ $TODOTXT_VERBOSE -gt 0 ]; then if [ $TODOTXT_VERBOSE -gt 0 ]; then
NEWTODO=$(sed "$item!d" "$TODO_FILE") NEWTODO=$(sed "$item!d" "$TODO_FILE")
echo "$item $NEWTODO" 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)." echo "TODO: $item prioritized ($newpri)."
fi fi
fi else
fi die "$errmsg"
if [ "$oldpri" = "$newpri" ]; then
echo "TODO: $item already prioritized ($newpri)."
fi fi
;; ;;