From 52b9db310fa09a9a18c1fdf1b9be87f05b375665 Mon Sep 17 00:00:00 2001 From: Ingo Karkat Date: Thu, 3 Jun 2010 22:13:17 +0200 Subject: [PATCH 1/9] Removed unnecessary echo within echo. --- todo.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/todo.sh b/todo.sh index 50f8e05..f8c4c5e 100755 --- a/todo.sh +++ b/todo.sh @@ -760,7 +760,7 @@ case $action in sed -i.bak -e $item"s/^(.) //" "$TODO_FILE" [ $TODOTXT_VERBOSE -gt 0 ] && { NEWTODO=$(sed "$item!d" "$TODO_FILE") - echo "`echo "$item: $NEWTODO"`" + echo "$item: $NEWTODO" echo "TODO: $item deprioritized." } else @@ -982,7 +982,7 @@ note: PRIORITY must be anywhere from A to Z." sed -i.bak -e $item"s/^(.) //" -e $item"s/^/($newpri) /" "$TODO_FILE" [ $TODOTXT_VERBOSE -gt 0 ] && { NEWTODO=$(sed "$item!d" "$TODO_FILE") - echo "`echo "$item: $NEWTODO"`" + echo "$item: $NEWTODO" echo "TODO: $item prioritized ($newpri)." } cleanup From 69e756a2cde9b5eb5044fdfbda8ddceb63b2120d Mon Sep 17 00:00:00 2001 From: Ingo Karkat Date: Fri, 4 Jun 2010 16:22:15 +0200 Subject: [PATCH 2/9] Bugfix: _list() cannot handle filter TERM starting with space. Added proper quoting at check for search term starting with a dash. Added tests for ls use with TERM, both with literal text and regexps. Seems that use case was missing from the tests so far. Extra: Removed unnecessary "$@" argument to for() loop. --- tests/t1300-ls.sh | 41 +++++++++++++++++++++++++++++++++++++++++ todo.sh | 4 ++-- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/tests/t1300-ls.sh b/tests/t1300-ls.sh index fb47438..a374c5b 100755 --- a/tests/t1300-ls.sh +++ b/tests/t1300-ls.sh @@ -53,6 +53,47 @@ test_todo_session 'checking TODOTXT_FINAL_FILTER' <>> todo.sh ls second +3 bbb yyy this line should be second. +-- +TODO: 1 of 3 tasks shown + +>>> todo.sh ls "should be f" +2 aaa zzz this line should be first. +-- +TODO: 1 of 3 tasks shown + +>>> todo.sh ls " zzz" +2 aaa zzz this line should be first. +-- +TODO: 1 of 3 tasks shown +EOF + +# +# check the filtering of TERM with regexp +# +test_todo_session 'checking filtering of TERM with regexp' <>> todo.sh ls "ir[ds]" +2 aaa zzz this line should be first. +1 ccc xxx this line should be third. +-- +TODO: 2 of 3 tasks shown + +>>> todo.sh ls "f.*t" +2 aaa zzz this line should be first. +-- +TODO: 1 of 3 tasks shown + +>>> todo.sh ls "ir[ds]" xxx +1 ccc xxx this line should be third. +-- +TODO: 1 of 3 tasks shown +EOF + # # check the x command line option # diff --git a/todo.sh b/todo.sh index f8c4c5e..b82c234 100755 --- a/todo.sh +++ b/todo.sh @@ -515,10 +515,10 @@ _list() { ## Prefix the filter_command with the pre_filter_command filter_command="${pre_filter_command:-}" - for search_term in "$@" + for search_term do ## See if the first character of $search_term is a dash - if [ ${search_term:0:1} != '-' ] + if [ "${search_term:0:1}" != '-' ] then ## First character isn't a dash: hide lines that don't match ## this $search_term From 70b2c4ca40c9458671fc3c10e1d239d9967a210a Mon Sep 17 00:00:00 2001 From: Ingo Karkat Date: Fri, 4 Jun 2010 16:50:09 +0200 Subject: [PATCH 3/9] Made verbose message of _addto() consistent with other task messages. In verbose mode, commands first print the updated task, then summarize the change in the following line. The add/addm/addto commands deviated from this, using "TODO: '' added on line N." This change splits this into two separate lines, obsoletes the implementation jargon of "line", and makes it easier to visually parse the message. This is also a preparation for a possible future use of a _list()-like function, so that the updated task is processed and highlighted like the normal task output. --- tests/t1000-addlist.sh | 12 ++++++++---- tests/t1010-add-date.sh | 12 ++++++++---- tests/t1020-addtolistfile.sh | 12 ++++++++---- tests/t1030-addto-date.sh | 12 ++++++++---- tests/t1200-pri.sh | 3 ++- tests/t2000-multiline.sh | 12 ++++++++---- tests/t9999-testsuite_example.sh | 9 ++++++--- todo.sh | 3 ++- 8 files changed, 50 insertions(+), 25 deletions(-) diff --git a/tests/t1000-addlist.sh b/tests/t1000-addlist.sh index f881f8b..42e16e8 100755 --- a/tests/t1000-addlist.sh +++ b/tests/t1000-addlist.sh @@ -12,7 +12,8 @@ command work, including support for filtering. # test_todo_session 'basic add/list' <>> todo.sh add notice the daisies -TODO: 'notice the daisies' added on line 1. +1: notice the daisies +TODO: 1 added. >>> todo.sh list 1 notice the daisies @@ -20,7 +21,8 @@ TODO: 'notice the daisies' added on line 1. TODO: 1 of 1 tasks shown >>> todo.sh add smell the roses -TODO: 'smell the roses' added on line 2. +2: smell the roses +TODO: 2 added. >>> todo.sh list 1 notice the daisies @@ -46,7 +48,8 @@ EOF test_todo_session 'case-insensitive filtering' <>> todo.sh add smell the uppercase Roses -TODO: 'smell the uppercase Roses' added on line 3. +3: smell the uppercase Roses +TODO: 3 added. >>> todo.sh list roses 2 smell the roses @@ -57,7 +60,8 @@ EOF test_todo_session 'add with &' <>> todo.sh add "dig the garden & water the flowers" -TODO: 'dig the garden & water the flowers' added on line 4. +4: dig the garden & water the flowers +TODO: 4 added. >>> todo.sh list 4 dig the garden & water the flowers diff --git a/tests/t1010-add-date.sh b/tests/t1010-add-date.sh index 50629ca..603d199 100755 --- a/tests/t1010-add-date.sh +++ b/tests/t1010-add-date.sh @@ -12,7 +12,8 @@ a date to each item. # test_todo_session 'cmd line first day' <>> todo.sh -t add notice the daisies -TODO: '2009-02-13 notice the daisies' added on line 1. +1: 2009-02-13 notice the daisies +TODO: 1 added. >>> todo.sh list 1 2009-02-13 notice the daisies @@ -24,7 +25,8 @@ test_tick test_todo_session 'cmd line second day' <>> todo.sh -t add smell the roses -TODO: '2009-02-14 smell the roses' added on line 2. +2: 2009-02-14 smell the roses +TODO: 2 added. >>> todo.sh list 1 2009-02-13 notice the daisies @@ -37,7 +39,8 @@ test_tick test_todo_session 'cmd line third day' <>> todo.sh -t add mow the lawn -TODO: '2009-02-15 mow the lawn' added on line 3. +3: 2009-02-15 mow the lawn +TODO: 3 added. >>> todo.sh list 1 2009-02-13 notice the daisies @@ -55,7 +58,8 @@ test_tick 3600 test_todo_session 'config file third day' <>> todo.sh add take out the trash -TODO: '2009-02-15 take out the trash' added on line 4. +4: 2009-02-15 take out the trash +TODO: 4 added. >>> todo.sh list 1 2009-02-13 notice the daisies diff --git a/tests/t1020-addtolistfile.sh b/tests/t1020-addtolistfile.sh index 760a8f5..575fb16 100755 --- a/tests/t1020-addtolistfile.sh +++ b/tests/t1020-addtolistfile.sh @@ -19,7 +19,8 @@ touch "$HOME/garden.txt" test_todo_session 'basic addto/listfile' <>> todo.sh addto garden.txt notice the daisies -GARDEN: 'notice the daisies' added on line 1. +1: notice the daisies +GARDEN: 1 added. >>> todo.sh listfile garden.txt 1 notice the daisies @@ -27,7 +28,8 @@ GARDEN: 'notice the daisies' added on line 1. GARDEN: 1 of 1 tasks shown >>> todo.sh addto garden.txt smell the roses -GARDEN: 'smell the roses' added on line 2. +2: smell the roses +GARDEN: 2 added. >>> todo.sh listfile garden.txt 1 notice the daisies @@ -53,7 +55,8 @@ EOF test_todo_session 'case-insensitive filtering' <>> todo.sh addto garden.txt smell the uppercase Roses -GARDEN: 'smell the uppercase Roses' added on line 3. +3: smell the uppercase Roses +GARDEN: 3 added. >>> todo.sh listfile garden.txt roses 2 smell the roses @@ -64,7 +67,8 @@ EOF test_todo_session 'addto with &' <>> todo.sh addto garden.txt "dig the garden & water the flowers" -GARDEN: 'dig the garden & water the flowers' added on line 4. +4: dig the garden & water the flowers +GARDEN: 4 added. >>> todo.sh listfile garden.txt 4 dig the garden & water the flowers diff --git a/tests/t1030-addto-date.sh b/tests/t1030-addto-date.sh index 8f05aa4..899794d 100755 --- a/tests/t1030-addto-date.sh +++ b/tests/t1030-addto-date.sh @@ -14,7 +14,8 @@ touch "$HOME/garden.txt" # test_todo_session 'cmd line first day' <>> todo.sh -t addto garden.txt notice the daisies -GARDEN: '2009-02-13 notice the daisies' added on line 1. +1: 2009-02-13 notice the daisies +GARDEN: 1 added. >>> todo.sh listfile garden.txt 1 2009-02-13 notice the daisies @@ -26,7 +27,8 @@ test_tick test_todo_session 'cmd line second day' <>> todo.sh -t addto garden.txt smell the roses -GARDEN: '2009-02-14 smell the roses' added on line 2. +2: 2009-02-14 smell the roses +GARDEN: 2 added. >>> todo.sh listfile garden.txt 1 2009-02-13 notice the daisies @@ -39,7 +41,8 @@ test_tick test_todo_session 'cmd line third day' <>> todo.sh -t addto garden.txt mow the lawn -GARDEN: '2009-02-15 mow the lawn' added on line 3. +3: 2009-02-15 mow the lawn +GARDEN: 3 added. >>> todo.sh listfile garden.txt 1 2009-02-13 notice the daisies @@ -57,7 +60,8 @@ test_tick 3600 test_todo_session 'config file third day' <>> todo.sh addto garden.txt take out the trash -GARDEN: '2009-02-15 take out the trash' added on line 4. +4: 2009-02-15 take out the trash +GARDEN: 4 added. >>> todo.sh listfile garden.txt 1 2009-02-13 notice the daisies diff --git a/tests/t1200-pri.sh b/tests/t1200-pri.sh index 4326470..b8742e2 100755 --- a/tests/t1200-pri.sh +++ b/tests/t1200-pri.sh @@ -75,7 +75,8 @@ TODO: 2 prioritized (A). TODO: 2 of 3 tasks shown >>> todo.sh add "smell the coffee +wakeup" -TODO: 'smell the coffee +wakeup' added on line 4. +4: smell the coffee +wakeup +TODO: 4 added. >>> todo.sh -p list 2 (A) notice the sunflowers diff --git a/tests/t2000-multiline.sh b/tests/t2000-multiline.sh index 43ab362..3eaf742 100755 --- a/tests/t2000-multiline.sh +++ b/tests/t2000-multiline.sh @@ -33,7 +33,8 @@ fi ## Add test # Create the expected file -echo "TODO: 'eat apples eat oranges drink milk' added on line 2.">$HOME/expect.multi +echo "2: eat apples eat oranges drink milk +TODO: 2 added.">$HOME/expect.multi test_expect_success 'multiline squash item add' ' ( @@ -108,9 +109,12 @@ fi ## Multiple line addition # Create the expected file -echo "TODO: 'eat apples' added on line 2." > $HOME/expect.multi -echo "TODO: 'eat oranges' added on line 3." >>$HOME/expect.multi -echo "TODO: 'drink milk' added on line 4." >> $HOME/expect.multi +echo "2: eat apples +TODO: 2 added." > $HOME/expect.multi +echo "3: eat oranges +TODO: 3 added." >>$HOME/expect.multi +echo "4: drink milk +TODO: 4 added." >> $HOME/expect.multi test_expect_success 'actual multiline add' ' ( diff --git a/tests/t9999-testsuite_example.sh b/tests/t9999-testsuite_example.sh index 13d6fcc..64994e3 100755 --- a/tests/t9999-testsuite_example.sh +++ b/tests/t9999-testsuite_example.sh @@ -48,7 +48,8 @@ TODO: 2 marked as done. TODO: 4 of 4 tasks shown >>> todo.sh add "make the coffee +wakeup" -TODO: 'make the coffee +wakeup' added on line 5. +5: make the coffee +wakeup +TODO: 5 added. >>> todo.sh -p list coffee 5 make the coffee +wakeup @@ -57,7 +58,8 @@ TODO: 'make the coffee +wakeup' added on line 5. TODO: 2 of 5 tasks shown >>> todo.sh add "visit http://example.com" -TODO: 'visit http://example.com' added on line 6. +6: visit http://example.com +TODO: 6 added. >>> todo.sh -p list 1 (B) smell the uppercase Roses +flowers @outside @@ -134,7 +136,8 @@ TODO: 5 of 5 tasks shown TODO: 5 of 5 tasks shown >>> todo.sh add "the coffee +wakeup" -TODO: 'the coffee +wakeup' added on line 6. +6: the coffee +wakeup +TODO: 6 added. >>> todo.sh -p list 1 (B) smell the uppercase Roses +flowers @outside diff --git a/todo.sh b/todo.sh index b82c234..fc1fd16 100755 --- a/todo.sh +++ b/todo.sh @@ -484,7 +484,8 @@ _addto() { TASKNUM=$(sed -n '$ =' "$file") BASE=$(basename "$file") PREFIX=$(echo ${BASE%%.[^.]*} | tr [a-z] [A-Z]) - echo "${PREFIX}: '$input' added on line $TASKNUM." + echo "$TASKNUM: $input" + echo "${PREFIX}: $TASKNUM added." } } From e7b5841721e9029343d987ab8730cbf2b2e568c0 Mon Sep 17 00:00:00 2001 From: Glyn Faulkner Date: Mon, 21 Jun 2010 15:25:42 +0200 Subject: [PATCH 4/9] Generalizes the PRI_X color support to all priorities. It allows you to assign a distinct color to any priority, not just A, B and C. Submitted to the todo.txt mailing list on 3-Jun-2010; committed on behalf of the author because there was no follow-up; cp. http://tech.groups.yahoo.com/group/todotxt/message/2619 Also committed this because it fixes a sed expression error when there are spaces in a $PRI_... variable, which occurred in my integration with Conky. Note: This commit obsoletes and replaces the previous fix to colorization in commit 8b7e2e6aada05fd824cb. Added tests for highlighting of priorities. --- tests/t1330-ls-highlighting.sh | 114 +++++++++++++++++++++++++++++++++ todo.sh | 22 +++---- 2 files changed, 125 insertions(+), 11 deletions(-) create mode 100755 tests/t1330-ls-highlighting.sh diff --git a/tests/t1330-ls-highlighting.sh b/tests/t1330-ls-highlighting.sh new file mode 100755 index 0000000..c3c3558 --- /dev/null +++ b/tests/t1330-ls-highlighting.sh @@ -0,0 +1,114 @@ +#!/bin/sh +# + +test_description='list highlighting + +This test checks the highlighting (with colors) of prioritized tasks. +' +. ./test-lib.sh + +TEST_TODO_=todo.cfg + +# +# check the highlighting of prioritized tasks +# +cat > todo.txt <>> todo.sh ls +1 (A) @con01 +prj01 -- Some project 01 task, pri A +2 (B) @con02 +prj02 -- Some project 02 task, pri B +3 (C) @con01 +prj01 -- Some project 01 task, pri C +4 (D) @con02 +prj02 -- Some project 02 task, pri D +5 (E) @con01 +prj01 -- Some project 01 task, pri E +6 (Z) @con02 +prj02 -- Some project 02 task, pri Z +7 @con01 +prj01 -- Some project 01 task, no priority +8 @con02 +prj02 -- Some project 02 task, no priority +-- +TODO: 8 of 8 tasks shown +EOF + +# +# check changing the color definitions into something other than ANSI color +# escape sequences +# +TEST_TODO_CUSTOM=todo-custom.cfg +cat todo.cfg > "$TEST_TODO_CUSTOM" +cat >> "$TEST_TODO_CUSTOM" <<'EOF' +export YELLOW='${color yellow}' +export GREEN='${color green}' +export LIGHT_BLUE='${color LightBlue}' +export WHITE='${color white}' +export DEFAULT='${color}' +export PRI_A=$YELLOW +export PRI_B=$GREEN +export PRI_C=$LIGHT_BLUE +export PRI_X=$WHITE +EOF +test_todo_session 'customized highlighting' <<'EOF' +>>> todo.sh -d "$TEST_TODO_CUSTOM" ls +${color yellow}1 (A) @con01 +prj01 -- Some project 01 task, pri A${color} +${color green}2 (B) @con02 +prj02 -- Some project 02 task, pri B${color} +${color LightBlue}3 (C) @con01 +prj01 -- Some project 01 task, pri C${color} +${color white}4 (D) @con02 +prj02 -- Some project 02 task, pri D${color} +${color white}5 (E) @con01 +prj01 -- Some project 01 task, pri E${color} +${color white}6 (Z) @con02 +prj02 -- Some project 02 task, pri Z${color} +7 @con01 +prj01 -- Some project 01 task, no priority +8 @con02 +prj02 -- Some project 02 task, no priority +-- +TODO: 8 of 8 tasks shown +EOF + +# +# check defining highlightings for more priorities than the default A, B, C +# +TEST_TODO_ADDITIONAL=todo-additional.cfg +cat todo.cfg > "$TEST_TODO_ADDITIONAL" +cat >> "$TEST_TODO_ADDITIONAL" <<'EOF' +export PRI_E=$BROWN +export PRI_Z=$LIGHT_PURPLE +EOF +test_todo_session 'additional highlighting pri E+Z' <<'EOF' +>>> todo.sh -d "$TEST_TODO_ADDITIONAL" ls +1 (A) @con01 +prj01 -- Some project 01 task, pri A +2 (B) @con02 +prj02 -- Some project 02 task, pri B +3 (C) @con01 +prj01 -- Some project 01 task, pri C +4 (D) @con02 +prj02 -- Some project 02 task, pri D +5 (E) @con01 +prj01 -- Some project 01 task, pri E +6 (Z) @con02 +prj02 -- Some project 02 task, pri Z +7 @con01 +prj01 -- Some project 01 task, no priority +8 @con02 +prj02 -- Some project 02 task, no priority +-- +TODO: 8 of 8 tasks shown +EOF + +# check changing the fallback highlighting for undefined priorities +# +TEST_TODO_PRI_X=todo-pri-x.cfg +cat todo.cfg > "$TEST_TODO_PRI_X" +cat >> "$TEST_TODO_PRI_X" <<'EOF' +export PRI_X=$BROWN +EOF +test_todo_session 'different highlighting for pri X' <<'EOF' +>>> todo.sh -d "$TEST_TODO_PRI_X" ls +1 (A) @con01 +prj01 -- Some project 01 task, pri A +2 (B) @con02 +prj02 -- Some project 02 task, pri B +3 (C) @con01 +prj01 -- Some project 01 task, pri C +4 (D) @con02 +prj02 -- Some project 02 task, pri D +5 (E) @con01 +prj01 -- Some project 01 task, pri E +6 (Z) @con02 +prj02 -- Some project 02 task, pri Z +7 @con01 +prj01 -- Some project 01 task, no priority +8 @con02 +prj02 -- Some project 02 task, no priority +-- +TODO: 8 of 8 tasks shown +EOF + +test_done diff --git a/todo.sh b/todo.sh index cad4312..9e54ee8 100755 --- a/todo.sh +++ b/todo.sh @@ -460,9 +460,9 @@ ACTION=${1:-$TODOTXT_DEFAULT_ACTION} [ -f "$REPORT_FILE" ] || cp /dev/null "$REPORT_FILE" if [ $TODOTXT_PLAIN = 1 ]; then - PRI_A=$NONE - PRI_B=$NONE - PRI_C=$NONE + for clr in ${!PRI_@}; do + export $clr=$NONE + done PRI_X=$NONE DEFAULT=$NONE fi @@ -570,14 +570,14 @@ _list() { s/^ /0/; ''' \ | eval ${TODOTXT_SORT_COMMAND} \ - | sed ''' - /^[0-9]\{'$PADDING'\} x /! { - /(A)/ s|^.*|'$PRI_A'&'$DEFAULT'| - /(B)/ s|^.*|'$PRI_B'&'$DEFAULT'| - /(C)/ s|^.*|'$PRI_C'&'$DEFAULT'| - /([D-Z])/ s|^.*|'$PRI_X'&'$DEFAULT'| - } - ''' \ + | awk '''{ + pos = match($0, /\([A-Z]\)/) + if( pos > 0 && match($0, /^[0-9]+ x /) != 1 ) { + clr=ENVIRON["PRI_" substr($0, pos+1, 1)] + str = ( clr ? clr : ENVIRON["PRI_X"] ) $0 ENVIRON["DEFAULT"] + gsub( /\\+033/, "\033", str) ; print str + } else { print } + }''' \ | sed ''' s/'${HIDE_PRIORITY_SUBSTITUTION:-^}'//g s/'${HIDE_PROJECTS_SUBSTITUTION:-^}'//g From 37fcc53b26f0e619df4de7a2249c1ba60e109694 Mon Sep 17 00:00:00 2001 From: Ingo Karkat Date: Tue, 29 Jun 2010 08:00:24 +0200 Subject: [PATCH 5/9] BUG: test_todo_session with error exit doesn't work BUG 1: didn't report non-error exit A test that enforces a non-zero exit code via "=== N" would succeed when the command under test returned with success (0); only differing exit codes would be correctly reported. Corrected logic so that the check for the exit code would always run, not just when the command under test failed. BUG 2: too early evaluation of $? In the test expression, the evaluation of $? must be deferred until the test expression itself is evaluated. Escaping $? to prevent premature evaluation in the context of the expression definition. --- tests/test-lib.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test-lib.sh b/tests/test-lib.sh index 34cd9e4..efe8960 100644 --- a/tests/test-lib.sh +++ b/tests/test-lib.sh @@ -542,7 +542,7 @@ test_todo_session () { if [ $status = 0 ]; then test_expect_success "$1 $subnum" "$cmd > output && test_cmp expect output" else - test_expect_success "$1 $subnum" "$cmd > output || test $? = $status && test_cmp expect output" + test_expect_success "$1 $subnum" "$cmd > output ; test \$? = $status && test_cmp expect output" fi subnum=$(($subnum + 1)) @@ -560,7 +560,7 @@ test_todo_session () { if [ $status = 0 ]; then test_expect_success "$1 $subnum" "$cmd > output && test_cmp expect output" else - test_expect_success "$1 $subnum" "$cmd > output || test $? = $status && test_cmp expect output" + test_expect_success "$1 $subnum" "$cmd > output ; test \$? = $status && test_cmp expect output" fi fi } From f72c1034ee9c57523620e344dc68b16cba66ac9d Mon Sep 17 00:00:00 2001 From: Ingo Karkat Date: Tue, 29 Jun 2010 10:43:53 +0200 Subject: [PATCH 6/9] Added tests for custom actions (TODO_ACTIONS_DIR). t0002-actions.sh for locating the .todo.actions.d directory. t8000-actions.sh for the contract between todo.sh and custom actions. --- tests/t0002-actions.sh | 40 ++++++++++++++++++++++++++++++++ tests/t8000-actions.sh | 52 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100755 tests/t0002-actions.sh create mode 100755 tests/t8000-actions.sh diff --git a/tests/t0002-actions.sh b/tests/t0002-actions.sh new file mode 100755 index 0000000..d3b31ed --- /dev/null +++ b/tests/t0002-actions.sh @@ -0,0 +1,40 @@ +#!/bin/sh + +test_description='todo.sh actions.d + +This test just makes sure that todo.sh can locate custom actions. +' +. ./test-lib.sh + +# All the below tests will output the custom action message +cat > expect << EOF +TODO: foo +EOF + +cat > foo << EOF +echo "TODO: foo" +EOF +chmod +x foo + +test_expect_success 'custom action (default location 1)' ' + mkdir .todo.actions.d + cp foo .todo.actions.d/ + todo.sh foo > output; + test_cmp expect output && rm -rf .todo.actions.d +' + +test_expect_success 'custom action (default location 2)' ' + mkdir -p .todo/actions + cp foo .todo/actions/ + todo.sh foo > output; + test_cmp expect output && rm -rf .todo/actions +' + +test_expect_success 'custom action (env variable)' ' + mkdir myactions + cp foo myactions/ + TODO_ACTIONS_DIR=myactions todo.sh foo > output; + test_cmp expect output && rm -rf myactions +' + +test_done diff --git a/tests/t8000-actions.sh b/tests/t8000-actions.sh new file mode 100755 index 0000000..3d92248 --- /dev/null +++ b/tests/t8000-actions.sh @@ -0,0 +1,52 @@ +#!/bin/sh + +test_description='custom actions functionality + +This test covers the contract between todo.sh and custom actions. +' +. ./test-lib.sh + +unset TODO_ACTIONS_DIR +mkdir .todo.actions.d +cat > .todo.actions.d/foo << EOF +echo "TODO: foo" +EOF + +test_todo_session 'nonexecutable action' <>> todo.sh foo +Usage: todo.sh [-fhpantvV] [-d todo_config] action [task_number] [task_description] +Try 'todo.sh -h' for more information. +=== 1 +EOF + +chmod +x .todo.actions.d/foo +test_todo_session 'executable action' <>> todo.sh foo +TODO: foo +EOF + +cat > .todo.actions.d/ls << EOF +echo "TODO: my ls" +EOF +chmod +x .todo.actions.d/ls +test_todo_session 'overriding built-in action' <>> todo.sh ls +TODO: my ls + +>>> todo.sh command ls +-- +TODO: 0 of 0 tasks shown +EOF + +cat > .todo.actions.d/bad << EOF +echo "TODO: bad" +exit 42 +EOF +chmod +x .todo.actions.d/bad +test_todo_session 'failing action' <>> todo.sh bad +TODO: bad +=== 42 +EOF + +test_done From 38e2b8847f9115638a397bf039b41c212f5e44f9 Mon Sep 17 00:00:00 2001 From: Ingo Karkat Date: Tue, 29 Jun 2010 11:07:40 +0200 Subject: [PATCH 7/9] BUG: Failure of custom actions is not reflected in todo.sh exit status. No further actions are done after cleanup() calls, so the change from "exit" to "return" is safe. Further refactoring of the cleanup() calls is pending. --- todo.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/todo.sh b/todo.sh index 9e54ee8..6dc42a2 100755 --- a/todo.sh +++ b/todo.sh @@ -250,7 +250,7 @@ die() cleanup() { [ -f "$TMP_FILE" ] && rm "$TMP_FILE" - exit 0 + return 0 } cleaninput() @@ -620,7 +620,9 @@ then elif [ -d "$TODO_ACTIONS_DIR" -a -x "$TODO_ACTIONS_DIR/$action" ] then "$TODO_ACTIONS_DIR/$action" "$@" + status=$? cleanup + exit $status fi ## Only run if $action isn't found in .todo.actions.d From c58317258e3492bb436c1c40a9d6100ab52d97f2 Mon Sep 17 00:00:00 2001 From: Ingo Karkat Date: Tue, 29 Jun 2010 11:26:07 +0200 Subject: [PATCH 8/9] Refactoring: Moved cleanup() calls from individual actions to end of script. --- todo.sh | 46 +++++++++++++++++++--------------------------- 1 file changed, 19 insertions(+), 27 deletions(-) diff --git a/todo.sh b/todo.sh index 6dc42a2..96b7c54 100755 --- a/todo.sh +++ b/todo.sh @@ -279,7 +279,6 @@ archive() sed -n 'G; s/\n/&&/; /^\([ ~-]*\n\).*\n\1/d; s/\n//; h; P' "$TMP_FILE" > "$TODO_FILE" #[[ $TODOTXT_VERBOSE -gt 0 ]] && echo "TODO: Duplicate tasks have been removed." [ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: $TODO_FILE archived." - cleanup } @@ -637,7 +636,7 @@ case $action in input=$* fi _addto "$TODO_FILE" "$input" - cleanup;; + ;; "addm") if [[ -z "$2" && $TODOTXT_FORCE = 0 ]]; then @@ -659,7 +658,7 @@ case $action in _addto "$TODO_FILE" "$line" done IFS=$SAVEIFS - cleanup;; + ;; "addto" ) [ -z "$2" ] && die "usage: $TODO_SH addto DEST \"TODO ITEM\"" @@ -674,7 +673,7 @@ case $action in else echo "TODO: Destination file $dest does not exist." fi - cleanup;; + ;; "append" | "app" ) errmsg="usage: $TODO_SH append ITEM# \"TEXT TO APPEND\"" @@ -700,7 +699,7 @@ case $action in else echo "TODO: Error appending task $item." fi - cleanup;; + ;; "archive" ) archive;; @@ -732,7 +731,6 @@ case $action in sed -i.bak -e $item"s/^.*//" "$TODO_FILE" fi [ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: '$DELETEME' deleted." - cleanup else echo "TODO: No tasks were deleted." fi @@ -742,7 +740,8 @@ case $action in else sed -i.bak -e $item"s/$3/ /g" "$TODO_FILE" [ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: $3 removed from $item." - fi ;; + fi + ;; "depri" | "dp" ) errmsg="usage: $TODO_SH depri ITEM#[, ITEM#, ITEM#, ...]" @@ -770,7 +769,7 @@ case $action in die "$errmsg" fi done - cleanup ;; + ;; "do" ) errmsg="usage: $TODO_SH do ITEM#[, ITEM#, ITEM#, ...]" @@ -806,7 +805,7 @@ case $action in if [ $TODOTXT_AUTO_ARCHIVE = 1 ]; then archive fi - cleanup ;; + ;; "help" ) if [ -t 1 ] ; then # STDOUT is a TTY @@ -821,8 +820,6 @@ case $action in "list" | "ls" ) shift ## Was ls; new $1 is first search term _list "$TODO_FILE" "$@" - - cleanup ;; "listall" | "lsa" ) @@ -830,8 +827,6 @@ case $action in cat "$TODO_FILE" "$DONE_FILE" > "$TMP_FILE" _list "$TMP_FILE" "$@" - - cleanup ;; "listfile" | "lf" ) @@ -840,18 +835,15 @@ case $action in shift ## Was filename; next $1 is first search term _list "$FILE" "$@" - - cleanup ;; "listcon" | "lsc" ) grep -o '[^ ]*@[^ ]\+' "$TODO_FILE" | grep '^@' | sort -u - cleanup ;; + ;; "listproj" | "lsprj" ) grep -o '[^ ]*+[^ ]\+' "$TODO_FILE" | grep '^+' | sort -u - cleanup ;; - + ;; "listpri" | "lsp" ) shift ## was "listpri", new $1 is priority to list @@ -906,7 +898,6 @@ case $action in echo "$MOVEME" >> "$dest" [ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: '$MOVEME' moved from '$src' to '$dest'." - cleanup else echo "TODO: No tasks moved." fi @@ -919,7 +910,7 @@ case $action in else echo "TODO: Source file $src does not exist." fi - cleanup;; + ;; "prepend" | "prep" ) errmsg="usage: $TODO_SH prepend ITEM# \"TEXT TO PREPEND\"" @@ -965,7 +956,7 @@ case $action in echo "TODO: Error prepending task $item." fi fi - cleanup;; + ;; "pri" | "p" ) item=$2 @@ -988,10 +979,10 @@ note: PRIORITY must be anywhere from A to Z." echo "$item: $NEWTODO" echo "TODO: $item prioritized ($newpri)." } - cleanup else die "$errmsg" - fi;; + fi + ;; "replace" ) errmsg="usage: $TODO_SH replace ITEM# \"UPDATED ITEM\"" @@ -1028,7 +1019,7 @@ note: PRIORITY must be anywhere from A to Z." echo "replaced with" echo "$item: $NEWTODO" } - cleanup;; + ;; "report" ) #archive first @@ -1047,9 +1038,10 @@ note: PRIORITY must be anywhere from A to Z." echo $TECHO >> "$REPORT_FILE" [ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: Report file updated." cat "$REPORT_FILE" - cleanup;; + ;; * ) - usage - ;; + usage;; esac + +cleanup From 2d0efff9a8dcccf32e4513e6d5e2f57ad4c77f38 Mon Sep 17 00:00:00 2001 From: Ingo Karkat Date: Tue, 29 Jun 2010 12:52:56 +0200 Subject: [PATCH 9/9] Also exporting the die() function; it's often useful in custom actions. --- todo.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/todo.sh b/todo.sh index 96b7c54..d2fc5de 100755 --- a/todo.sh +++ b/todo.sh @@ -601,7 +601,7 @@ _list() { fi } -export -f _list +export -f _list die # == HANDLE ACTION == action=$( printf "%s\n" "$ACTION" | tr 'A-Z' 'a-z' )