From 6fc2d8191905d66c7307a55771f1c1aab813ec1e Mon Sep 17 00:00:00 2001 From: Paul Mansfield Date: Tue, 23 Feb 2010 23:05:03 +0000 Subject: [PATCH 1/4] Bugfix: Old versions of bash do not have =~ Versions of bash before 3.0 do not have =~ syntax to match on a regex. Changed to using a simple grep -c test instead. Fixes issues with osx and Solaris 9 and before. --- todo.sh | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/todo.sh b/todo.sh index 9164a2a..79d79ef 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 From e395ac78d8ab55f9bb7e6b6229be8e639096300d Mon Sep 17 00:00:00 2001 From: Gina Trapani Date: Fri, 26 Mar 2010 12:55:55 -0700 Subject: [PATCH 2/4] Fix line endings --- tests/t2000-multiline.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 From 5a5f3bd24d8c47b86854ef23e1550895625031ee Mon Sep 17 00:00:00 2001 From: Jared Cordasco Date: Tue, 13 Apr 2010 10:36:31 -0500 Subject: [PATCH 3/4] Tab fixes. --- todo.sh | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/todo.sh b/todo.sh index 79d79ef..3cbebe3 100755 --- a/todo.sh +++ b/todo.sh @@ -262,7 +262,7 @@ cleaninput() action_regexp="^\(append\|app\|prepend\|prep\|replace\)$" # Check which action we are being used in as this affects what cleaning we do - if [ `echo $action | grep -c $action_regexp` -eq 1 ]; 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 @@ -772,26 +772,26 @@ 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." - } - 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." + } + else + echo "$item is already marked done" + fi done if [ $TODOTXT_AUTO_ARCHIVE = 1 ]; then From d3c14201a5ba130dfb6c2afc5ae906ae428da672 Mon Sep 17 00:00:00 2001 From: Jared Cordasco Date: Tue, 13 Apr 2010 10:38:01 -0500 Subject: [PATCH 4/4] Initial version of done functionality w/ basic test. --- tests/t1550-done.sh | 52 +++++++++++++++++++++++++++++++++++++++++++++ todo.sh | 20 +++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100755 tests/t1550-done.sh diff --git a/tests/t1550-done.sh b/tests/t1550-done.sh new file mode 100755 index 0000000..583ae70 --- /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/todo.sh b/todo.sh index 3cbebe3..640b348 100755 --- a/todo.sh +++ b/todo.sh @@ -799,6 +799,26 @@ 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." + } + + cleanup;; + "help" ) if [ -t 1 ] ; then # STDOUT is a TTY if (exec which ${PAGER:-less} 2>/dev/null >/dev/null); then