diff --git a/tests/t1550-done.sh b/tests/t1550-done.sh new file mode 100755 index 0000000..77282e1 --- /dev/null +++ b/tests/t1550-done.sh @@ -0,0 +1,52 @@ +#!/bin/sh + +test_description='done functionality +' +. ./test-lib.sh + +#DATE=`date '+%Y-%m-%d'` + +test_todo_session 'done usage' <>> export TODOTXT_FORCE=1 + +>>> todo.sh done +usage: todo.sh done "TODO ITEM" +=== 1 +EOF + +cat > todo.txt <>> todo.sh lsa +2 remove1 +3 remove2 +4 remove3 +5 remove4 +1 stop +-- +TODO: 5 of 5 tasks shown + +>>> todo.sh done smell the uppercase Roses +TODO: 'smell the uppercase Roses' marked as done. + +>>> todo.sh done notice the sunflowers +TODO: 'notice the sunflowers' marked as done. + +>>> todo.sh lsa +2 remove1 +3 remove2 +4 remove3 +5 remove4 +1 stop +7 x 2009-02-13 notice the sunflowers +6 x 2009-02-13 smell the uppercase Roses +-- +TODO: 7 of 7 tasks shown +EOF +test_done diff --git a/tests/t2000-multiline.sh b/tests/t2000-multiline.sh index bf8a66b..43ab362 100755 --- a/tests/t2000-multiline.sh +++ b/tests/t2000-multiline.sh @@ -18,7 +18,7 @@ cat /dev/null > $HOME/todo.txt # Run replace "$HOME/bin/todo.sh" replace 1 "eat apples -eat oranges +eat oranges drink milk" > $HOME/output.multi # Test output against expected @@ -43,7 +43,7 @@ cat /dev/null > $HOME/todo.txt # Run add "$HOME/bin/todo.sh" add "eat apples -eat oranges +eat oranges drink milk" > $HOME/output.multi # Test output against expected @@ -68,7 +68,7 @@ cat /dev/null > $HOME/todo.txt # Run append "$HOME/bin/todo.sh" append 1 "eat apples -eat oranges +eat oranges drink milk" > $HOME/output.multi # Test output against expected @@ -93,7 +93,7 @@ cat /dev/null > $HOME/todo.txt # Run prepend "$HOME/bin/todo.sh" prepend 1 "eat apples -eat oranges +eat oranges drink milk" > $HOME/output.multi # Test output against expected diff --git a/todo.sh b/todo.sh index 6a96210..f3b0239 100755 --- a/todo.sh +++ b/todo.sh @@ -259,13 +259,10 @@ cleaninput() # Replace newlines with spaces Always input=`echo $input | tr -d '\r|\n'` - # Storing regexp in variable fixes quoting difference between - # bash v3.1.x and v3.2.x see: - # http://stackoverflow.com/questions/218156/bash-regex-with-quotes - action_regexp='^(append|app|prepend|prep|replace)$' + action_regexp="^\(append\|app\|prepend\|prep\|replace\)$" # Check which action we are being used in as this affects what cleaning we do - if [[ $action =~ $action_regexp ]]; then + if [ `echo $action | grep -c $action_regexp` -eq 1 ]; then # These actions use sed and & as the matched string so escape it input=`echo $input | sed 's/\&/\\\&/g'` fi @@ -503,9 +500,9 @@ _addto() { _commit() { [ -z "$1" ] && die "Fatal Error: No commit message." [ -z "$2" ] && die "Fatal Error: No commit files." - MESG="$(echo $1 | sed -e 's|\\n|\n|g')" - shift - FILES=$* + MESG="$(echo $1 | sed -e 's|\\n|\n|g')" + shift + FILES=$* if [ $TODOTXT_GIT_VERBOSE -eq 0 ] ; then ( cd $TODO_DIR @@ -833,28 +830,28 @@ case $action in # Split multiple do's, if comma seperated change to whitespace sepereated # Loop the 'do' function for each item for item in `echo $* | tr ',' ' '`; do - [ -z "$item" ] && die "$errmsg" - [[ "$item" = +([0-9]) ]] || die "$errmsg" + [ -z "$item" ] && die "$errmsg" + [[ "$item" = +([0-9]) ]] || die "$errmsg" - todo=$(sed "$item!d" "$TODO_FILE") - [ -z "$todo" ] && die "$item: No such todo." + todo=$(sed "$item!d" "$TODO_FILE") + [ -z "$todo" ] && die "$item: No such todo." - # Check if this item has already been done - if [ `echo $todo | grep -c "^x "` -eq 0 ] ; then - now=`date '+%Y-%m-%d'` - # remove priority once item is done - sed -i.bak $item"s/^(.) //" "$TODO_FILE" - sed -i.bak $item"s|^|&x $now |" "$TODO_FILE" - [ $TODOTXT_VERBOSE -gt 0 ] && { - newtodo=$(sed "$item!d" "$TODO_FILE") - echo "$item: $newtodo" - echo "TODO: $item marked as done." - } - [ $TODOTXT_GIT_ENABLED -eq 1 ] && \ - _commit "TODO: '$todo' marked as done." $TODO_FILE - else - echo "$item is already marked done" - fi + # Check if this item has already been done + if [ `echo $todo | grep -c "^x "` -eq 0 ] ; then + now=`date '+%Y-%m-%d'` + # remove priority once item is done + sed -i.bak $item"s/^(.) //" "$TODO_FILE" + sed -i.bak $item"s|^|&x $now |" "$TODO_FILE" + [ $TODOTXT_VERBOSE -gt 0 ] && { + newtodo=$(sed "$item!d" "$TODO_FILE") + echo "$item: $newtodo" + echo "TODO: $item marked as done." + } + [ $TODOTXT_GIT_ENABLED -eq 1 ] && \ + _commit "TODO: '$todo' marked as done." $TODO_FILE + else + echo "$item is already marked done" + fi done if [ $TODOTXT_AUTO_ARCHIVE = 1 ]; then @@ -862,6 +859,28 @@ case $action in fi cleanup ;; +"done" ) + if [[ -z "$2" && $TODOTXT_FORCE = 0 ]]; then + echo -n "Done: " + read input + else + [ -z "$2" ] && die "usage: $TODO_SH done \"TODO ITEM\"" + shift + input=$* + fi + + now=`date '+%Y-%m-%d'` + # remove priority once item is done + newtodo=$(sed -e "s/^(.) // ; s|^|&x $now |" <<<${input}) + echo "$newtodo" >> "$DONE_FILE" + [ $TODOTXT_VERBOSE -gt 0 ] && { + echo "TODO: '$input' marked as done." + } + [ $TODOTXT_GIT_ENABLED -eq 1 ] && \ + _commit "TODO: '$input' marked as done." $DONE_FILE + + cleanup;; + "help" ) if [ -t 1 ] ; then # STDOUT is a TTY if (exec which ${PAGER:-less} 2>/dev/null >/dev/null); then @@ -1008,7 +1027,7 @@ case $action in # If priority isn't set prepend if [ -z $priority ]; then - if sed -i.bak $item" s|^.*|$input &|" "$TODO_FILE"; then + if sed -i.bak $item" s|^.*|$input &|" "$TODO_FILE"; then [ $TODOTXT_VERBOSE -gt 0 ] && { newtodo=$(sed "$item!d" "$TODO_FILE") echo "$item: $newtodo" @@ -1016,7 +1035,7 @@ case $action in [ $TODOTXT_GIT_ENABLED -eq 1 ] && \ _commit "TODO: Prepended '$todo' w/ '$input' on line $item." \ $TODO_FILE - else + else echo "TODO: Error prepending task $item." fi # If priority is set, remove priority, prepend and add back priority @@ -1029,9 +1048,9 @@ case $action in [ $TODOTXT_GIT_ENABLED -eq 1 ] && \ _commit "TODO: Prepended '$todo' w/ '$input' on line $item." \ $TODO_FILE - else + else echo "TODO: Error prepending task $item." - fi + fi fi cleanup;;