Compare commits

..

52 Commits
v1.0.0 ... v2.7

Author SHA1 Message Date
Ingo Karkat
94325f57cd Improved color map instructions.
Clarified the use of ANSI escape codes.
Added motivation why to change, e.g. when using Conky.
Added requirement to uncomment color defaults when changing the color map, based on a support request on the mailing list.
2010-07-17 21:29:55 +02:00
Ingo Karkat
938bbc1ec2 Aligned PRI_X comment with updated one in config.
As an addendum to commit 9b7f85bea1.
2010-07-17 09:47:39 +02:00
Ingo Karkat
99f8911c8f Added fallback for $TODO_DIR/${FILE}.txt.
This allows to leave off the .txt file extension in commands like "todo.sh listfile done".
Plus: Minor coding style alignment, replaced $1 argument with existing $FILE variable.
2010-07-16 16:15:45 +02:00
Ingo Karkat
f5d4249078 ENH: Added highlighting of done (but not yet archived) tasks.
This makes done tasks more stand out (like prioritized tasks) in the task list. Default highlighting is LIGHT_GREY, which seems to be modest and go well with the assumed dark terminal background.
Reintroduced the OSX-compatible sed filter that was introduced by commit 8b7e2e6aad and superseded by the PRI_X coloring generalization.
2010-07-15 16:14:46 +02:00
Ingo Karkat
9b7f85bea1 Config file addendum to generalization of PRI_X color support.
Adapts the config file comments to the generalization of PRI_X color support to all priorities (commit e7b5841721).
2010-07-15 15:19:38 +02:00
Ingo Karkat
a7afc7917d Minor: aligned capitalization in fatal error message. 2010-07-15 15:19:24 +02:00
Ingo Karkat
4d29e68e89 Aligned "no such task" error message with verbose messages.
The message now also starts with "TODO:", like all other messages (except for the usage messages).
Before: 42: No such task.
After:  TODO: No task 42.
2010-07-15 13:48:24 +02:00
Ingo Karkat
b383b1f0c5 Aligned verbose message output of tasks with normal task output.
I.e. removed the colon after the ITEM#. Updated tasks are now listed like the 'todo.sh ls' command does, e.g.
    42 smell the roses
This is in preparation to eventually use a function factored out from _list() for the verbose task output, which would enable coloring in the verbose message and thus align the verbose message output even more with the normal task output.
2010-07-14 18:01:39 +02:00
Ingo Karkat
8a95a66749 Using die() for some more error messages. 2010-07-14 17:31:11 +02:00
Ingo Karkat
83053fd0c1 Better verbose messages for 'replace' and 'del TERM'.
Added "TODO:" prefix and simplified messages.
2010-07-14 17:18:57 +02:00
Ingo Karkat
74fa07d26a Aligned implementations of verbose output.
Replaced multi-line [ ] && { ... } with if-then.
2010-07-14 16:47:03 +02:00
Ingo Karkat
3e597ce20e Merge commit 'upstream/master' 2010-07-13 18:15:54 +02:00
Ingo Karkat
da466c9361 Improved 'move' command.
- Removed (accidental) printing of the task (without leading ITEM#) when checking for existence of the task; using empty check of task text as done elsewhere.
- Simplified error handling and using die() for proper exit code.
- Aligned verbose move message with the verbose output of other commands.
2010-07-13 18:11:05 +02:00
Ingo Karkat
72caab8bbd Added test for del preserving line numbers. 2010-07-13 17:49:40 +02:00
Ingo Karkat
7501b225c2 ENH: Improved 'del ITEM# TERM' command.
- Condensing whitespace around TERM into a single space and removing leading/trailing spaces if at the beginning/end of the task.
- Proper error message if TERM not found.
- Aligned verbose removal message with the verbose output of the 'replace' command.
In addition, removed (accidental) printing of the task (without leading ITEM#) when checking for existence of the task; using empty check of task text as done elsewhere.
2010-07-13 17:48:54 +02:00
Ingo Karkat
bcbf93ebe4 Fixed todo.sh del usage and exit code. 2010-07-13 16:18:02 +02:00
Gina Trapani
cea6d07735 Merge branch 'inkarkat/master' 2010-07-13 01:07:24 -07:00
Ingo Karkat
2f4ba26994 ENH: Sentence delimiters for append action.
This fixes a personal annoyance.
If the text to be appended to the task begins with one of the delimiter characters, no whitespace is inserted in between. This makes appending to an enumeration (todo.sh add 42 ", foo") syntactically correct.
The list of delimiters is configurable (for personal preferences / non-English languages) via SENTENCE_DELIMITERS in the config file.
2010-07-05 13:49:58 +02:00
Ingo Karkat
5e44868261 ENH: 'prepend' and 'replace' actions keep prepended date.
Generalized and simplified the logic that already kept an existing priority to also keep a date added via todo.sh -t / TODOTXT_DATE_ON_ADD (unless the replaced text also starts with a date).
2010-07-05 11:24:19 +02:00
Ingo Karkat
2f6d9ae329 Factored out 'prepend' and 'replace' actions.
They contained much duplication, which has been consolidated into replaceOrPrepend().
2010-07-05 09:38:10 +02:00
Gina Trapani
d46a12f14a Merge branch 'inkarkat/master' 2010-06-29 10:50:58 -07:00
Gina Trapani
95919765f7 Merge branch 'master' of git@github.com:ginatrapani/todo.txt-cli 2010-06-29 10:12:56 -07:00
Ingo Karkat
2d0efff9a8 Also exporting the die() function; it's often useful in custom actions. 2010-06-29 12:52:56 +02:00
Ingo Karkat
c58317258e Refactoring: Moved cleanup() calls from individual actions to end of script. 2010-06-29 11:26:07 +02:00
Ingo Karkat
38e2b8847f 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.
2010-06-29 11:07:40 +02:00
Ingo Karkat
f72c1034ee 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.
2010-06-29 10:43:53 +02:00
Ingo Karkat
37fcc53b26 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.
2010-06-29 08:00:24 +02:00
Glyn Faulkner
e7b5841721 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 8b7e2e6aad.
Added tests for highlighting of priorities.
2010-06-21 15:25:42 +02:00
Ingo Karkat
0b16bae2e8 Merge commit 'upstream/master' 2010-06-21 12:41:24 +02:00
Ed Blackman
8b7e2e6aad Replace colorization sed scripts with ones that are more compatible with OSX
sed and NLS todo items.  They're also more consistent with other internal usage
of sed.
2010-06-10 13:20:35 +08:00
Ingo Karkat
9f03cf6847 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: '<task>' 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.
2010-06-10 13:20:07 +08:00
Ingo Karkat
821b9d2795 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.
2010-06-10 13:20:05 +08:00
Ingo Karkat
c52d9c33af Removed unnecessary echo within echo. 2010-06-10 13:20:04 +08:00
Ingo Karkat
70b2c4ca40 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: '<task>' 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.
2010-06-04 16:50:09 +02:00
Ingo Karkat
69e756a2cd 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.
2010-06-04 16:22:15 +02:00
Ingo Karkat
52b9db310f Removed unnecessary echo within echo. 2010-06-03 22:13:17 +02:00
Gina Trapani
26bee144bd Merge branch 'inkarkat/master' 2010-05-30 19:09:58 -07:00
Ingo Karkat
8ff3a7ce4a Cleaned up terms in command error messages.
The messages now consistently use "task"; the use of "todo" is deprecated.
2010-05-27 15:48:37 +02:00
Ingo Karkat
8bddb08196 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.
2010-05-27 15:11:33 +02:00
Ingo Karkat
391064e4f0 Replaced "NUMBER" with "ITEM#" in help and shorthelp.
This makes the help output consistent with the syntax error messages of individual commands.
2010-05-27 14:49:07 +02:00
Ingo Karkat
d52a1a7bd2 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.
2010-05-25 13:42:04 +02:00
Ingo Karkat
15084aa4d7 Allow passing multiple items to depri, like for the do command. 2010-05-25 13:27:28 +02:00
Ingo Karkat
5876cc0437 Bugfix: depri first checks validity of item argument syntax before searching for todo.
Added testcase for the basic depriority command.
2010-05-25 13:08:27 +02:00
Ingo Karkat
370abbbf36 Aligned short help for "do" with correct long help text. 2010-05-25 10:23:07 +02:00
Ingo Karkat
97eaa24b06 Corrected typo in comment. 2010-05-25 10:15:53 +02:00
Ingo Karkat
9e5e6aef39 Printing usage message if no ITEM# given to "todo.sh do". 2010-05-25 10:10:09 +02:00
Ingo Karkat
edac86a94d Aligned "todo.sh do" usage message with existing support of passing multiple numbers. 2010-05-25 09:44:22 +02:00
Gina Trapani
948686a501 Merge branch 'master' of git@github.com:ginatrapani/todo.txt-cli 2010-05-14 18:37:43 -07:00
Yujie Wu
2a65615c7a Added a case for the fixed replace command. 2010-05-08 08:52:59 +08:00
Yujie Wu
d7e194b09d Fixed bug for replace command. 2010-05-08 08:52:59 +08:00
Yujie Wu
fd10678257 Added a case for the fixed replace command. 2010-05-07 17:47:41 -07:00
Jared Cordasco
a4ab8a808a Tab fixes. 2010-04-16 06:12:00 +08:00
23 changed files with 1012 additions and 501 deletions

6
.gitattributes vendored
View File

@@ -1,6 +0,0 @@
.git[ia]* export-ignore
GEN-VERSION-FILE export-ignore
Makefile export-ignore
README.textile export-ignore
VERSION-FILE export-ignore
tests export-ignore

View File

@@ -10,7 +10,7 @@ to find it somewhere else.
# Remove the pre-created todo.cfg to test behavior in its absence # Remove the pre-created todo.cfg to test behavior in its absence
rm -f todo.cfg rm -f todo.cfg
echo "Fatal error: Cannot read configuration file $HOME/.todo/config" > expect echo "Fatal Error: Cannot read configuration file $HOME/.todo/config" > expect
test_expect_success 'no config file' ' test_expect_success 'no config file' '
todo.sh > output 2>&1 || test_cmp expect output todo.sh > output 2>&1 || test_cmp expect output
' '

40
tests/t0002-actions.sh Executable file
View File

@@ -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

View File

@@ -12,7 +12,8 @@ command work, including support for filtering.
# #
test_todo_session 'basic add/list' <<EOF test_todo_session 'basic add/list' <<EOF
>>> todo.sh add notice the daisies >>> todo.sh add notice the daisies
TODO: 'notice the daisies' added on line 1. 1 notice the daisies
TODO: 1 added.
>>> todo.sh list >>> todo.sh list
1 notice the daisies 1 notice the daisies
@@ -20,7 +21,8 @@ TODO: 'notice the daisies' added on line 1.
TODO: 1 of 1 tasks shown TODO: 1 of 1 tasks shown
>>> todo.sh add smell the roses >>> todo.sh add smell the roses
TODO: 'smell the roses' added on line 2. 2 smell the roses
TODO: 2 added.
>>> todo.sh list >>> todo.sh list
1 notice the daisies 1 notice the daisies
@@ -46,7 +48,8 @@ EOF
test_todo_session 'case-insensitive filtering' <<EOF test_todo_session 'case-insensitive filtering' <<EOF
>>> todo.sh add smell the uppercase Roses >>> 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 >>> todo.sh list roses
2 smell the roses 2 smell the roses
@@ -57,7 +60,8 @@ EOF
test_todo_session 'add with &' <<EOF test_todo_session 'add with &' <<EOF
>>> todo.sh add "dig the garden & water the flowers" >>> 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 >>> todo.sh list
4 dig the garden & water the flowers 4 dig the garden & water the flowers

View File

@@ -12,7 +12,8 @@ a date to each item.
# #
test_todo_session 'cmd line first day' <<EOF test_todo_session 'cmd line first day' <<EOF
>>> todo.sh -t add notice the daisies >>> 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 >>> todo.sh list
1 2009-02-13 notice the daisies 1 2009-02-13 notice the daisies
@@ -24,7 +25,8 @@ test_tick
test_todo_session 'cmd line second day' <<EOF test_todo_session 'cmd line second day' <<EOF
>>> todo.sh -t add smell the roses >>> 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 >>> todo.sh list
1 2009-02-13 notice the daisies 1 2009-02-13 notice the daisies
@@ -37,7 +39,8 @@ test_tick
test_todo_session 'cmd line third day' <<EOF test_todo_session 'cmd line third day' <<EOF
>>> todo.sh -t add mow the lawn >>> 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 >>> todo.sh list
1 2009-02-13 notice the daisies 1 2009-02-13 notice the daisies
@@ -55,7 +58,8 @@ test_tick 3600
test_todo_session 'config file third day' <<EOF test_todo_session 'config file third day' <<EOF
>>> todo.sh add take out the trash >>> 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 >>> todo.sh list
1 2009-02-13 notice the daisies 1 2009-02-13 notice the daisies

View File

@@ -13,13 +13,15 @@ commands work, including support for filtering.
test_todo_session 'nonexistant file' <<EOF test_todo_session 'nonexistant file' <<EOF
>>> todo.sh addto garden.txt notice the daisies >>> todo.sh addto garden.txt notice the daisies
TODO: Destination file $HOME/garden.txt does not exist. TODO: Destination file $HOME/garden.txt does not exist.
=== 1
EOF EOF
touch "$HOME/garden.txt" touch "$HOME/garden.txt"
test_todo_session 'basic addto/listfile' <<EOF test_todo_session 'basic addto/listfile' <<EOF
>>> todo.sh addto garden.txt notice the daisies >>> 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 >>> todo.sh listfile garden.txt
1 notice the daisies 1 notice the daisies
@@ -27,7 +29,8 @@ GARDEN: 'notice the daisies' added on line 1.
GARDEN: 1 of 1 tasks shown GARDEN: 1 of 1 tasks shown
>>> todo.sh addto garden.txt smell the roses >>> 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 >>> todo.sh listfile garden.txt
1 notice the daisies 1 notice the daisies
@@ -53,7 +56,8 @@ EOF
test_todo_session 'case-insensitive filtering' <<EOF test_todo_session 'case-insensitive filtering' <<EOF
>>> todo.sh addto garden.txt smell the uppercase Roses >>> 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 >>> todo.sh listfile garden.txt roses
2 smell the roses 2 smell the roses
@@ -64,7 +68,8 @@ EOF
test_todo_session 'addto with &' <<EOF test_todo_session 'addto with &' <<EOF
>>> todo.sh addto garden.txt "dig the garden & water the flowers" >>> 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 >>> todo.sh listfile garden.txt
4 dig the garden & water the flowers 4 dig the garden & water the flowers

View File

@@ -14,7 +14,8 @@ touch "$HOME/garden.txt"
# #
test_todo_session 'cmd line first day' <<EOF test_todo_session 'cmd line first day' <<EOF
>>> todo.sh -t addto garden.txt notice the daisies >>> 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 >>> todo.sh listfile garden.txt
1 2009-02-13 notice the daisies 1 2009-02-13 notice the daisies
@@ -26,7 +27,8 @@ test_tick
test_todo_session 'cmd line second day' <<EOF test_todo_session 'cmd line second day' <<EOF
>>> todo.sh -t addto garden.txt smell the roses >>> 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 >>> todo.sh listfile garden.txt
1 2009-02-13 notice the daisies 1 2009-02-13 notice the daisies
@@ -39,7 +41,8 @@ test_tick
test_todo_session 'cmd line third day' <<EOF test_todo_session 'cmd line third day' <<EOF
>>> todo.sh -t addto garden.txt mow the lawn >>> 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 >>> todo.sh listfile garden.txt
1 2009-02-13 notice the daisies 1 2009-02-13 notice the daisies
@@ -57,7 +60,8 @@ test_tick 3600
test_todo_session 'config file third day' <<EOF test_todo_session 'config file third day' <<EOF
>>> todo.sh addto garden.txt take out the trash >>> 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 >>> todo.sh listfile garden.txt
1 2009-02-13 notice the daisies 1 2009-02-13 notice the daisies

View File

@@ -19,9 +19,9 @@ EOF
test_todo_session 'basic replace' <<EOF test_todo_session 'basic replace' <<EOF
>>> todo.sh replace 1 "smell the cows" >>> todo.sh replace 1 "smell the cows"
1: notice the daisies 1 notice the daisies
replaced with TODO: Replaced task with:
1: smell the cows 1 smell the cows
>>> todo.sh list >>> todo.sh list
1 smell the cows 1 smell the cows
@@ -29,9 +29,9 @@ replaced with
TODO: 1 of 1 tasks shown TODO: 1 of 1 tasks shown
>>> todo.sh replace 1 smell the roses >>> todo.sh replace 1 smell the roses
1: smell the cows 1 smell the cows
replaced with TODO: Replaced task with:
1: smell the roses 1 smell the roses
>>> todo.sh list >>> todo.sh list
1 smell the roses 1 smell the roses
@@ -47,42 +47,88 @@ chase the chickens
EOF EOF
test_todo_session 'replace in multi-item file' <<EOF test_todo_session 'replace in multi-item file' <<EOF
>>> todo.sh replace 1 smell the cheese >>> todo.sh replace 1 smell the cheese
1: smell the cows 1 smell the cows
replaced with TODO: Replaced task with:
1: smell the cheese 1 smell the cheese
>>> todo.sh replace 3 jump on hay >>> todo.sh replace 3 jump on hay
3: thrash some hay 3 thrash some hay
replaced with TODO: Replaced task with:
3: jump on hay 3 jump on hay
>>> todo.sh replace 4 collect the eggs >>> todo.sh replace 4 collect the eggs
4: chase the chickens 4 chase the chickens
replaced with TODO: Replaced task with:
4: collect the eggs 4 collect the eggs
EOF EOF
test_todo_session 'replace with priority' <<EOF test_todo_session 'replace with priority' <<EOF
>>> todo.sh pri 4 a >>> todo.sh pri 4 a
4: (A) collect the eggs 4 (A) collect the eggs
TODO: 4 prioritized (A). TODO: 4 prioritized (A).
>>> todo.sh replace 4 "collect the bread" >>> todo.sh replace 4 "collect the bread"
4: (A) collect the eggs 4 (A) collect the eggs
replaced with TODO: Replaced task with:
4: (A) collect the bread 4 (A) collect the bread
>>> todo.sh replace 4 collect the eggs
4 (A) collect the bread
TODO: Replaced task with:
4 (A) collect the eggs
EOF EOF
test_todo_session 'replace with &' << EOF test_todo_session 'replace with &' << EOF
>>> todo.sh replace 3 "thrash the hay & thresh the wheat" >>> todo.sh replace 3 "thrash the hay & thresh the wheat"
3: jump on hay 3 jump on hay
replaced with TODO: Replaced task with:
3: thrash the hay & thresh the wheat 3 thrash the hay & thresh the wheat
EOF EOF
test_todo_session 'replace error' << EOF test_todo_session 'replace error' << EOF
>>> todo.sh replace 10 "hej!" >>> todo.sh replace 10 "hej!"
=== 1 === 1
10: No such todo. TODO: No task 10.
EOF
cat /dev/null > todo.txt
test_todo_session 'replace handling prepended date on add' <<EOF
>>> todo.sh -t add "new task"
1 2009-02-13 new task
TODO: 1 added.
>>> todo.sh replace 1 this is just a new one
1 2009-02-13 new task
TODO: Replaced task with:
1 2009-02-13 this is just a new one
>>> todo.sh replace 1 2010-07-04 this also has a new date
1 2009-02-13 this is just a new one
TODO: Replaced task with:
1 2010-07-04 this also has a new date
EOF
cat /dev/null > todo.txt
test_todo_session 'replace handling priority and prepended date on add' <<EOF
>>> todo.sh -t add "new task"
1 2009-02-13 new task
TODO: 1 added.
>>> todo.sh pri 1 A
1 (A) 2009-02-13 new task
TODO: 1 prioritized (A).
>>> todo.sh replace 1 this is just a new one
1 (A) 2009-02-13 new task
TODO: Replaced task with:
1 (A) 2009-02-13 this is just a new one
EOF
test_todo_session 'replace with prepended date replaces existing date' <<EOF
>>> todo.sh replace 1 2010-07-04 this also has a new date
1 (A) 2009-02-13 this is just a new one
TODO: Replaced task with:
1 (A) 2010-07-04 this also has a new date
EOF EOF
test_done test_done

View File

@@ -25,7 +25,7 @@ test_todo_session 'basic priority' <<EOF
TODO: 3 of 3 tasks shown TODO: 3 of 3 tasks shown
>>> todo.sh pri 1 B >>> todo.sh pri 1 B
1: (B) smell the uppercase Roses +flowers @outside 1 (B) smell the uppercase Roses +flowers @outside
TODO: 1 prioritized (B). TODO: 1 prioritized (B).
>>> todo.sh list >>> todo.sh list
@@ -43,7 +43,7 @@ TODO: 3 of 3 tasks shown
TODO: 3 of 3 tasks shown TODO: 3 of 3 tasks shown
>>> todo.sh pri 2 C >>> todo.sh pri 2 C
2: (C) notice the sunflowers 2 (C) notice the sunflowers
TODO: 2 prioritized (C). TODO: 2 prioritized (C).
>>> todo.sh -p list >>> todo.sh -p list
@@ -54,7 +54,7 @@ TODO: 2 prioritized (C).
TODO: 3 of 3 tasks shown TODO: 3 of 3 tasks shown
>>> todo.sh pri 2 A >>> todo.sh pri 2 A
2: (A) notice the sunflowers 2 (A) notice the sunflowers
TODO: 2 prioritized (A). TODO: 2 prioritized (A).
>>> todo.sh -p list >>> todo.sh -p list
@@ -65,7 +65,7 @@ TODO: 2 prioritized (A).
TODO: 3 of 3 tasks shown TODO: 3 of 3 tasks shown
>>> todo.sh pri 2 a >>> todo.sh pri 2 a
2: (A) notice the sunflowers 2 (A) notice the sunflowers
TODO: 2 prioritized (A). TODO: 2 prioritized (A).
>>> todo.sh -p listpri >>> todo.sh -p listpri
@@ -75,7 +75,8 @@ TODO: 2 prioritized (A).
TODO: 2 of 3 tasks shown TODO: 2 of 3 tasks shown
>>> todo.sh add "smell the coffee +wakeup" >>> 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 >>> todo.sh -p list
2 (A) notice the sunflowers 2 (A) notice the sunflowers

View File

@@ -53,6 +53,47 @@ test_todo_session 'checking TODOTXT_FINAL_FILTER' <<EOF
TODO: 3 of 3 tasks shown TODO: 3 of 3 tasks shown
EOF EOF
#
# check the filtering of TERM
#
test_todo_session 'checking filtering of TERM' <<EOF
>>> 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' <<EOF
>>> 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 # check the x command line option
# #

151
tests/t1330-ls-highlighting.sh Executable file
View File

@@ -0,0 +1,151 @@
#!/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 <<EOF
(A) @con01 +prj01 -- Some project 01 task, pri A
(B) @con02 +prj02 -- Some project 02 task, pri B
(C) @con01 +prj01 -- Some project 01 task, pri C
(D) @con02 +prj02 -- Some project 02 task, pri D
(E) @con01 +prj01 -- Some project 01 task, pri E
(Z) @con02 +prj02 -- Some project 02 task, pri Z
@con01 +prj01 -- Some project 01 task, no priority
@con02 +prj02 -- Some project 02 task, no priority
EOF
test_todo_session 'default highlighting' <<EOF
>>> 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
# check highlighting of done (but not yet archived) tasks
#
cat > todo.txt <<EOF
(A) smell the uppercase Roses +flowers @outside
remove1
notice the sunflowers
remove2
stop
EOF
test_todo_session 'highlighting of done tasks' <<EOF
>>> todo.sh -a do 2
2 x 2009-02-13 remove1
TODO: 2 marked as done.
>>> todo.sh list
1 (A) smell the uppercase Roses +flowers @outside
3 notice the sunflowers
4 remove2
5 stop
2 x 2009-02-13 remove1
--
TODO: 5 of 5 tasks shown
>>> todo.sh -a do 4
4 x 2009-02-13 remove2
TODO: 4 marked as done.
>>> todo.sh list
1 (A) smell the uppercase Roses +flowers @outside
3 notice the sunflowers
5 stop
2 x 2009-02-13 remove1
4 x 2009-02-13 remove2
--
TODO: 5 of 5 tasks shown
EOF
test_done

View File

@@ -31,7 +31,7 @@ TODO: 3 of 3 tasks shown
TODO: 3 of 3 tasks shown TODO: 3 of 3 tasks shown
>>> todo.sh prepend 2 test >>> todo.sh prepend 2 test
2: test notice the sunflowers 2 test notice the sunflowers
>>> todo.sh -p list >>> todo.sh -p list
1 (B) smell the uppercase Roses +flowers @outside 1 (B) smell the uppercase Roses +flowers @outside
@@ -41,7 +41,7 @@ TODO: 3 of 3 tasks shown
TODO: 3 of 3 tasks shown TODO: 3 of 3 tasks shown
>>> todo.sh prepend 1 test >>> todo.sh prepend 1 test
1: (B) test smell the uppercase Roses +flowers @outside 1 (B) test smell the uppercase Roses +flowers @outside
>>> todo.sh -p list >>> todo.sh -p list
1 (B) test smell the uppercase Roses +flowers @outside 1 (B) test smell the uppercase Roses +flowers @outside
@@ -54,7 +54,41 @@ EOF
test_todo_session 'prepend with &' <<EOF test_todo_session 'prepend with &' <<EOF
>>> todo.sh prepend 3 "no running & jumping now" >>> todo.sh prepend 3 "no running & jumping now"
3: no running & jumping now stop 3 no running & jumping now stop
EOF
cat /dev/null > todo.txt
test_todo_session 'prepend handling prepended date on add' <<EOF
>>> todo.sh -t add "new task"
1 2009-02-13 new task
TODO: 1 added.
>>> todo.sh prepend 1 "this is just a"
1 2009-02-13 this is just a new task
EOF
cat /dev/null > todo.txt
test_todo_session 'prepend handling priority and prepended date on add' <<EOF
>>> todo.sh -t add "new task"
1 2009-02-13 new task
TODO: 1 added.
>>> todo.sh pri 1 A
1 (A) 2009-02-13 new task
TODO: 1 prioritized (A).
>>> todo.sh prepend 1 "this is just a"
1 (A) 2009-02-13 this is just a new task
EOF
cat /dev/null > todo.txt
test_todo_session 'prepend with prepended date keeps both' <<EOF
>>> todo.sh -t add "new task"
1 2009-02-13 new task
TODO: 1 added.
>>> todo.sh prepend 1 "2010-07-04 this is just a"
1 2009-02-13 2010-07-04 this is just a new task
EOF EOF
test_done test_done

View File

@@ -8,7 +8,13 @@ test_description='do functionality
test_todo_session 'do usage' <<EOF test_todo_session 'do usage' <<EOF
>>> todo.sh do B B >>> todo.sh do B B
usage: todo.sh do ITEM# usage: todo.sh do ITEM#[, ITEM#, ITEM#, ...]
=== 1
EOF
test_todo_session 'do missing ITEM#' <<EOF
>>> todo.sh do
usage: todo.sh do ITEM#[, ITEM#, ITEM#, ...]
=== 1 === 1
EOF EOF
@@ -35,9 +41,9 @@ test_todo_session 'basic do' <<EOF
TODO: 7 of 7 tasks shown TODO: 7 of 7 tasks shown
>>> todo.sh do 7,6 >>> todo.sh do 7,6
7: x 2009-02-13 remove4 7 x 2009-02-13 remove4
TODO: 7 marked as done. TODO: 7 marked as done.
6: x 2009-02-13 remove3 6 x 2009-02-13 remove3
TODO: 6 marked as done. TODO: 6 marked as done.
x 2009-02-13 remove3 x 2009-02-13 remove3
x 2009-02-13 remove4 x 2009-02-13 remove4
@@ -53,9 +59,9 @@ TODO: $HOME/todo.txt archived.
TODO: 5 of 5 tasks shown TODO: 5 of 5 tasks shown
>>> todo.sh do 5 4 >>> todo.sh do 5 4
5: x 2009-02-13 remove2 5 x 2009-02-13 remove2
TODO: 5 marked as done. TODO: 5 marked as done.
4: x 2009-02-13 remove1 4 x 2009-02-13 remove1
TODO: 4 marked as done. TODO: 4 marked as done.
x 2009-02-13 remove1 x 2009-02-13 remove1
x 2009-02-13 remove2 x 2009-02-13 remove2
@@ -71,7 +77,7 @@ EOF
test_todo_session 'fail multiple do attempts' <<EOF test_todo_session 'fail multiple do attempts' <<EOF
>>> todo.sh -a do 3 >>> todo.sh -a do 3
3: x 2009-02-13 stop 3 x 2009-02-13 stop
TODO: 3 marked as done. TODO: 3 marked as done.
>>> todo.sh -a do 3 >>> todo.sh -a do 3

View File

@@ -1,52 +0,0 @@
#!/bin/sh
test_description='done functionality
'
. ./test-lib.sh
#DATE=`date '+%Y-%m-%d'`
test_todo_session 'done usage' <<EOF
>>> export TODOTXT_FORCE=1
>>> todo.sh done
usage: todo.sh done "TODO ITEM"
=== 1
EOF
cat > todo.txt <<EOF
stop
remove1
remove2
remove3
remove4
EOF
test_todo_session 'basic done' <<EOF
>>> 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

View File

@@ -19,7 +19,7 @@ EOF
test_todo_session 'basic append' <<EOF test_todo_session 'basic append' <<EOF
>>> todo.sh append 1 "smell the roses" >>> todo.sh append 1 "smell the roses"
1: notice the daisies smell the roses 1 notice the daisies smell the roses
>>> todo.sh list >>> todo.sh list
1 notice the daisies smell the roses 1 notice the daisies smell the roses
@@ -29,7 +29,7 @@ EOF
test_todo_session 'basic append with &' <<EOF test_todo_session 'basic append with &' <<EOF
>>> todo.sh append 1 "see the wasps & bees" >>> todo.sh append 1 "see the wasps & bees"
1: notice the daisies smell the roses see the wasps & bees 1 notice the daisies smell the roses see the wasps & bees
>>> todo.sh list >>> todo.sh list
1 notice the daisies smell the roses see the wasps & bees 1 notice the daisies smell the roses see the wasps & bees
@@ -41,7 +41,36 @@ EOF
test_todo_session 'append error' << EOF test_todo_session 'append error' << EOF
>>> todo.sh append 10 "hej!" >>> todo.sh append 10 "hej!"
=== 1 === 1
10: No such todo. TODO: No task 10.
EOF
cat > todo.txt <<EOF
notice the daisies
EOF
test_todo_session 'append of current sentence' <<EOF
>>> todo.sh append 1 ", lilies and roses"
1 notice the daisies, lilies and roses
>>> todo.sh append 1 "; see the wasps"
1 notice the daisies, lilies and roses; see the wasps
>>> todo.sh append 1 "& bees"
1 notice the daisies, lilies and roses; see the wasps & bees
EOF
cp todo.cfg special-delimiters.cfg
cat >> special-delimiters.cfg <<EOF
export SENTENCE_DELIMITERS='*,.:;&'
EOF
test_todo_session 'append of current sentence SENTENCE_DELIMITERS' <<EOF
>>> todo.sh -d special-delimiters.cfg append 1 "&beans"
1 notice the daisies, lilies and roses; see the wasps & bees&beans
>>> todo.sh -d special-delimiters.cfg append 1 "%foo"
1 notice the daisies, lilies and roses; see the wasps & bees&beans %foo
>>> todo.sh -d special-delimiters.cfg append 1 "*2"
1 notice the daisies, lilies and roses; see the wasps & bees&beans %foo*2
EOF EOF
test_done test_done

71
tests/t1700-depri.sh Executable file
View File

@@ -0,0 +1,71 @@
#!/bin/sh
test_description='basic depriority functionality
'
. ./test-lib.sh
test_todo_session 'depriority usage' <<EOF
>>> todo.sh depri B B
usage: todo.sh depri ITEM#[, ITEM#, ITEM#, ...]
=== 1
EOF
test_todo_session 'depriority nonexistant item' <<EOF
>>> todo.sh depri 42
TODO: No task 42.
=== 1
EOF
cat > todo.txt <<EOF
(B) smell the uppercase Roses +flowers @outside
(A) notice the sunflowers
stop
EOF
test_todo_session 'basic depriority' <<EOF
>>> 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
cat > todo.txt <<EOF
(B) smell the uppercase Roses +flowers @outside
(A) notice the sunflowers
(C) stop
EOF
test_todo_session 'multiple depriority' <<EOF
>>> 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

153
tests/t1800-del.sh Executable file
View File

@@ -0,0 +1,153 @@
#!/bin/sh
test_description='basic del functionality
'
. ./test-lib.sh
test_todo_session 'del usage' <<EOF
>>> todo.sh del B
usage: todo.sh del ITEM# [TERM]
=== 1
EOF
test_todo_session 'del nonexistant item' <<EOF
>>> todo.sh -f del 42
TODO: No task 42.
=== 1
>>> todo.sh -f del 42 Roses
TODO: No task 42.
=== 1
EOF
cat > todo.txt <<EOF
(B) smell the uppercase Roses +flowers @outside
(A) notice the sunflowers
stop
EOF
test_todo_session 'basic del' <<EOF
>>> 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 -f del 1
1 (B) smell the uppercase Roses +flowers @outside
TODO: 1 deleted.
>>> todo.sh -p list
2 (A) notice the sunflowers
3 stop
--
TODO: 2 of 2 tasks shown
EOF
cat > todo.txt <<EOF
(B) smell the uppercase Roses +flowers @outside
(A) notice the sunflowers
stop
EOF
test_todo_session 'del preserving line numbers' <<EOF
>>> todo.sh -f del 1
1 (B) smell the uppercase Roses +flowers @outside
TODO: 1 deleted.
>>> todo.sh -f del 1
TODO: No task 1.
=== 1
>>> todo.sh add A new task
4 A new task
TODO: 4 added.
>>> todo.sh -p list
2 (A) notice the sunflowers
4 A new task
3 stop
--
TODO: 3 of 3 tasks shown
>>> todo.sh -f -n del 2
2 (A) notice the sunflowers
TODO: 2 deleted.
>>> todo.sh add Another new task
3 Another new task
TODO: 3 added.
>>> todo.sh -p list
2 A new task
3 Another new task
1 stop
--
TODO: 3 of 3 tasks shown
EOF
cat > todo.txt <<EOF
(B) smell the uppercase Roses +flowers @outside
(A) notice the sunflowers
(C) stop
EOF
test_todo_session 'basic del TERM' <<EOF
>>> 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 del 1 uppercase
1 (B) smell the uppercase Roses +flowers @outside
TODO: Removed 'uppercase' from task.
1 (B) smell the Roses +flowers @outside
>>> todo.sh -p list
2 (A) notice the sunflowers
1 (B) smell the Roses +flowers @outside
3 (C) stop
--
TODO: 3 of 3 tasks shown
>>> todo.sh del 1 "the Roses"
1 (B) smell the Roses +flowers @outside
TODO: Removed 'the Roses' from task.
1 (B) smell +flowers @outside
>>> todo.sh del 1 m
1 (B) smell +flowers @outside
TODO: Removed 'm' from task.
1 (B) sell +flowers @outside
>>> todo.sh del 1 @outside
1 (B) sell +flowers @outside
TODO: Removed '@outside' from task.
1 (B) sell +flowers
>>> todo.sh del 1 sell
1 (B) sell +flowers
TODO: Removed 'sell' from task.
1 (B) +flowers
EOF
cat > todo.txt <<EOF
(B) smell the uppercase Roses +flowers @outside
(A) notice the sunflowers
(C) stop
EOF
test_todo_session 'del nonexistant TERM' <<EOF
>>> todo.sh del 1 dung
1 (B) smell the uppercase Roses +flowers @outside
TODO: 'dung' not found; no removal done.
=== 1
>>> 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
EOF
test_done

View File

@@ -6,9 +6,9 @@ test_description='Multi-line functionality'
## Replace test ## Replace test
# Create the expected file # Create the expected file
echo "1: smell the cheese echo "1 smell the cheese
replaced with TODO: Replaced task with:
1: eat apples eat oranges drink milk">$HOME/expect.multi 1 eat apples eat oranges drink milk">$HOME/expect.multi
test_expect_success 'multiline squash item replace' ' test_expect_success 'multiline squash item replace' '
( (
@@ -33,7 +33,8 @@ fi
## Add test ## Add test
# Create the expected file # 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' ' test_expect_success 'multiline squash item add' '
( (
@@ -58,7 +59,7 @@ fi
## Append test ## Append test
# Create the expected file # Create the expected file
echo "1: smell the cheese eat apples eat oranges drink milk">$HOME/expect.multi echo "1 smell the cheese eat apples eat oranges drink milk">$HOME/expect.multi
test_expect_success 'multiline squash item append' ' test_expect_success 'multiline squash item append' '
( (
@@ -83,7 +84,7 @@ fi
## Prepend test ## Prepend test
# Create the expected file # Create the expected file
echo "1: eat apples eat oranges drink milk smell the cheese">$HOME/expect.multi echo "1 eat apples eat oranges drink milk smell the cheese">$HOME/expect.multi
test_expect_success 'multiline squash item prepend' ' test_expect_success 'multiline squash item prepend' '
( (
@@ -108,9 +109,12 @@ fi
## Multiple line addition ## Multiple line addition
# Create the expected file # Create the expected file
echo "TODO: 'eat apples' added on line 2." > $HOME/expect.multi echo "2 eat apples
echo "TODO: 'eat oranges' added on line 3." >>$HOME/expect.multi TODO: 2 added." > $HOME/expect.multi
echo "TODO: 'drink milk' added on line 4." >> $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' ' test_expect_success 'actual multiline add' '
( (

52
tests/t8000-actions.sh Executable file
View File

@@ -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' <<EOF
>>> 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' <<EOF
>>> 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' <<EOF
>>> 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' <<EOF
>>> todo.sh bad
TODO: bad
=== 42
EOF
test_done

View File

@@ -36,7 +36,7 @@ TODO: 2 of 4 tasks shown
TODO: 1 of 4 tasks shown TODO: 1 of 4 tasks shown
>>> todo.sh -a do 2 >>> todo.sh -a do 2
2: x 2009-02-13 notice the sunflowers 2 x 2009-02-13 notice the sunflowers
TODO: 2 marked as done. TODO: 2 marked as done.
>>> todo.sh -p list >>> todo.sh -p list
@@ -48,7 +48,8 @@ TODO: 2 marked as done.
TODO: 4 of 4 tasks shown TODO: 4 of 4 tasks shown
>>> todo.sh add "make the coffee +wakeup" >>> 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 >>> todo.sh -p list coffee
5 make the coffee +wakeup 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: 2 of 5 tasks shown
>>> todo.sh add "visit http://example.com" >>> 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 >>> todo.sh -p list
1 (B) smell the uppercase Roses +flowers @outside 1 (B) smell the uppercase Roses +flowers @outside
@@ -96,7 +98,7 @@ usage: todo.sh append ITEM# "TEXT TO APPEND"
=== 1 === 1
>>> todo.sh append 2 and think >>> todo.sh append 2 and think
2: stop and think 2 stop and think
>>> todo.sh -p list >>> todo.sh -p list
1 (B) smell the uppercase Roses +flowers @outside 1 (B) smell the uppercase Roses +flowers @outside
@@ -108,7 +110,7 @@ usage: todo.sh append ITEM# "TEXT TO APPEND"
TODO: 5 of 5 tasks shown TODO: 5 of 5 tasks shown
>>> todo.sh append 10 "hej!" >>> todo.sh append 10 "hej!"
10: No such todo. TODO: No task 10.
=== 1 === 1
>>> todo.sh -p list >>> todo.sh -p list
@@ -121,7 +123,7 @@ TODO: 5 of 5 tasks shown
TODO: 5 of 5 tasks shown TODO: 5 of 5 tasks shown
>>> todo.sh do 10 >>> todo.sh do 10
10: No such todo. TODO: No task 10.
=== 1 === 1
>>> todo.sh -p list >>> todo.sh -p list
@@ -134,7 +136,8 @@ TODO: 5 of 5 tasks shown
TODO: 5 of 5 tasks shown TODO: 5 of 5 tasks shown
>>> todo.sh add "the coffee +wakeup" >>> 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 >>> todo.sh -p list
1 (B) smell the uppercase Roses +flowers @outside 1 (B) smell the uppercase Roses +flowers @outside
@@ -147,7 +150,7 @@ TODO: 'the coffee +wakeup' added on line 6.
TODO: 6 of 6 tasks shown TODO: 6 of 6 tasks shown
>>> todo.sh prepend 6 "make" >>> todo.sh prepend 6 "make"
6: make the coffee +wakeup 6 make the coffee +wakeup
>>> todo.sh -p list >>> todo.sh -p list
1 (B) smell the uppercase Roses +flowers @outside 1 (B) smell the uppercase Roses +flowers @outside

View File

@@ -542,7 +542,7 @@ test_todo_session () {
if [ $status = 0 ]; then if [ $status = 0 ]; then
test_expect_success "$1 $subnum" "$cmd > output && test_cmp expect output" test_expect_success "$1 $subnum" "$cmd > output && test_cmp expect output"
else 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
subnum=$(($subnum + 1)) subnum=$(($subnum + 1))
@@ -560,7 +560,7 @@ test_todo_session () {
if [ $status = 0 ]; then if [ $status = 0 ]; then
test_expect_success "$1 $subnum" "$cmd > output && test_cmp expect output" test_expect_success "$1 $subnum" "$cmd > output && test_cmp expect output"
else 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
fi fi
} }

View File

@@ -17,8 +17,13 @@ export TMP_FILE="$TODO_DIR/todo.tmp"
# === COLOR MAP === # === COLOR MAP ===
## If you have re-mapped your color codes, you may need to ## Text coloring and formatting is done by inserting ANSI escape codes.
## If you have re-mapped your color codes, or use the todo.txt
## output in another output system (like Conky), you may need to
## over-ride by uncommenting and editing these defaults. ## over-ride by uncommenting and editing these defaults.
## If you change any of these here, you also need to uncomment
## the defaults in the COLORS section below. Otherwise, todo.txt
## will still use the defaults!
# export BLACK='\\033[0;30m' # export BLACK='\\033[0;30m'
# export RED='\\033[0;31m' # export RED='\\033[0;31m'
@@ -38,16 +43,25 @@ export TMP_FILE="$TODO_DIR/todo.tmp"
# export WHITE='\\033[1;37m' # export WHITE='\\033[1;37m'
# export DEFAULT='\\033[0m' # export DEFAULT='\\033[0m'
# === PRIORITY COLORS === # === COLORS ===
## Priorities can be any upper-case letter.
## Colors are supported for the first three.
## Uncomment and edit to override these defaults. ## Uncomment and edit to override these defaults.
## Reference the constants from the color map above,
## or use $NONE to disable highlighting.
#
# Priorities can be any upper-case letter.
# A,B,C are highlighted; you can add coloring for more.
#
# export PRI_A=$YELLOW # color for A priority # export PRI_A=$YELLOW # color for A priority
# export PRI_B=$GREEN # color for B priority # export PRI_B=$GREEN # color for B priority
# export PRI_C=$LIGHT_BLUE # color for C priority # export PRI_C=$LIGHT_BLUE # color for C priority
# export PRI_X=$WHITE # color for rest of them # export PRI_D=... # define your own
# export PRI_X=$WHITE # color unless explicitly defined
# There is highlighting for tasks that have been done,
# but haven't been archived yet.
#
# export COLOR_DONE=$LIGHT_GREY
# === BEHAVIOR === # === BEHAVIOR ===

629
todo.sh
View File

@@ -1,5 +1,8 @@
#! /bin/bash #! /bin/bash
# === HEAVY LIFTING ===
shopt -s extglob
# NOTE: Todo.sh requires the .todo/config configuration file to run. # NOTE: Todo.sh requires the .todo/config configuration file to run.
# Place the .todo/config file in your home directory or use the -d option for a custom location. # Place the .todo/config file in your home directory or use the -d option for a custom location.
@@ -44,12 +47,12 @@ shorthelp()
addto DEST "TEXT TO ADD" addto DEST "TEXT TO ADD"
addm "THINGS I NEED TO DO addm "THINGS I NEED TO DO
MORE THINGS I NEED TO DO" MORE THINGS I NEED TO DO"
append|app NUMBER "TEXT TO APPEND" append|app ITEM# "TEXT TO APPEND"
archive archive
command [ACTIONS] command [ACTIONS]
del|rm NUMBER [TERM] del|rm ITEM# [TERM]
dp|depri NUMBER dp|depri ITEM#[, ITEM#, ITEM#, ...]
do NUMBER do ITEM#[, ITEM#, ITEM#, ...]
help help
list|ls [TERM...] list|ls [TERM...]
listall|lsa [TERM...] listall|lsa [TERM...]
@@ -57,10 +60,10 @@ shorthelp()
listfile|lf SRC [TERM...] listfile|lf SRC [TERM...]
listpri|lsp [PRIORITY] listpri|lsp [PRIORITY]
listproj|lsprj listproj|lsprj
move|mv NUMBER DEST [SRC] move|mv ITEM# DEST [SRC]
prepend|prep NUMBER "TEXT TO PREPEND" prepend|prep ITEM# "TEXT TO PREPEND"
pri|p NUMBER PRIORITY pri|p ITEM# PRIORITY
replace NUMBER "UPDATED TODO" replace ITEM# "UPDATED TODO"
report report
See "help" for more details. See "help" for more details.
@@ -91,37 +94,37 @@ help()
Adds a line of text to any file located in the todo.txt directory. Adds a line of text to any file located in the todo.txt directory.
For example, addto inbox.txt "decide about vacation" For example, addto inbox.txt "decide about vacation"
append NUMBER "TEXT TO APPEND" append ITEM# "TEXT TO APPEND"
app NUMBER "TEXT TO APPEND" app ITEM# "TEXT TO APPEND"
Adds TEXT TO APPEND to the end of the todo on line NUMBER. Adds TEXT TO APPEND to the end of the task on line ITEM#.
Quotes optional. Quotes optional.
archive 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] command [ACTIONS]
Runs the remaining arguments using only todo.sh builtins. Runs the remaining arguments using only todo.sh builtins.
Will not call any .todo.actions.d scripts. Will not call any .todo.actions.d scripts.
del NUMBER [TERM] del ITEM# [TERM]
rm NUMBER [TERM] rm ITEM# [TERM]
Deletes the item on line NUMBER in todo.txt. Deletes the task on line ITEM# in todo.txt.
If term specified, deletes only the term from the line. If TERM specified, deletes only TERM from the task.
depri NUMBER depri ITEM#[, ITEM#, ITEM#, ...]
dp NUMBER dp ITEM#[, ITEM#, ITEM#, ...]
Deprioritizes (removes the priority) from the item Deprioritizes (removes the priority) from the task(s)
on line NUMBER in todo.txt. on line ITEM# in todo.txt.
do NUMBER[, NUMBER, NUMBER, ...] do ITEM#[, ITEM#, ITEM#, ...]
Marks item(s) on line NUMBER as done in todo.txt. Marks task(s) on line ITEM# as done in todo.txt.
help help
Display this help message. Display this help message.
list [TERM...] list [TERM...]
ls [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. numbers. If no TERM specified, lists entire todo.txt.
listall [TERM...] listall [TERM...]
@@ -142,36 +145,36 @@ help()
listpri [PRIORITY] listpri [PRIORITY]
lsp [PRIORITY] lsp [PRIORITY]
Displays all items prioritized PRIORITY. Displays all tasks prioritized PRIORITY.
If no PRIORITY specified, lists all prioritized items. If no PRIORITY specified, lists all prioritized tasks.
listproj listproj
lsprj lsprj
Lists all the projects that start with the + sign in todo.txt. Lists all the projects that start with the + sign in todo.txt.
move NUMBER DEST [SRC] move ITEM# DEST [SRC]
mv NUMBER DEST [SRC] mv ITEM# DEST [SRC]
Moves a line from source text file (SRC) to destination text file (DEST). 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 Both source and destination file must be located in the directory defined
in the configuration directory. When SRC is not defined in the configuration directory. When SRC is not defined
it's by default todo.txt. it's by default todo.txt.
prepend NUMBER "TEXT TO PREPEND" prepend ITEM# "TEXT TO PREPEND"
prep NUMBER "TEXT TO PREPEND" prep ITEM# "TEXT TO PREPEND"
Adds TEXT TO PREPEND to the beginning of the todo on line NUMBER. Adds TEXT TO PREPEND to the beginning of the task on line ITEM#.
Quotes optional. Quotes optional.
pri NUMBER PRIORITY pri ITEM# PRIORITY
p NUMBER PRIORITY p ITEM# PRIORITY
Adds PRIORITY to todo on line NUMBER. If the item is already Adds PRIORITY to task on line ITEM#. If the task is already
prioritized, replaces current priority with new PRIORITY. prioritized, replaces current priority with new PRIORITY.
PRIORITY must be an uppercase letter between A and Z. PRIORITY must be an uppercase letter between A and Z.
replace NUMBER "UPDATED TODO" replace ITEM# "UPDATED TODO"
Replaces todo on line NUMBER with UPDATED TODO. Replaces task on line ITEM# with UPDATED TODO.
report 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.
@@ -250,7 +253,7 @@ die()
cleanup() cleanup()
{ {
[ -f "$TMP_FILE" ] && rm "$TMP_FILE" [ -f "$TMP_FILE" ] && rm "$TMP_FILE"
exit 0 return 0
} }
cleaninput() cleaninput()
@@ -277,13 +280,68 @@ archive()
sed -i.bak '/^x /d' "$TODO_FILE" sed -i.bak '/^x /d' "$TODO_FILE"
cp "$TODO_FILE" "$TMP_FILE" cp "$TODO_FILE" "$TMP_FILE"
sed -n 'G; s/\n/&&/; /^\([ ~-]*\n\).*\n\1/d; s/\n//; h; P' "$TMP_FILE" > "$TODO_FILE" 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." if [ $TODOTXT_VERBOSE -gt 0 ]; then
[ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: $TODO_FILE archived." echo "TODO: $TODO_FILE archived."
[ $TODOTXT_GIT_ENABLED -eq 1 ] && \ fi
_commit "TODO: $TODO_FILE archived." $TODO_FILE $DONE_FILE
cleanup
} }
replaceOrPrepend()
{
action=$1; shift
case "$action" in
replace)
backref=
querytext="Replacement: "
;;
prepend)
backref=' &'
querytext="Prepend: "
;;
esac
shift; item=$1; shift
[ -z "$item" ] && die "$errmsg"
[[ "$item" = +([0-9]) ]] || die "$errmsg"
todo=$(sed "$item!d" "$TODO_FILE")
[ -z "$todo" ] && die "TODO: No task $item."
if [[ -z "$1" && $TODOTXT_FORCE = 0 ]]; then
echo -n "$querytext"
read input
else
input=$*
fi
cleaninput $input
# Retrieve existing priority and prepended date
priority=$(sed -e "$item!d" -e $item's/^\(([A-Z]) \)\{0,1\}\([0-9]\{2,4\}-[0-9]\{2\}-[0-9]\{2\} \)\{0,1\}.*/\1/' "$TODO_FILE")
prepdate=$(sed -e "$item!d" -e $item's/^\(([A-Z]) \)\{0,1\}\([0-9]\{2,4\}-[0-9]\{2\}-[0-9]\{2\} \)\{0,1\}.*/\2/' "$TODO_FILE")
if [ "$prepdate" -a "$action" = "replace" ] && [ "$(echo "$input"|sed -e 's/^\([0-9]\{2,4\}-[0-9]\{2\}-[0-9]\{2\}\)\{0,1\}.*/\1/')" ]; then
# If the replaced text starts with a date, it will replace the existing
# date, too.
prepdate=
fi
# Temporarily remove any existing priority and prepended date, perform the
# change (replace/prepend) and re-insert the existing priority and prepended
# date again.
sed -i.bak -e "$item s/^${priority}${prepdate}//" -e "$item s|^.*|${priority}${prepdate}${input}${backref}|" "$TODO_FILE"
if [ $TODOTXT_VERBOSE -gt 0 ]; then
newtodo=$(sed "$item!d" "$TODO_FILE")
case "$action" in
replace)
echo "$item $todo"
echo "TODO: Replaced task with:"
echo "$item $newtodo"
;;
prepend)
echo "$item $newtodo"
;;
esac
fi
}
# == PROCESS OPTIONS == # == PROCESS OPTIONS ==
while getopts ":fhpnatvVx+@Pd:" Option while getopts ":fhpnatvVx+@Pd:" Option
@@ -382,8 +440,6 @@ TODOTXT_DATE_ON_ADD=${TODOTXT_DATE_ON_ADD:-0}
TODOTXT_DEFAULT_ACTION=${TODOTXT_DEFAULT_ACTION:-} TODOTXT_DEFAULT_ACTION=${TODOTXT_DEFAULT_ACTION:-}
TODOTXT_SORT_COMMAND=${TODOTXT_SORT_COMMAND:-env LC_COLLATE=C sort -f -k2} TODOTXT_SORT_COMMAND=${TODOTXT_SORT_COMMAND:-env LC_COLLATE=C sort -f -k2}
TODOTXT_FINAL_FILTER=${TODOTXT_FINAL_FILTER:-cat} TODOTXT_FINAL_FILTER=${TODOTXT_FINAL_FILTER:-cat}
TODOTXT_GIT_ENABLED=${TODOTXT_GIT_ENABLED:-1}
TODOTXT_GIT_VERBOSE=${TODOTXT_GIT_VERBOSE:-0}
# Export all TODOTXT_* variables # Export all TODOTXT_* variables
export ${!TODOTXT_@} export ${!TODOTXT_@}
@@ -412,7 +468,16 @@ export DEFAULT='\\033[0m'
export PRI_A=$YELLOW # color for A priority export PRI_A=$YELLOW # color for A priority
export PRI_B=$GREEN # color for B priority export PRI_B=$GREEN # color for B priority
export PRI_C=$LIGHT_BLUE # color for C priority export PRI_C=$LIGHT_BLUE # color for C priority
export PRI_X=$WHITE # color for rest of them export PRI_X=$WHITE # color unless explicitly defined
# Default highlight colors.
export COLOR_DONE=$LIGHT_GREY # color for done (but not yet archived) tasks
# Default sentence delimiters for todo.sh append.
# If the text to be appended to the task begins with one of these characters, no
# whitespace is inserted in between. This makes appending to an enumeration
# (todo.sh add 42 ", foo") syntactically correct.
export SENTENCE_DELIMITERS=',.:;'
[ -e "$TODOTXT_CFG_FILE" ] || { [ -e "$TODOTXT_CFG_FILE" ] || {
CFG_FILE_ALT="$HOME/todo.cfg" CFG_FILE_ALT="$HOME/todo.cfg"
@@ -448,7 +513,7 @@ fi
} }
# === SANITY CHECKS (thanks Karl!) === # === SANITY CHECKS (thanks Karl!) ===
[ -r "$TODOTXT_CFG_FILE" ] || die "Fatal error: Cannot read configuration file $TODOTXT_CFG_FILE" [ -r "$TODOTXT_CFG_FILE" ] || die "Fatal Error: Cannot read configuration file $TODOTXT_CFG_FILE"
. "$TODOTXT_CFG_FILE" . "$TODOTXT_CFG_FILE"
@@ -464,16 +529,14 @@ ACTION=${1:-$TODOTXT_DEFAULT_ACTION}
[ -f "$REPORT_FILE" ] || cp /dev/null "$REPORT_FILE" [ -f "$REPORT_FILE" ] || cp /dev/null "$REPORT_FILE"
if [ $TODOTXT_PLAIN = 1 ]; then if [ $TODOTXT_PLAIN = 1 ]; then
PRI_A=$NONE for clr in ${!PRI_@}; do
PRI_B=$NONE export $clr=$NONE
PRI_C=$NONE done
PRI_X=$NONE PRI_X=$NONE
DEFAULT=$NONE DEFAULT=$NONE
COLOR_DONE=$NONE
fi fi
# === HEAVY LIFTING ===
shopt -s extglob
_addto() { _addto() {
file="$1" file="$1"
input="$2" input="$2"
@@ -484,69 +547,33 @@ _addto() {
input="$now $input" input="$now $input"
fi fi
echo "$input" >> "$file" echo "$input" >> "$file"
if [ $TODOTXT_VERBOSE -gt 0 ]; then
( [ $TODOTXT_VERBOSE -gt 0 ] || [ $TODOTXT_GIT_ENABLED -eq 1 ] ) && {
TASKNUM=$(sed -n '$ =' "$file") TASKNUM=$(sed -n '$ =' "$file")
BASE=$(basename "$file") BASE=$(basename "$file")
PREFIX=$(echo ${BASE%%.[^.]*} | tr [a-z] [A-Z]) PREFIX=$(echo ${BASE%%.[^.]*} | tr [a-z] [A-Z])
MESG="${PREFIX}: '$input' added on line $TASKNUM." echo "$TASKNUM $input"
[ $TODOTXT_VERBOSE -gt 0 ] && \ echo "${PREFIX}: $TASKNUM added."
echo $MESG
[ $TODOTXT_GIT_ENABLED -eq 1 ] && \
_commit "$MESG" $file
}
}
_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=$*
if [ $TODOTXT_GIT_VERBOSE -eq 0 ] ; then
( cd $TODO_DIR
for file in $FILES ; do
BASE=$(basename $file)
git add $BASE > /dev/null 2>&1
[ "$?" != 0 ] && die "Fatal Error: Git add $BASE failed."
done
git commit -m "$MESG" > /dev/null 2>&1
[ "$?" != 0 ] && die "Fatal Error: Git commit failed."
)
else
( cd $TODO_DIR
for file in $FILES ; do
BASE=$(basename $file)
git add $BASE
[ "$?" != 0 ] && die "Fatal Error: Git add $BASE failed."
done
git commit -m "$MESG"
[ "$?" != 0 ] && die "Fatal Error: Git commit failed."
)
fi fi
} }
_list() { _list() {
local FILE="$1" local FILE="$1"
## If the file starts with a "/" use absolute path. Otherwise, ## If the file starts with a "/" use absolute path. Otherwise,
## try to find it in either $TODO_DIR or using a relative path ## try to find it in either $TODO_DIR or using a relative path
if [ "${1:0:1}" == / ] if [ "${1:0:1}" == / ]; then
then
## Absolute path ## Absolute path
src="$FILE" src="$FILE"
elif [ -f "$TODO_DIR/$FILE" ] elif [ -f "$TODO_DIR/$FILE" ]; then
then
## Path relative to todo.sh directory ## Path relative to todo.sh directory
src="$TODO_DIR/$1" src="$TODO_DIR/$FILE"
elif [ -f "$FILE" ] elif [ -f "$FILE" ]; then
then
## Path relative to current working directory ## Path relative to current working directory
src="$FILE" src="$FILE"
elif [ -f "$TODO_DIR/${FILE}.txt" ]; then
## Path relative to todo.sh directory, missing file extension
src="$TODO_DIR/${FILE}.txt"
else else
echo "TODO: File $FILE does not exist." die "TODO: File $FILE does not exist."
exit 1
fi fi
## Get our search arguments, if any ## Get our search arguments, if any
@@ -555,10 +582,10 @@ _list() {
## Prefix the filter_command with the pre_filter_command ## Prefix the filter_command with the pre_filter_command
filter_command="${pre_filter_command:-}" filter_command="${pre_filter_command:-}"
for search_term in "$@" for search_term
do do
## See if the first character of $search_term is a dash ## See if the first character of $search_term is a dash
if [ ${search_term:0:1} != '-' ] if [ "${search_term:0:1}" != '-' ]
then then
## First character isn't a dash: hide lines that don't match ## First character isn't a dash: hide lines that don't match
## this $search_term ## this $search_term
@@ -610,13 +637,16 @@ _list() {
''' \ ''' \
| eval ${TODOTXT_SORT_COMMAND} \ | eval ${TODOTXT_SORT_COMMAND} \
| sed ''' | sed '''
/^[0-9]\{'$PADDING'\} x /! { /^[0-9]\{'$PADDING'\} x /s|^.*|'$COLOR_DONE'&'$DEFAULT'|
s/\(.*(A).*\)/'$PRI_A'\1'$DEFAULT'/g; ''' \
s/\(.*(B).*\)/'$PRI_B'\1'$DEFAULT'/g; | awk '''{
s/\(.*(C).*\)/'$PRI_C'\1'$DEFAULT'/g; pos = match($0, /\([A-Z]\)/)
s/\(.*([D-Z]).*\)/'$PRI_X'\1'$DEFAULT'/g; 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 ''' | sed '''
s/'${HIDE_PRIORITY_SUBSTITUTION:-^}'//g s/'${HIDE_PRIORITY_SUBSTITUTION:-^}'//g
s/'${HIDE_PROJECTS_SUBSTITUTION:-^}'//g s/'${HIDE_PROJECTS_SUBSTITUTION:-^}'//g
@@ -635,13 +665,12 @@ _list() {
echo "--" echo "--"
echo "${PREFIX}: ${NUMTASKS:-0} of ${TOTALTASKS:-0} tasks shown" echo "${PREFIX}: ${NUMTASKS:-0} of ${TOTALTASKS:-0} tasks shown"
fi fi
if [ $TODOTXT_VERBOSE -gt 1 ] if [ $TODOTXT_VERBOSE -gt 1 ]; then
then
echo "TODO DEBUG: Filter Command was: ${filter_command:-cat}" echo "TODO DEBUG: Filter Command was: ${filter_command:-cat}"
fi fi
} }
export -f _list export -f _list die
# == HANDLE ACTION == # == HANDLE ACTION ==
action=$( printf "%s\n" "$ACTION" | tr 'A-Z' 'a-z' ) action=$( printf "%s\n" "$ACTION" | tr 'A-Z' 'a-z' )
@@ -659,7 +688,9 @@ then
elif [ -d "$TODO_ACTIONS_DIR" -a -x "$TODO_ACTIONS_DIR/$action" ] elif [ -d "$TODO_ACTIONS_DIR" -a -x "$TODO_ACTIONS_DIR/$action" ]
then then
"$TODO_ACTIONS_DIR/$action" "$@" "$TODO_ACTIONS_DIR/$action" "$@"
status=$?
cleanup cleanup
exit $status
fi fi
## Only run if $action isn't found in .todo.actions.d ## Only run if $action isn't found in .todo.actions.d
@@ -674,7 +705,7 @@ case $action in
input=$* input=$*
fi fi
_addto "$TODO_FILE" "$input" _addto "$TODO_FILE" "$input"
cleanup;; ;;
"addm") "addm")
if [[ -z "$2" && $TODOTXT_FORCE = 0 ]]; then if [[ -z "$2" && $TODOTXT_FORCE = 0 ]]; then
@@ -696,7 +727,7 @@ case $action in
_addto "$TODO_FILE" "$line" _addto "$TODO_FILE" "$line"
done done
IFS=$SAVEIFS IFS=$SAVEIFS
cleanup;; ;;
"addto" ) "addto" )
[ -z "$2" ] && die "usage: $TODO_SH addto DEST \"TODO ITEM\"" [ -z "$2" ] && die "usage: $TODO_SH addto DEST \"TODO ITEM\""
@@ -709,9 +740,9 @@ case $action in
if [ -f "$dest" ]; then if [ -f "$dest" ]; then
_addto "$dest" "$input" _addto "$dest" "$input"
else else
echo "TODO: Destination file $dest does not exist." die "TODO: Destination file $dest does not exist."
fi fi
cleanup;; ;;
"append" | "app" ) "append" | "app" )
errmsg="usage: $TODO_SH append ITEM# \"TEXT TO APPEND\"" errmsg="usage: $TODO_SH append ITEM# \"TEXT TO APPEND\""
@@ -720,121 +751,126 @@ case $action in
[ -z "$item" ] && die "$errmsg" [ -z "$item" ] && die "$errmsg"
[[ "$item" = +([0-9]) ]] || die "$errmsg" [[ "$item" = +([0-9]) ]] || die "$errmsg"
todo=$(sed "$item!d" "$TODO_FILE") todo=$(sed "$item!d" "$TODO_FILE")
[ -z "$todo" ] && die "$item: No such todo." [ -z "$todo" ] && die "TODO: No task $item."
if [[ -z "$1" && $TODOTXT_FORCE = 0 ]]; then if [[ -z "$1" && $TODOTXT_FORCE = 0 ]]; then
echo -n "Append: " echo -n "Append: "
read input read input
else else
input=$* input=$*
fi fi
case "$input" in
[$SENTENCE_DELIMITERS]*) appendspace=;;
*) appendspace=" ";;
esac
cleaninput $input cleaninput $input
if sed -i.bak $item" s|^.*|& $input|" "$TODO_FILE"; then if sed -i.bak $item" s|^.*|&${appendspace}${input}|" "$TODO_FILE"; then
[ $TODOTXT_VERBOSE -gt 0 ] && { if [ $TODOTXT_VERBOSE -gt 0 ]; then
newtodo=$(sed "$item!d" "$TODO_FILE") newtodo=$(sed "$item!d" "$TODO_FILE")
echo "$item: $newtodo" echo "$item $newtodo"
} fi
[ $TODOTXT_GIT_ENABLED -eq 1 ] && \
_commit "TODO: Appended '$todo' w/ '$input' on line $item." \
$TODO_FILE
else else
echo "TODO: Error appending task $item." die "TODO: Error appending task $item."
fi fi
cleanup;; ;;
"archive" ) "archive" )
archive;; archive;;
"commit" )
[ -z "$2" ] && die "usage: $TODO_SH commit MESSAGE"
shift
MESG=$*
( cd $TODO_DIR
git commit -a -m "$MESG"
);;
"del" | "rm" ) "del" | "rm" )
# replace deleted line with a blank line when TODOTXT_PRESERVE_LINE_NUMBERS is 1 # replace deleted line with a blank line when TODOTXT_PRESERVE_LINE_NUMBERS is 1
errmsg="usage: $TODO_SH del ITEM#" errmsg="usage: $TODO_SH del ITEM# [TERM]"
item=$2 item=$2
[ -z "$item" ] && die "$errmsg" [ -z "$item" ] && die "$errmsg"
[[ "$item" = +([0-9]) ]] || die "$errmsg"
DELETEME=$(sed "$item!d" "$TODO_FILE")
[ -z "$DELETEME" ] && die "TODO: No task $item."
if [ -z "$3" ]; then if [ -z "$3" ]; then
if [ $TODOTXT_FORCE = 0 ]; then
[[ "$item" = +([0-9]) ]] || die "$errmsg" echo "Delete '$DELETEME'? (y/n)"
if sed -ne "$item p" "$TODO_FILE" | grep "^."; then read ANSWER
DELETEME=$(sed "$item!d" "$TODO_FILE") else
ANSWER="y"
if [ $TODOTXT_FORCE = 0 ]; then fi
echo "Delete '$DELETEME'? (y/n)" if [ "$ANSWER" = "y" ]; then
read ANSWER if [ $TODOTXT_PRESERVE_LINE_NUMBERS = 0 ]; then
# delete line (changes line numbers)
sed -i.bak -e $item"s/^.*//" -e '/./!d' "$TODO_FILE"
else else
ANSWER="y" # leave blank line behind (preserves line numbers)
sed -i.bak -e $item"s/^.*//" "$TODO_FILE"
fi fi
if [ "$ANSWER" = "y" ]; then if [ $TODOTXT_VERBOSE -gt 0 ]; then
if [ $TODOTXT_PRESERVE_LINE_NUMBERS = 0 ]; then echo "$item $DELETEME"
# delete line (changes line numbers) echo "TODO: $item deleted."
sed -i.bak -e $item"s/^.*//" -e '/./!d' "$TODO_FILE"
else
# leave blank line behind (preserves line numbers)
sed -i.bak -e $item"s/^.*//" "$TODO_FILE"
fi
[ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: '$DELETEME' deleted."
[ $TODOTXT_GIT_ENABLED -eq 1 ] && \
_commit "TODO: '$DELETEME' deleted." $TODO_FILE
cleanup
else
echo "TODO: No tasks were deleted."
fi fi
else else
echo "$item: No such todo." echo "TODO: No tasks were deleted."
fi fi
else else
sed -i.bak -e $item"s/$3/ /g" "$TODO_FILE" sed -i.bak \
[ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: $3 removed from $item." -e $item"s/^\((.) \)\{0,1\} *$3 */\1/g" \
[ $TODOTXT_GIT_ENABLED -eq 1 ] && \ -e $item"s/ *$3 *\$//g" \
_commit "TODO: $3 removed from $item." $TODO_FILE -e $item"s/ *$3 */ /g" \
fi ;; -e $item"s/ *$3 */ /g" \
-e $item"s/$3//g" \
"$TODO_FILE"
newtodo=$(sed "$item!d" "$TODO_FILE")
if [ "$DELETEME" = "$newtodo" ]; then
[ $TODOTXT_VERBOSE -gt 0 ] && echo "$item $DELETEME"
die "TODO: '$3' not found; no removal done."
fi
if [ $TODOTXT_VERBOSE -gt 0 ]; then
echo "$item $DELETEME"
echo "TODO: Removed '$3' from task."
echo "$item $newtodo"
fi
fi
;;
"depri" | "dp" ) "depri" | "dp" )
item=$2 errmsg="usage: $TODO_SH depri ITEM#[, ITEM#, ITEM#, ...]"
errmsg="usage: $TODO_SH depri ITEM#" shift;
[ $# -eq 0 ] && die "$errmsg"
todo=$(sed "$item!d" "$TODO_FILE") # Split multiple depri's, if comma separated change to whitespace separated
[ -z "$todo" ] && die "$item: No such todo." # Loop the 'depri' function for each item
[[ "$item" = +([0-9]) ]] || die "$errmsg" for item in `echo $* | tr ',' ' '`; do
[[ "$item" = +([0-9]) ]] || die "$errmsg"
todo=$(sed "$item!d" "$TODO_FILE")
[ -z "$todo" ] && die "TODO: No task $item."
sed -e $item"s/^(.) //" "$TODO_FILE" > /dev/null 2>&1 sed -e $item"s/^(.) //" "$TODO_FILE" > /dev/null 2>&1
if [ "$?" -eq 0 ]; then if [ "$?" -eq 0 ]; then
#it's all good, continue #it's all good, continue
sed -i.bak -e $item"s/^(.) //" "$TODO_FILE" sed -i.bak -e $item"s/^(.) //" "$TODO_FILE"
[ $TODOTXT_VERBOSE -gt 0 ] && { if [ $TODOTXT_VERBOSE -gt 0 ]; then
NEWTODO=$(sed "$item!d" "$TODO_FILE") NEWTODO=$(sed "$item!d" "$TODO_FILE")
echo "`echo "$item: $NEWTODO"`" echo "$item $NEWTODO"
echo "TODO: $item deprioritized." echo "TODO: $item deprioritized."
} fi
[ $TODOTXT_GIT_ENABLED -eq 1 ] && \ else
_commit "TODO: '$todo' deprioritized." $TODO_FILE die "$errmsg"
cleanup fi
else done
die "$errmsg" ;;
fi;;
"do" ) "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 so we get arguments to the do request
shift; 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 # Loop the 'do' function for each item
for item in `echo $* | tr ',' ' '`; do for item in `echo $* | tr ',' ' '`; do
[ -z "$item" ] && die "$errmsg" [ -z "$item" ] && die "$errmsg"
[[ "$item" = +([0-9]) ]] || die "$errmsg" [[ "$item" = +([0-9]) ]] || die "$errmsg"
todo=$(sed "$item!d" "$TODO_FILE") todo=$(sed "$item!d" "$TODO_FILE")
[ -z "$todo" ] && die "$item: No such todo." [ -z "$todo" ] && die "TODO: No task $item."
# Check if this item has already been done # Check if this item has already been done
if [ `echo $todo | grep -c "^x "` -eq 0 ] ; then if [ `echo $todo | grep -c "^x "` -eq 0 ] ; then
@@ -842,13 +878,11 @@ case $action in
# remove priority once item is done # remove priority once item is done
sed -i.bak $item"s/^(.) //" "$TODO_FILE" sed -i.bak $item"s/^(.) //" "$TODO_FILE"
sed -i.bak $item"s|^|&x $now |" "$TODO_FILE" sed -i.bak $item"s|^|&x $now |" "$TODO_FILE"
[ $TODOTXT_VERBOSE -gt 0 ] && { if [ $TODOTXT_VERBOSE -gt 0 ]; then
newtodo=$(sed "$item!d" "$TODO_FILE") newtodo=$(sed "$item!d" "$TODO_FILE")
echo "$item: $newtodo" echo "$item $newtodo"
echo "TODO: $item marked as done." echo "TODO: $item marked as done."
} fi
[ $TODOTXT_GIT_ENABLED -eq 1 ] && \
_commit "TODO: '$todo' marked as done." $TODO_FILE
else else
echo "$item is already marked done" echo "$item is already marked done"
fi fi
@@ -857,35 +891,13 @@ case $action in
if [ $TODOTXT_AUTO_ARCHIVE = 1 ]; then if [ $TODOTXT_AUTO_ARCHIVE = 1 ]; then
archive archive
fi 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" ) "help" )
if [ -t 1 ] ; then # STDOUT is a TTY 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) # we have a working PAGER (or less as a default)
help | exec ${PAGER:-less} help | "${PAGER:-less}" && exit 0
fi fi
fi fi
help # just in case something failed above, we go ahead and just spew to STDOUT help # just in case something failed above, we go ahead and just spew to STDOUT
@@ -894,8 +906,6 @@ case $action in
"list" | "ls" ) "list" | "ls" )
shift ## Was ls; new $1 is first search term shift ## Was ls; new $1 is first search term
_list "$TODO_FILE" "$@" _list "$TODO_FILE" "$@"
cleanup
;; ;;
"listall" | "lsa" ) "listall" | "lsa" )
@@ -903,8 +913,6 @@ case $action in
cat "$TODO_FILE" "$DONE_FILE" > "$TMP_FILE" cat "$TODO_FILE" "$DONE_FILE" > "$TMP_FILE"
_list "$TMP_FILE" "$@" _list "$TMP_FILE" "$@"
cleanup
;; ;;
"listfile" | "lf" ) "listfile" | "lf" )
@@ -913,18 +921,15 @@ case $action in
shift ## Was filename; next $1 is first search term shift ## Was filename; next $1 is first search term
_list "$FILE" "$@" _list "$FILE" "$@"
cleanup
;; ;;
"listcon" | "lsc" ) "listcon" | "lsc" )
grep -o '[^ ]*@[^ ]\+' "$TODO_FILE" | grep '^@' | sort -u grep -o '[^ ]*@[^ ]\+' "$TODO_FILE" | grep '^@' | sort -u
cleanup ;; ;;
"listproj" | "lsprj" ) "listproj" | "lsprj" )
grep -o '[^ ]*+[^ ]\+' "$TODO_FILE" | grep '^+' | sort -u grep -o '[^ ]*+[^ ]\+' "$TODO_FILE" | grep '^+' | sort -u
cleanup ;; ;;
"listpri" | "lsp" ) "listpri" | "lsp" )
shift ## was "listpri", new $1 is priority to list shift ## was "listpri", new $1 is priority to list
@@ -945,11 +950,6 @@ case $action in
_list "$TODO_FILE" "$pri" _list "$TODO_FILE" "$pri"
;; ;;
"log" | "pull" | "push" )
( cd $TODO_DIR
git $action
);;
"move" | "mv" ) "move" | "mv" )
# replace moved line with a blank line when TODOTXT_PRESERVE_LINE_NUMBERS is 1 # replace moved line with a blank line when TODOTXT_PRESERVE_LINE_NUMBERS is 1
errmsg="usage: $TODO_SH mv ITEM# DEST [SRC]" errmsg="usage: $TODO_SH mv ITEM# DEST [SRC]"
@@ -963,96 +963,40 @@ case $action in
[[ "$item" = +([0-9]) ]] || die "$errmsg" [[ "$item" = +([0-9]) ]] || die "$errmsg"
if [ -f "$src" ]; then [ -f "$src" ] || die "TODO: Source file $src does not exist."
if [ -f "$dest" ]; then [ -f "$dest" ] || die "TODO: Destination file $dest does not exist."
if sed -ne "$item p" "$src" | grep "^."; then
MOVEME=$(sed "$item!d" "$src")
if [ $TODOTXT_FORCE = 0 ]; then
echo "Move '$MOVEME' from $src to $dest? (y/n)"
read ANSWER
else
ANSWER="y"
fi
if [ "$ANSWER" = "y" ]; then
if [ $TODOTXT_PRESERVE_LINE_NUMBERS = 0 ]; then
# delete line (changes line numbers)
sed -i.bak -e $item"s/^.*//" -e '/./!d' "$src"
else
# leave blank line behind (preserves line numbers)
sed -i.bak -e $item"s/^.*//" "$src"
fi
echo "$MOVEME" >> "$dest"
[ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: '$MOVEME' moved from '$src' to '$dest'." MOVEME=$(sed "$item!d" "$src")
[ $TODOTXT_GIT_ENABLED -eq 1 ] && \ [ -z "$MOVEME" ] && die "$item: No such item in $src."
_commit "TODO: '$MOVEME' moved from '$src' to '$dest'." \ if [ $TODOTXT_FORCE = 0 ]; then
$src $dest echo "Move '$MOVEME' from $src to $dest? (y/n)"
cleanup read ANSWER
else else
echo "TODO: No tasks moved." ANSWER="y"
fi fi
else if [ "$ANSWER" = "y" ]; then
echo "$item: No such item in $src." if [ $TODOTXT_PRESERVE_LINE_NUMBERS = 0 ]; then
fi # delete line (changes line numbers)
sed -i.bak -e $item"s/^.*//" -e '/./!d' "$src"
else else
echo "TODO: Destination file $dest does not exist." # leave blank line behind (preserves line numbers)
sed -i.bak -e $item"s/^.*//" "$src"
fi
echo "$MOVEME" >> "$dest"
if [ $TODOTXT_VERBOSE -gt 0 ]; then
echo "$item $MOVEME"
echo "TODO: $item moved from '$src' to '$dest'."
fi fi
else else
echo "TODO: Source file $src does not exist." echo "TODO: No tasks moved."
fi fi
cleanup;; ;;
"prepend" | "prep" ) "prepend" | "prep" )
errmsg="usage: $TODO_SH prepend ITEM# \"TEXT TO PREPEND\"" errmsg="usage: $TODO_SH prepend ITEM# \"TEXT TO PREPEND\""
shift; item=$1; shift replaceOrPrepend 'prepend' "$@"
;;
[ -z "$item" ] && die "$errmsg"
[[ "$item" = +([0-9]) ]] || die "$errmsg"
todo=$(sed "$item!d" "$TODO_FILE")
[ -z "$todo" ] && die "$item: No such todo."
if [[ -z "$1" && $TODOTXT_FORCE = 0 ]]; then
echo -n "Prepend: "
read input
else
input=$*
fi
cleaninput $input
# Test for then set priority
if [ `sed "$item!d" "$TODO_FILE"|grep -c "^(\\w)"` -eq 1 ]; then
priority=$(sed "$item!d" "$TODO_FILE" | awk -F '\\(|\\)' '{print $2}')
fi
# If priority isn't set prepend
if [ -z $priority ]; then
if sed -i.bak $item" s|^.*|$input &|" "$TODO_FILE"; then
[ $TODOTXT_VERBOSE -gt 0 ] && {
newtodo=$(sed "$item!d" "$TODO_FILE")
echo "$item: $newtodo"
}
[ $TODOTXT_GIT_ENABLED -eq 1 ] && \
_commit "TODO: Prepended '$todo' w/ '$input' on line $item." \
$TODO_FILE
else
echo "TODO: Error prepending task $item."
fi
# If priority is set, remove priority, prepend and add back priority
else
if sed -i.bak -e "$item s/^(.) //" -e "$item s|^.*|\($priority\) $1 &|" "$TODO_FILE"; then
[ $TODOTXT_VERBOSE -gt 0 ] && {
newtodo=$(sed "$item!d" "$TODO_FILE")
echo "$item: $newtodo"
}
[ $TODOTXT_GIT_ENABLED -eq 1 ] && \
_commit "TODO: Prepended '$todo' w/ '$input' on line $item." \
$TODO_FILE
else
echo "TODO: Error prepending task $item."
fi
fi
cleanup;;
"pri" | "p" ) "pri" | "p" )
item=$2 item=$2
@@ -1070,56 +1014,20 @@ note: PRIORITY must be anywhere from A to Z."
if [ "$?" -eq 0 ]; then if [ "$?" -eq 0 ]; then
#it's all good, continue #it's all good, continue
sed -i.bak -e $item"s/^(.) //" -e $item"s/^/($newpri) /" "$TODO_FILE" sed -i.bak -e $item"s/^(.) //" -e $item"s/^/($newpri) /" "$TODO_FILE"
[ $TODOTXT_VERBOSE -gt 0 ] && { if [ $TODOTXT_VERBOSE -gt 0 ]; then
NEWTODO=$(sed "$item!d" "$TODO_FILE") NEWTODO=$(sed "$item!d" "$TODO_FILE")
echo "`echo "$item: $NEWTODO"`" echo "$item $NEWTODO"
echo "TODO: $item prioritized ($newpri)." echo "TODO: $item prioritized ($newpri)."
} fi
[ $TODOTXT_GIT_ENABLED -eq 1 ] && \
_commit "TODO: $item prioritized ($newpri)." $TODO_FILE
cleanup
else else
die "$errmsg" die "$errmsg"
fi;; fi
;;
"replace" ) "replace" )
errmsg="usage: $TODO_SH replace ITEM# \"UPDATED ITEM\"" errmsg="usage: $TODO_SH replace ITEM# \"UPDATED ITEM\""
shift; item=$1; shift replaceOrPrepend 'replace' "$@"
;;
[ -z "$item" ] && die "$errmsg"
[[ "$item" = +([0-9]) ]] || die "$errmsg"
todo=$(sed "$item!d" "$TODO_FILE")
[ -z "$todo" ] && die "$item: No such todo."
# Test for then set priority
if [ `sed "$item!d" "$TODO_FILE"|grep -c "^(\\w)"` -eq 1 ]; then
priority=$(sed "$item!d" "$TODO_FILE" | awk -F '\\(|\\)' '{print $2}')
fi
if [[ -z "$1" && $TODOTXT_FORCE = 0 ]]; then
echo -n "Replacement: "
read input
else
input=$*
fi
cleaninput $input
# If priority isn't set replace, if it is remove priority, replace then add priority again
if [ -z $priority ]; then
sed -i.bak $item" s|^.*|$input|" "$TODO_FILE"
else
sed -i.bak -e "$item s/^(.) //" -e "$item s|^.*|\($priority\) $1|" "$TODO_FILE"
fi
NEWTODO=$(head -$item "$TODO_FILE" | tail -1)
[ $TODOTXT_VERBOSE -gt 0 ] && {
echo "$item: $todo"
echo "replaced with"
echo "$item: $NEWTODO"
}
[ $TODOTXT_GIT_ENABLED -eq 1 ] && \
_commit "$item: $todo\nreplaced with\n$item: $NEWTODO" $TODO_FILE
cleanup;;
"report" ) "report" )
#archive first #archive first
@@ -1137,12 +1045,11 @@ note: PRIORITY must be anywhere from A to Z."
echo ${TDONE:-0}) echo ${TDONE:-0})
echo $TECHO >> "$REPORT_FILE" echo $TECHO >> "$REPORT_FILE"
[ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: Report file updated." [ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: Report file updated."
[ $TODOTXT_GIT_ENABLED -eq 1 ] && \
_commit "TODO: Report file updated." $REPORT_FILE
cat "$REPORT_FILE" cat "$REPORT_FILE"
cleanup;; ;;
* ) * )
usage usage;;
;;
esac esac
cleanup