From edac86a94df0530a49334c948104b3532f391542 Mon Sep 17 00:00:00 2001 From: Ingo Karkat Date: Tue, 25 May 2010 09:37:18 +0200 Subject: [PATCH 01/10] Aligned "todo.sh do" usage message with existing support of passing multiple numbers. --- tests/t1500-do.sh | 2 +- todo.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/t1500-do.sh b/tests/t1500-do.sh index 0ae79ca..a0a1ff6 100755 --- a/tests/t1500-do.sh +++ b/tests/t1500-do.sh @@ -8,7 +8,7 @@ test_description='do functionality test_todo_session 'do usage' <>> todo.sh do B B -usage: todo.sh do ITEM# +usage: todo.sh do ITEM#[, ITEM#, ITEM#, ...] === 1 EOF diff --git a/todo.sh b/todo.sh index e430bfb..5c051b1 100755 --- a/todo.sh +++ b/todo.sh @@ -765,7 +765,7 @@ case $action in fi;; "do" ) - errmsg="usage: $TODO_SH do ITEM#" + errmsg="usage: $TODO_SH do ITEM#[, ITEM#, ITEM#, ...]" # shift so we get arguments to the do request shift; From 9e5e6aef39bfe3da929aadd4f2131dad04c22a0b Mon Sep 17 00:00:00 2001 From: Ingo Karkat Date: Tue, 25 May 2010 10:10:09 +0200 Subject: [PATCH 02/10] Printing usage message if no ITEM# given to "todo.sh do". --- tests/t1500-do.sh | 6 ++++++ todo.sh | 1 + 2 files changed, 7 insertions(+) diff --git a/tests/t1500-do.sh b/tests/t1500-do.sh index a0a1ff6..5c89696 100755 --- a/tests/t1500-do.sh +++ b/tests/t1500-do.sh @@ -12,6 +12,12 @@ usage: todo.sh do ITEM#[, ITEM#, ITEM#, ...] === 1 EOF +test_todo_session 'do missing ITEM#' <>> todo.sh do +usage: todo.sh do ITEM#[, ITEM#, ITEM#, ...] +=== 1 +EOF + cat > todo.txt < Date: Tue, 25 May 2010 10:15:53 +0200 Subject: [PATCH 03/10] Corrected typo in comment. --- todo.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/todo.sh b/todo.sh index 73e2e9c..15e0a04 100755 --- a/todo.sh +++ b/todo.sh @@ -770,7 +770,7 @@ case $action in shift; [ "$#" -eq 0 ] && die "$errmsg" - # Split multiple do's, if comma seperated change to whitespace sepereated + # Split multiple do's, if comma separated change to whitespace separated # Loop the 'do' function for each item for item in `echo $* | tr ',' ' '`; do [ -z "$item" ] && die "$errmsg" From 370abbbf36733c43900d390281b8a61c6927faef Mon Sep 17 00:00:00 2001 From: Ingo Karkat Date: Tue, 25 May 2010 10:23:07 +0200 Subject: [PATCH 04/10] Aligned short help for "do" with correct long help text. --- todo.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/todo.sh b/todo.sh index 15e0a04..3acdfca 100755 --- a/todo.sh +++ b/todo.sh @@ -49,7 +49,7 @@ shorthelp() command [ACTIONS] del|rm NUMBER [TERM] dp|depri NUMBER - do NUMBER + do NUMBER[, NUMBER, NUMBER, ...] help list|ls [TERM...] listall|lsa [TERM...] From 5876cc04373dfeb4e9d8a9bf83123764238dfe14 Mon Sep 17 00:00:00 2001 From: Ingo Karkat Date: Tue, 25 May 2010 13:08:27 +0200 Subject: [PATCH 05/10] Bugfix: depri first checks validity of item argument syntax before searching for todo. Added testcase for the basic depriority command. --- tests/t1700-depri.sh | 44 ++++++++++++++++++++++++++++++++++++++++++++ todo.sh | 2 +- 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100755 tests/t1700-depri.sh diff --git a/tests/t1700-depri.sh b/tests/t1700-depri.sh new file mode 100755 index 0000000..24bad09 --- /dev/null +++ b/tests/t1700-depri.sh @@ -0,0 +1,44 @@ +#!/bin/sh + +test_description='basic depriority functionality +' +. ./test-lib.sh + +test_todo_session 'depriority usage' <>> todo.sh depri B B +usage: todo.sh depri ITEM# +=== 1 +EOF + +test_todo_session 'depriority nonexistant item' <>> todo.sh depri 42 +42: No such todo. +=== 1 +EOF + +cat > todo.txt <>> todo.sh -p list +2 (A) notice the sunflowers +1 (B) smell the uppercase Roses +flowers @outside +3 stop +-- +TODO: 3 of 3 tasks shown + +>>> todo.sh depri 1 +1: smell the uppercase Roses +flowers @outside +TODO: 1 deprioritized. + +>>> todo.sh -p list +2 (A) notice the sunflowers +1 smell the uppercase Roses +flowers @outside +3 stop +-- +TODO: 3 of 3 tasks shown +EOF + +test_done diff --git a/todo.sh b/todo.sh index 3acdfca..2894b40 100755 --- a/todo.sh +++ b/todo.sh @@ -745,9 +745,9 @@ case $action in item=$2 errmsg="usage: $TODO_SH depri ITEM#" + [[ "$item" = +([0-9]) ]] || die "$errmsg" todo=$(sed "$item!d" "$TODO_FILE") [ -z "$todo" ] && die "$item: No such todo." - [[ "$item" = +([0-9]) ]] || die "$errmsg" sed -e $item"s/^(.) //" "$TODO_FILE" > /dev/null 2>&1 From 15084aa4d770cc3d17b1b03dec5aca272aa2e203 Mon Sep 17 00:00:00 2001 From: Ingo Karkat Date: Tue, 25 May 2010 13:27:28 +0200 Subject: [PATCH 06/10] 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#, ...]" From d52a1a7bd22b5e3ccfb309919e98f379a99ec0cf Mon Sep 17 00:00:00 2001 From: Ingo Karkat Date: Tue, 25 May 2010 13:42:04 +0200 Subject: [PATCH 07/10] Bugfix: Doubled help output on TTY with PAGER. On "todo.sh help", first the long help output is printed through the pager, and after quitting the pager the output is printed once more in full. Didn't write a test for this, as this requires a connected terminal and cannot be observed in the test harness. Fix: The "exec" command has no effect inside a pipe; added an explicit "exit 0". Also simplified check for PAGER: No "exec" necessary, combining stderr and stdout. Also added quoting for PAGER so that it can contain spaces. --- todo.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/todo.sh b/todo.sh index 172dea8..d7136f9 100755 --- a/todo.sh +++ b/todo.sh @@ -807,9 +807,9 @@ case $action in "help" ) if [ -t 1 ] ; then # STDOUT is a TTY - if (exec which ${PAGER:-less} 2>/dev/null >/dev/null); then + if which "${PAGER:-less}" >/dev/null 2>&1; then # we have a working PAGER (or less as a default) - help | exec ${PAGER:-less} + help | "${PAGER:-less}" && exit 0 fi fi help # just in case something failed above, we go ahead and just spew to STDOUT From 391064e4f0235476084c6b63c5a01b7cef9fa9eb Mon Sep 17 00:00:00 2001 From: Ingo Karkat Date: Thu, 27 May 2010 14:49:07 +0200 Subject: [PATCH 08/10] Replaced "NUMBER" with "ITEM#" in help and shorthelp. This makes the help output consistent with the syntax error messages of individual commands. --- todo.sh | 58 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/todo.sh b/todo.sh index d7136f9..91a7413 100755 --- a/todo.sh +++ b/todo.sh @@ -44,12 +44,12 @@ shorthelp() addto DEST "TEXT TO ADD" addm "THINGS I NEED TO DO MORE THINGS I NEED TO DO" - append|app NUMBER "TEXT TO APPEND" + append|app ITEM# "TEXT TO APPEND" archive command [ACTIONS] - del|rm NUMBER [TERM] - dp|depri NUMBER[, NUMBER, NUMBER, ...] - do NUMBER[, NUMBER, NUMBER, ...] + del|rm ITEM# [TERM] + dp|depri ITEM#[, ITEM#, ITEM#, ...] + do ITEM#[, ITEM#, ITEM#, ...] help list|ls [TERM...] listall|lsa [TERM...] @@ -57,10 +57,10 @@ shorthelp() listfile|lf SRC [TERM...] listpri|lsp [PRIORITY] listproj|lsprj - move|mv NUMBER DEST [SRC] - prepend|prep NUMBER "TEXT TO PREPEND" - pri|p NUMBER PRIORITY - replace NUMBER "UPDATED TODO" + move|mv ITEM# DEST [SRC] + prepend|prep ITEM# "TEXT TO PREPEND" + pri|p ITEM# PRIORITY + replace ITEM# "UPDATED TODO" report See "help" for more details. @@ -91,9 +91,9 @@ help() Adds a line of text to any file located in the todo.txt directory. For example, addto inbox.txt "decide about vacation" - append NUMBER "TEXT TO APPEND" - app NUMBER "TEXT TO APPEND" - Adds TEXT TO APPEND to the end of the todo on line NUMBER. + append ITEM# "TEXT TO APPEND" + app ITEM# "TEXT TO APPEND" + Adds TEXT TO APPEND to the end of the todo on line ITEM#. Quotes optional. archive @@ -103,18 +103,18 @@ help() Runs the remaining arguments using only todo.sh builtins. Will not call any .todo.actions.d scripts. - del NUMBER [TERM] - rm NUMBER [TERM] - Deletes the item on line NUMBER in todo.txt. + del ITEM# [TERM] + rm ITEM# [TERM] + Deletes the item on line ITEM# in todo.txt. If term specified, deletes only the term from the line. - depri NUMBER[, NUMBER, NUMBER, ...] - dp NUMBER[, NUMBER, NUMBER, ...] + depri ITEM#[, ITEM#, ITEM#, ...] + dp ITEM#[, ITEM#, ITEM#, ...] Deprioritizes (removes the priority) from the item - on line NUMBER in todo.txt. + on line ITEM# in todo.txt. - do NUMBER[, NUMBER, NUMBER, ...] - Marks item(s) on line NUMBER as done in todo.txt. + do ITEM#[, ITEM#, ITEM#, ...] + Marks item(s) on line ITEM# as done in todo.txt. help Display this help message. @@ -149,26 +149,26 @@ help() lsprj Lists all the projects that start with the + sign in todo.txt. - move NUMBER DEST [SRC] - mv NUMBER DEST [SRC] + move ITEM# DEST [SRC] + mv ITEM# DEST [SRC] Moves a line from source text file (SRC) to destination text file (DEST). Both source and destination file must be located in the directory defined in the configuration directory. When SRC is not defined it's by default todo.txt. - prepend NUMBER "TEXT TO PREPEND" - prep NUMBER "TEXT TO PREPEND" - Adds TEXT TO PREPEND to the beginning of the todo on line NUMBER. + prepend ITEM# "TEXT TO PREPEND" + prep ITEM# "TEXT TO PREPEND" + Adds TEXT TO PREPEND to the beginning of the todo on line ITEM#. Quotes optional. - pri NUMBER PRIORITY - p NUMBER PRIORITY - Adds PRIORITY to todo on line NUMBER. If the item is already + pri ITEM# PRIORITY + p ITEM# PRIORITY + Adds PRIORITY to todo on line ITEM#. If the item is already prioritized, replaces current priority with new PRIORITY. PRIORITY must be an uppercase letter between A and Z. - replace NUMBER "UPDATED TODO" - Replaces todo on line NUMBER with UPDATED TODO. + replace ITEM# "UPDATED TODO" + Replaces todo on line ITEM# with UPDATED TODO. report Adds the number of open todo's and closed done's to report.txt. From 8bddb081961bb0d5c953a318067ae6bd4bdc3db3 Mon Sep 17 00:00:00 2001 From: Ingo Karkat Date: Thu, 27 May 2010 15:11:33 +0200 Subject: [PATCH 09/10] Cleaned up terms in help. The help and messages now consistently use "task"; the use of "todo" is deprecated. "ITEM#" is used to refer to the number of the task. This may be more consistently expressed as "TASK#". On the other hand, that could lead to more confusion between TASK (the text) and TASK# (the number). The implementation still leaks through in the phrase "on line ITEM#"; ideally, todo.txt would abstract over the line-based textual representation. --- todo.sh | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/todo.sh b/todo.sh index 91a7413..5d075bd 100755 --- a/todo.sh +++ b/todo.sh @@ -93,11 +93,11 @@ help() append ITEM# "TEXT TO APPEND" app ITEM# "TEXT TO APPEND" - Adds TEXT TO APPEND to the end of the todo on line ITEM#. + Adds TEXT TO APPEND to the end of the task on line ITEM#. Quotes optional. archive - Moves done items from todo.txt to done.txt and removes blank lines. + Moves all done tasks from todo.txt to done.txt and removes blank lines. command [ACTIONS] Runs the remaining arguments using only todo.sh builtins. @@ -105,23 +105,23 @@ help() del ITEM# [TERM] rm ITEM# [TERM] - Deletes the item on line ITEM# in todo.txt. - If term specified, deletes only the term from the line. + Deletes the task on line ITEM# in todo.txt. + If TERM specified, deletes only TERM from the task. depri ITEM#[, ITEM#, ITEM#, ...] dp ITEM#[, ITEM#, ITEM#, ...] - Deprioritizes (removes the priority) from the item + Deprioritizes (removes the priority) from the task(s) on line ITEM# in todo.txt. do ITEM#[, ITEM#, ITEM#, ...] - Marks item(s) on line ITEM# as done in todo.txt. + Marks task(s) on line ITEM# as done in todo.txt. help Display this help message. list [TERM...] ls [TERM...] - Displays all todo's that contain TERM(s) sorted by priority with line + Displays all tasks that contain TERM(s) sorted by priority with line numbers. If no TERM specified, lists entire todo.txt. listall [TERM...] @@ -142,8 +142,8 @@ help() listpri [PRIORITY] lsp [PRIORITY] - Displays all items prioritized PRIORITY. - If no PRIORITY specified, lists all prioritized items. + Displays all tasks prioritized PRIORITY. + If no PRIORITY specified, lists all prioritized tasks. listproj lsprj @@ -158,20 +158,20 @@ help() prepend ITEM# "TEXT TO PREPEND" prep ITEM# "TEXT TO PREPEND" - Adds TEXT TO PREPEND to the beginning of the todo on line ITEM#. + Adds TEXT TO PREPEND to the beginning of the task on line ITEM#. Quotes optional. pri ITEM# PRIORITY p ITEM# PRIORITY - Adds PRIORITY to todo on line ITEM#. If the item is already + Adds PRIORITY to task on line ITEM#. If the task is already prioritized, replaces current priority with new PRIORITY. PRIORITY must be an uppercase letter between A and Z. replace ITEM# "UPDATED TODO" - Replaces todo on line ITEM# with UPDATED TODO. + Replaces task on line ITEM# with UPDATED TODO. report - Adds the number of open todo's and closed done's to report.txt. + Adds the number of open tasks and done tasks to report.txt. From 8ff3a7ce4af89df7e1abafcad59e1d7d10ef6577 Mon Sep 17 00:00:00 2001 From: Ingo Karkat Date: Thu, 27 May 2010 15:48:37 +0200 Subject: [PATCH 10/10] Cleaned up terms in command error messages. The messages now consistently use "task"; the use of "todo" is deprecated. --- tests/t1100-replace.sh | 2 +- tests/t1600-append.sh | 2 +- tests/t1700-depri.sh | 2 +- tests/t9999-testsuite_example.sh | 4 ++-- todo.sh | 12 ++++++------ 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/tests/t1100-replace.sh b/tests/t1100-replace.sh index e39ad4c..e796052 100755 --- a/tests/t1100-replace.sh +++ b/tests/t1100-replace.sh @@ -87,7 +87,7 @@ EOF test_todo_session 'replace error' << EOF >>> todo.sh replace 10 "hej!" === 1 -10: No such todo. +10: No such task. EOF test_done diff --git a/tests/t1600-append.sh b/tests/t1600-append.sh index c56bd79..885074e 100755 --- a/tests/t1600-append.sh +++ b/tests/t1600-append.sh @@ -41,7 +41,7 @@ EOF test_todo_session 'append error' << EOF >>> todo.sh append 10 "hej!" === 1 -10: No such todo. +10: No such task. EOF test_done diff --git a/tests/t1700-depri.sh b/tests/t1700-depri.sh index 3bc3b32..b401c62 100755 --- a/tests/t1700-depri.sh +++ b/tests/t1700-depri.sh @@ -12,7 +12,7 @@ EOF test_todo_session 'depriority nonexistant item' <>> todo.sh depri 42 -42: No such todo. +42: No such task. === 1 EOF diff --git a/tests/t9999-testsuite_example.sh b/tests/t9999-testsuite_example.sh index 620a492..13d6fcc 100755 --- a/tests/t9999-testsuite_example.sh +++ b/tests/t9999-testsuite_example.sh @@ -108,7 +108,7 @@ usage: todo.sh append ITEM# "TEXT TO APPEND" TODO: 5 of 5 tasks shown >>> todo.sh append 10 "hej!" -10: No such todo. +10: No such task. === 1 >>> todo.sh -p list @@ -121,7 +121,7 @@ TODO: 5 of 5 tasks shown TODO: 5 of 5 tasks shown >>> todo.sh do 10 -10: No such todo. +10: No such task. === 1 >>> todo.sh -p list diff --git a/todo.sh b/todo.sh index 5d075bd..50f8e05 100755 --- a/todo.sh +++ b/todo.sh @@ -680,7 +680,7 @@ case $action in [ -z "$item" ] && die "$errmsg" [[ "$item" = +([0-9]) ]] || die "$errmsg" todo=$(sed "$item!d" "$TODO_FILE") - [ -z "$todo" ] && die "$item: No such todo." + [ -z "$todo" ] && die "$item: No such task." if [[ -z "$1" && $TODOTXT_FORCE = 0 ]]; then echo -n "Append: " read input @@ -734,7 +734,7 @@ case $action in echo "TODO: No tasks were deleted." fi else - echo "$item: No such todo." + echo "$item: No such task." fi else sed -i.bak -e $item"s/$3/ /g" "$TODO_FILE" @@ -751,7 +751,7 @@ case $action in for item in `echo $* | tr ',' ' '`; do [[ "$item" = +([0-9]) ]] || die "$errmsg" todo=$(sed "$item!d" "$TODO_FILE") - [ -z "$todo" ] && die "$item: No such todo." + [ -z "$todo" ] && die "$item: No such task." sed -e $item"s/^(.) //" "$TODO_FILE" > /dev/null 2>&1 @@ -782,7 +782,7 @@ case $action in [[ "$item" = +([0-9]) ]] || die "$errmsg" todo=$(sed "$item!d" "$TODO_FILE") - [ -z "$todo" ] && die "$item: No such todo." + [ -z "$todo" ] && die "$item: No such task." # Check if this item has already been done if [ `echo $todo | grep -c "^x "` -eq 0 ] ; then @@ -926,7 +926,7 @@ case $action in [[ "$item" = +([0-9]) ]] || die "$errmsg" todo=$(sed "$item!d" "$TODO_FILE") - [ -z "$todo" ] && die "$item: No such todo." + [ -z "$todo" ] && die "$item: No such task." if [[ -z "$1" && $TODOTXT_FORCE = 0 ]]; then echo -n "Prepend: " @@ -998,7 +998,7 @@ note: PRIORITY must be anywhere from A to Z." [[ "$item" = +([0-9]) ]] || die "$errmsg" todo=$(sed "$item!d" "$TODO_FILE") - [ -z "$todo" ] && die "$item: No such todo." + [ -z "$todo" ] && die "$item: No such task." # Test for then set priority if [ `sed "$item!d" "$TODO_FILE"|grep -c "^(\\w)"` -eq 1 ]; then