Allow passing multiple items to depri, like for the do command.

This commit is contained in:
Ingo Karkat
2010-05-25 13:27:28 +02:00
parent 5876cc0437
commit 15084aa4d7
2 changed files with 54 additions and 22 deletions

View File

@@ -6,7 +6,7 @@ test_description='basic depriority functionality
test_todo_session 'depriority usage' <<EOF test_todo_session 'depriority usage' <<EOF
>>> todo.sh depri B B >>> todo.sh depri B B
usage: todo.sh depri ITEM# usage: todo.sh depri ITEM#[, ITEM#, ITEM#, ...]
=== 1 === 1
EOF EOF
@@ -41,4 +41,31 @@ TODO: 1 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
(C) stop
EOF
test_todo_session 'multiple depriority' <<EOF
>>> todo.sh -p list
2 (A) notice the sunflowers
1 (B) smell the uppercase Roses +flowers @outside
3 (C) stop
--
TODO: 3 of 3 tasks shown
>>> todo.sh depri 3 2
3: stop
TODO: 3 deprioritized.
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

19
todo.sh
View File

@@ -48,7 +48,7 @@ shorthelp()
archive archive
command [ACTIONS] command [ACTIONS]
del|rm NUMBER [TERM] del|rm NUMBER [TERM]
dp|depri NUMBER dp|depri NUMBER[, NUMBER, NUMBER, ...]
do NUMBER[, NUMBER, NUMBER, ...] do NUMBER[, NUMBER, NUMBER, ...]
help help
list|ls [TERM...] list|ls [TERM...]
@@ -108,8 +108,8 @@ help()
Deletes the item on line NUMBER in todo.txt. Deletes the item on line NUMBER in todo.txt.
If term specified, deletes only the term from the line. If term specified, deletes only the term from the line.
depri NUMBER depri NUMBER[, NUMBER, NUMBER, ...]
dp NUMBER dp NUMBER[, NUMBER, NUMBER, ...]
Deprioritizes (removes the priority) from the item Deprioritizes (removes the priority) from the item
on line NUMBER in todo.txt. on line NUMBER in todo.txt.
@@ -742,9 +742,13 @@ case $action in
fi ;; fi ;;
"depri" | "dp" ) "depri" | "dp" )
item=$2 errmsg="usage: $TODO_SH depri ITEM#[, ITEM#, ITEM#, ...]"
errmsg="usage: $TODO_SH depri ITEM#" shift;
[ $# -eq 0 ] && die "$errmsg"
# Split multiple depri's, if comma separated change to whitespace separated
# Loop the 'depri' function for each item
for item in `echo $* | tr ',' ' '`; do
[[ "$item" = +([0-9]) ]] || die "$errmsg" [[ "$item" = +([0-9]) ]] || die "$errmsg"
todo=$(sed "$item!d" "$TODO_FILE") todo=$(sed "$item!d" "$TODO_FILE")
[ -z "$todo" ] && die "$item: No such todo." [ -z "$todo" ] && die "$item: No such todo."
@@ -759,10 +763,11 @@ case $action in
echo "`echo "$item: $NEWTODO"`" echo "`echo "$item: $NEWTODO"`"
echo "TODO: $item deprioritized." echo "TODO: $item deprioritized."
} }
cleanup
else else
die "$errmsg" die "$errmsg"
fi;; fi
done
cleanup ;;
"do" ) "do" )
errmsg="usage: $TODO_SH do ITEM#[, ITEM#, ITEM#, ...]" errmsg="usage: $TODO_SH do ITEM#[, ITEM#, ITEM#, ...]"