From 15084aa4d770cc3d17b1b03dec5aca272aa2e203 Mon Sep 17 00:00:00 2001 From: Ingo Karkat Date: Tue, 25 May 2010 13:27:28 +0200 Subject: [PATCH] Allow passing multiple items to depri, like for the do command. --- tests/t1700-depri.sh | 29 ++++++++++++++++++++++++++- todo.sh | 47 ++++++++++++++++++++++++-------------------- 2 files changed, 54 insertions(+), 22 deletions(-) diff --git a/tests/t1700-depri.sh b/tests/t1700-depri.sh index 24bad09..3bc3b32 100755 --- a/tests/t1700-depri.sh +++ b/tests/t1700-depri.sh @@ -6,7 +6,7 @@ test_description='basic depriority functionality test_todo_session 'depriority usage' <>> 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 <>> 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 diff --git a/todo.sh b/todo.sh index 2894b40..172dea8 100755 --- a/todo.sh +++ b/todo.sh @@ -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#, ...]"