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
>>> todo.sh depri B B
usage: todo.sh depri ITEM#
usage: todo.sh depri ITEM#[, ITEM#, ITEM#, ...]
=== 1
EOF
@@ -41,4 +41,31 @@ TODO: 1 deprioritized.
TODO: 3 of 3 tasks shown
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

47
todo.sh
View File

@@ -48,7 +48,7 @@ shorthelp()
archive
command [ACTIONS]
del|rm NUMBER [TERM]
dp|depri NUMBER
dp|depri NUMBER[, NUMBER, NUMBER, ...]
do NUMBER[, NUMBER, NUMBER, ...]
help
list|ls [TERM...]
@@ -108,8 +108,8 @@ help()
Deletes the item on line NUMBER in todo.txt.
If term specified, deletes only the term from the line.
depri NUMBER
dp NUMBER
depri NUMBER[, NUMBER, NUMBER, ...]
dp NUMBER[, NUMBER, NUMBER, ...]
Deprioritizes (removes the priority) from the item
on line NUMBER in todo.txt.
@@ -742,27 +742,32 @@ case $action in
fi ;;
"depri" | "dp" )
item=$2
errmsg="usage: $TODO_SH depri ITEM#"
errmsg="usage: $TODO_SH depri ITEM#[, ITEM#, ITEM#, ...]"
shift;
[ $# -eq 0 ] && die "$errmsg"
[[ "$item" = +([0-9]) ]] || die "$errmsg"
todo=$(sed "$item!d" "$TODO_FILE")
[ -z "$todo" ] && die "$item: No such todo."
# 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"
todo=$(sed "$item!d" "$TODO_FILE")
[ -z "$todo" ] && die "$item: No such todo."
sed -e $item"s/^(.) //" "$TODO_FILE" > /dev/null 2>&1
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"
[ $TODOTXT_VERBOSE -gt 0 ] && {
NEWTODO=$(sed "$item!d" "$TODO_FILE")
echo "`echo "$item: $NEWTODO"`"
echo "TODO: $item deprioritized."
}
cleanup
else
die "$errmsg"
fi;;
if [ "$?" -eq 0 ]; then
#it's all good, continue
sed -i.bak -e $item"s/^(.) //" "$TODO_FILE"
[ $TODOTXT_VERBOSE -gt 0 ] && {
NEWTODO=$(sed "$item!d" "$TODO_FILE")
echo "`echo "$item: $NEWTODO"`"
echo "TODO: $item deprioritized."
}
else
die "$errmsg"
fi
done
cleanup ;;
"do" )
errmsg="usage: $TODO_SH do ITEM#[, ITEM#, ITEM#, ...]"