Compare commits

..

12 Commits

Author SHA1 Message Date
Ingo Karkat
f3fc18af6b Optimization: Put grep -v empty task filter inside sed.
No need to spawn off another process for this; we can do this inside the sed command that joins the task numbers with the task text.

Note: The sed on OS X does not understand the \+ bound, only in the form of + when used with -E. Instead, I chose to fall back to the \{1,\} basic regexp, in the hope that it is very portable, and to avoid introducing extended regexps to the script.
2012-01-23 11:55:15 +01:00
Jean Jordaan
c99543506a Various helptext fixes
* 'Quotes optional.' doesn't make sense for 'addm', because without quotes, 'addm' is 'add'.
* There are no projects that don't start with a +.
* Don't tell people to type uppercase when the software takes care of it.
* Mention actions, mention filtering *out* terms.
* Fix link to wiki in the README
Closes #60
2012-01-20 11:46:30 -08:00
Ingo Karkat
b4aaba8387 Strip trailing whitespace when completing tasks. 2012-01-20 11:23:56 -08:00
Ingo Karkat
493e975199 Remove task date(s) when completing prioritized and done tasks.
Replace the primitive substitutions inside the completion function with a call to sed (instead of calling head), and supply more powerful substitutions there.
2012-01-20 11:23:56 -08:00
Ingo Karkat
fda31ea260 Avoid external TR when replacing , with space.
No need for an external tool, Bash can do a global literal substitution itself.
2012-01-20 11:17:37 -08:00
Ingo Karkat
8744167827 Add HIDE_CUSTOM_SUBSTITUTION for customization and add-ons.
Add-ons or users may want to hide parts of the task text from the output.
Though this can already be solved through TODOTXT_FINAL_FILTER, augmenting the configured value is not trivial, and it introduces another SED command into the already long _list() pipeline. Putting an additional HIDE_CUSTOM_SUBSTITUTION into the existing pipeline has hardly any performance implications, and makes the realization of this use case trivial.
2012-01-20 11:10:30 -08:00
Ingo Karkat
73e28b7225 BUG: SED error when HIDE_..._SUBSTITUTION contains whitespace.
This error only occurs when add-ons override either HIDE_PROJECTS_SUBSTITUTION or HIDE_CONTEXTS_SUBSTITUTION with a pattern that contains whitespace, not with the values used within todo.sh. But correcting the sloppy quoting doesn't hurt, neither.
2012-01-20 11:10:30 -08:00
Ingo Karkat
43bd1b645b Add hint for OR'ing TERMs to help text for ls/list.
The regexp syntax and quoting rules aren't known to many who are not well versed in the Bash shell, and difficult to get right even for people in the know. This question came up just recently on the mailing list, too.
2012-01-20 11:09:10 -08:00
Ingo Karkat
4db4494f03 Cosmetics: Correct double-spacing in help text. 2012-01-20 11:09:10 -08:00
Ingo Karkat
799840b664 Cosmetics: Consistently use "TERM(s)" in help text.
Two places only used "TERM" although multiple are supported. This can be misleading: do one or all have to match?
2012-01-20 11:09:10 -08:00
Ingo Karkat
54f15a7854 ENH: listall doesn't simply use concatenated task lists.
The simplistic "listall" action implementation just uses _list() on the concatenation of active and done task lists. This has the following shortcomings:

- Task numbers shown for archived tasks from done.txt are invalid.
- As the number of done tasks likely greatly outnumbers the number of active tasks, the task number padding is often larger than expected (e.g. 0005 instead of 05).
- Verbose output lists all tasks as originating from TODO, whereas it should differentiate between TODO: and DONE: sources.

The main challenge is to keep processing all tasks through a single pass of _list(), so that there is a single, unified sorting applied to all tasks. A custom AWK script sets all (originally invalid) task numbers from done.txt to "0", meaning "archived task".
The verbose message from _list() is replaced with a custom message that shows the tasks from todo.txt, done.txt, and totals.

Oh, and added tests for the previously untested "listall" action.
2012-01-20 11:07:28 -08:00
Ingo Karkat
17658c852d Reformatting: Lay out _list() file numbering in multi-line.
...like the following complex formatting and filtering steps.
2011-12-23 22:51:13 +01:00
6 changed files with 228 additions and 30 deletions

View File

@@ -21,6 +21,7 @@ h2. Quick Links
* Original anemic release by "Gina Trapani":http://ginatrapani.org on 5/11/2006. * Original anemic release by "Gina Trapani":http://ginatrapani.org on 5/11/2006.
* Raised to great heights by "brainy and dedicated volunteers":http://github.com/ginatrapani/todo.txt-cli/network. * Raised to great heights by "brainy and dedicated volunteers":http://github.com/ginatrapani/todo.txt-cli/network.
* Licensed under the "GPL":http://www.gnu.org/copyleft/gpl.html * Licensed under the "GPL":http://www.gnu.org/copyleft/gpl.html
* "Add-on Directory":http://wiki.github.com/ginatrapani/todo.txt-cli/todosh-add-on-directory * "Add-on Directory":https://github.com/ginatrapani/todo.txt-cli/wiki/Todo.sh-Add-on-Directory
https://github.com/ginatrapani/todo.txt-cli/wiki/Creating-and-Installing-Add-ons
* "Changelog":http://wiki.github.com/ginatrapani/todo.txt-cli/todosh-changelog * "Changelog":http://wiki.github.com/ginatrapani/todo.txt-cli/todosh-changelog
* "Known Bugs":http://github.com/ginatrapani/todo.txt-cli/issues * "Known Bugs":http://github.com/ginatrapani/todo.txt-cli/issues

View File

@@ -45,6 +45,8 @@ test_expect_success 'null listpri a' '
cat > expect <<EOF cat > expect <<EOF
-- --
TODO: 0 of 0 tasks shown TODO: 0 of 0 tasks shown
DONE: 0 of 0 tasks shown
total 0 of 0 tasks shown
EOF EOF
test_expect_success 'null lsa' ' test_expect_success 'null lsa' '

View File

@@ -53,6 +53,18 @@ test_todo_session 'checking TODOTXT_FINAL_FILTER' <<EOF
TODO: 3 of 3 tasks shown TODO: 3 of 3 tasks shown
EOF EOF
#
# check the custom hiding
#
test_todo_session 'checking HIDE_CUSTOM_SUBSTITUTION' <<EOF
>>> HIDE_CUSTOM_SUBSTITUTION='[tT]h' todo.sh ls
2 aaa zzz is line should be first.
3 bbb yyy is line should be second.
1 ccc xxx is line should be ird.
--
TODO: 3 of 3 tasks shown
EOF
# #
# check the filtering of TERM # check the filtering of TERM
# #

150
tests/t1350-listall.sh Executable file
View File

@@ -0,0 +1,150 @@
#!/bin/sh
test_description='listall functionality
'
. ./test-lib.sh
cat > todo.txt <<EOF
smell the uppercase Roses +flowers @outside
x 2011-08-08 tend the garden @outside
notice the sunflowers
x 2011-12-26 go outside +wakeup
(A) stop
EOF
cat > done.txt <<EOF
x 2011-12-01 eat breakfast
x 2011-12-05 smell the coffee +wakeup
EOF
test_todo_session 'basic listall' <<EOF
>>> todo.sh -p listall
5 (A) stop
3 notice the sunflowers
1 smell the uppercase Roses +flowers @outside
2 x 2011-08-08 tend the garden @outside
0 x 2011-12-01 eat breakfast
0 x 2011-12-05 smell the coffee +wakeup
4 x 2011-12-26 go outside +wakeup
--
TODO: 5 of 5 tasks shown
DONE: 2 of 2 tasks shown
total 7 of 7 tasks shown
EOF
test_todo_session 'listall highlighting' <<EOF
>>> todo.sh listall
5 (A) stop
3 notice the sunflowers
1 smell the uppercase Roses +flowers @outside
2 x 2011-08-08 tend the garden @outside
0 x 2011-12-01 eat breakfast
0 x 2011-12-05 smell the coffee +wakeup
4 x 2011-12-26 go outside +wakeup
--
TODO: 5 of 5 tasks shown
DONE: 2 of 2 tasks shown
total 7 of 7 tasks shown
EOF
test_todo_session 'listall nonverbose' <<EOF
>>> TODOTXT_VERBOSE=0 todo.sh -p listall
5 (A) stop
3 notice the sunflowers
1 smell the uppercase Roses +flowers @outside
2 x 2011-08-08 tend the garden @outside
0 x 2011-12-01 eat breakfast
0 x 2011-12-05 smell the coffee +wakeup
4 x 2011-12-26 go outside +wakeup
EOF
test_todo_session 'listall filtering' <<EOF
>>> todo.sh -p listall @outside
1 smell the uppercase Roses +flowers @outside
2 x 2011-08-08 tend the garden @outside
--
TODO: 2 of 5 tasks shown
DONE: 0 of 2 tasks shown
total 2 of 7 tasks shown
>>> todo.sh -p listall the
3 notice the sunflowers
1 smell the uppercase Roses +flowers @outside
2 x 2011-08-08 tend the garden @outside
0 x 2011-12-05 smell the coffee +wakeup
--
TODO: 3 of 5 tasks shown
DONE: 1 of 2 tasks shown
total 4 of 7 tasks shown
>>> todo.sh -p listall breakfast
0 x 2011-12-01 eat breakfast
--
TODO: 0 of 5 tasks shown
DONE: 1 of 2 tasks shown
total 1 of 7 tasks shown
>>> todo.sh -p listall doesnotmatch
--
TODO: 0 of 5 tasks shown
DONE: 0 of 2 tasks shown
total 0 of 7 tasks shown
EOF
cat >> done.txt <<EOF
x 2010-01-01 old task 1
x 2010-01-01 old task 2
x 2010-01-01 old task 3
x 2010-01-01 old task 4
EOF
test_todo_session 'listall number width' <<EOF
>>> todo.sh -p listall
5 (A) stop
3 notice the sunflowers
1 smell the uppercase Roses +flowers @outside
0 x 2010-01-01 old task 1
0 x 2010-01-01 old task 2
0 x 2010-01-01 old task 3
0 x 2010-01-01 old task 4
2 x 2011-08-08 tend the garden @outside
0 x 2011-12-01 eat breakfast
0 x 2011-12-05 smell the coffee +wakeup
4 x 2011-12-26 go outside +wakeup
--
TODO: 5 of 5 tasks shown
DONE: 6 of 6 tasks shown
total 11 of 11 tasks shown
>>> TODOTXT_VERBOSE=0 todo.sh add new task 1
>>> TODOTXT_VERBOSE=0 todo.sh add new task 2
>>> TODOTXT_VERBOSE=0 todo.sh add new task 3
>>> TODOTXT_VERBOSE=0 todo.sh add new task 4
>>> TODOTXT_VERBOSE=0 todo.sh add new task 5
>>> todo.sh -p listall
05 (A) stop
06 new task 1
07 new task 2
08 new task 3
09 new task 4
10 new task 5
03 notice the sunflowers
01 smell the uppercase Roses +flowers @outside
00 x 2010-01-01 old task 1
00 x 2010-01-01 old task 2
00 x 2010-01-01 old task 3
00 x 2010-01-01 old task 4
02 x 2011-08-08 tend the garden @outside
00 x 2011-12-01 eat breakfast
00 x 2011-12-05 smell the coffee +wakeup
04 x 2011-12-26 go outside +wakeup
--
TODO: 10 of 10 tasks shown
DONE: 6 of 6 tasks shown
total 16 of 16 tasks shown
EOF
test_done

61
todo.sh
View File

@@ -67,6 +67,8 @@ shorthelp()
report report
shorthelp shorthelp
Actions can be added and overridden using scripts in the actions
directory.
EndHelp EndHelp
# Only list the one-line usage from the add-on actions. This assumes that # Only list the one-line usage from the add-on actions. This assumes that
@@ -162,7 +164,6 @@ help()
Adds FIRST THING I NEED TO DO to your todo.txt on its own line and Adds FIRST THING I NEED TO DO to your todo.txt on its own line and
Adds SECOND THING I NEED TO DO to you todo.txt on its own line. Adds SECOND THING I NEED TO DO to you todo.txt on its own line.
Project and context notation optional. Project and context notation optional.
Quotes optional.
addto DEST "TEXT TO ADD" addto DEST "TEXT TO ADD"
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.
@@ -199,16 +200,19 @@ help()
list [TERM...] list [TERM...]
ls [TERM...] ls [TERM...]
Displays all tasks that contain TERM(s) sorted by priority with line Displays all tasks that contain TERM(s) sorted by priority with line
numbers. Each task must match all TERMs (logical AND); to display numbers. Each task must match all TERM(s) (logical AND); to display
tasks that contain any TERM (logical OR), use tasks that contain any TERM (logical OR), use
"TERM1\|TERM2\|..." (with quotes), or TERM1\\\|TERM2 (unquoted). "TERM1\|TERM2\|..." (with quotes), or TERM1\\\|TERM2 (unquoted).
If no TERM specified, lists entire todo.txt. Hides all tasks that contain TERM(s) preceded by a
minus sign (i.e. -TERM). If no TERM specified, lists entire todo.txt.
listall [TERM...] listall [TERM...]
lsa [TERM...] lsa [TERM...]
Displays all the lines in todo.txt AND done.txt that contain TERM(s) Displays all the lines in todo.txt AND done.txt that contain TERM(s)
sorted by priority with line numbers. If no TERM specified, lists sorted by priority with line numbers. Hides all tasks that
entire todo.txt AND done.txt concatenated and sorted. contain TERM(s) preceded by a minus sign (i.e. -TERM). If no
TERM specified, lists entire todo.txt AND done.txt
concatenated and sorted.
listcon listcon
lsc lsc
@@ -217,20 +221,24 @@ help()
listfile [SRC [TERM...]] listfile [SRC [TERM...]]
lf [SRC [TERM...]] lf [SRC [TERM...]]
Displays all the lines in SRC file located in the todo.txt directory, Displays all the lines in SRC file located in the todo.txt directory,
sorted by priority with line numbers. If TERM specified, lists sorted by priority with line numbers. If TERM specified, lists
all lines that contain TERM(s) in SRC file. all lines that contain TERM(s) in SRC file. Hides all tasks that
contain TERM(s) preceded by a minus sign (i.e. -TERM).
Without any arguments, the names of all text files in the todo.txt Without any arguments, the names of all text files in the todo.txt
directory are listed. directory are listed.
listpri [PRIORITY] [TERM...] listpri [PRIORITY] [TERM...]
lsp [PRIORITY] [TERM...] lsp [PRIORITY] [TERM...]
Displays all tasks prioritized PRIORITY. Displays all tasks prioritized PRIORITY.
If no PRIORITY specified, lists all prioritized tasks. If no PRIORITY specified, lists all prioritized tasks.
If TERM specified, lists only prioritized tasks that contain TERM(s). If TERM specified, lists only prioritized tasks that contain TERM(s).
Hides all tasks that contain TERM(s) preceded by a minus sign
(i.e. -TERM).
listproj listproj
lsprj lsprj
Lists all the projects that start with the + sign in todo.txt. Lists all the projects (terms that start with a + sign) in
todo.txt.
move ITEM# DEST [SRC] move ITEM# DEST [SRC]
mv ITEM# DEST [SRC] mv ITEM# DEST [SRC]
@@ -248,7 +256,7 @@ help()
p ITEM# PRIORITY p ITEM# PRIORITY
Adds PRIORITY to task on line ITEM#. If the task 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 a letter between A and Z.
replace ITEM# "UPDATED TODO" replace ITEM# "UPDATED TODO"
Replaces task on line ITEM# with UPDATED TODO. Replaces task on line ITEM# with UPDATED TODO.
@@ -259,7 +267,6 @@ help()
shorthelp shorthelp
List the one-line usage of all built-in and add-on actions. List the one-line usage of all built-in and add-on actions.
EndActionsHelp EndActionsHelp
addonHelp addonHelp
@@ -778,8 +785,12 @@ _list() {
fi fi
items=$( items=$(
sed = "$src" \ sed = "$src" \
| sed "N; s/^/ /; s/ *\(.\{$PADDING,\}\)\n/\1 /" \ | sed -e '''
| grep -v "^[ 0-9]\+ *$" N
s/^/ /
s/ *\([ 0-9]\{'"$PADDING"',\}\)\n/\1 /
/^[ 0-9]\{1,\} *$/d
'''
) )
if [ "${filter_command}" ]; then if [ "${filter_command}" ]; then
filtered_items=$(echo -n "$items" | eval "${filter_command}") filtered_items=$(echo -n "$items" | eval "${filter_command}")
@@ -815,8 +826,9 @@ _list() {
} }
''' \ ''' \
| sed ''' | sed '''
s/'${HIDE_PROJECTS_SUBSTITUTION:-^}'//g s/'"${HIDE_PROJECTS_SUBSTITUTION:-^}"'//g
s/'${HIDE_CONTEXTS_SUBSTITUTION:-^}'//g s/'"${HIDE_CONTEXTS_SUBSTITUTION:-^}"'//g
s/'"${HIDE_CUSTOM_SUBSTITUTION:-^}"'//g
''' \ ''' \
| eval ${TODOTXT_FINAL_FILTER} \ | eval ${TODOTXT_FINAL_FILTER} \
) )
@@ -994,7 +1006,7 @@ case $action in
# Split multiple depri's, if comma separated change to whitespace separated # Split multiple depri's, if comma separated change to whitespace separated
# Loop the 'depri' function for each item # Loop the 'depri' function for each item
for item in $(echo $* | tr ',' ' '); do for item in ${*//,/ }; do
getTodo "$item" getTodo "$item"
if [[ "$todo" = \(?\)\ * ]]; then if [[ "$todo" = \(?\)\ * ]]; then
@@ -1018,7 +1030,7 @@ case $action in
# Split multiple do's, if comma separated change to whitespace separated # 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 ${*//,/ }; do
getTodo "$item" getTodo "$item"
# Check if this item has already been done # Check if this item has already been done
@@ -1071,7 +1083,20 @@ case $action in
shift ## Was lsa; new $1 is first search term shift ## Was lsa; new $1 is first search term
cat "$TODO_FILE" "$DONE_FILE" > "$TMP_FILE" cat "$TODO_FILE" "$DONE_FILE" > "$TMP_FILE"
_list "$TMP_FILE" "$@" TOTAL=$( sed -n '$ =' "$TODO_FILE" )
post_filter_command="awk -v TOTAL=$TOTAL -v PADDING=${#TOTAL} '{ \$1 = sprintf(\"%\" PADDING \"d\", (\$1 > TOTAL ? 0 : \$1)); print }' "
TODOTXT_VERBOSE=0 _list "$TMP_FILE" "$@"
if [ $TODOTXT_VERBOSE -gt 0 ]; then
TDONE=$( sed -n '$ =' "$DONE_FILE" )
TASKNUM=$(TODOTXT_PLAIN=1 TODOTXT_VERBOSE=0 _list "$TODO_FILE" "$@" | sed -n '$ =')
DONENUM=$(TODOTXT_PLAIN=1 TODOTXT_VERBOSE=0 _list "$DONE_FILE" "$@" | sed -n '$ =')
echo "--"
echo "$(getPrefix "$TODO_FILE"): ${TASKNUM:-0} of ${TOTAL:-0} tasks shown"
echo "$(getPrefix "$DONE_FILE"): ${DONENUM:-0} of ${TDONE:-0} tasks shown"
echo "total $((TASKNUM + DONENUM)) of $((TOTAL + TDONE)) tasks shown"
fi
;; ;;
"listfile" | "lf" ) "listfile" | "lf" )

View File

@@ -38,20 +38,28 @@ _todo()
+*) completions=$(TODOTXT_VERBOSE=0 todo.sh command listproj);; +*) completions=$(TODOTXT_VERBOSE=0 todo.sh command listproj);;
@*) completions=$(TODOTXT_VERBOSE=0 todo.sh command listcon);; @*) completions=$(TODOTXT_VERBOSE=0 todo.sh command listcon);;
*) if [[ "$cur" =~ ^[0-9]+$ ]]; then *) if [[ "$cur" =~ ^[0-9]+$ ]]; then
local item=$(TODOTXT_VERBOSE=0 todo.sh -@ -+ -p -x command ls "^ *${cur} " | head -n 1)
# Remove the (padded) task number; we prepend the # Remove the (padded) task number; we prepend the
# user-provided $cur. # user-provided $cur instead.
item=${item#* } # Remove the timestamp prepended by the -t option,
# and the done date (for done tasks); there's no
# Remove the timestamp prepended by the -t option; # todo.txt option for that yet.
# there's no todo.txt option for that yet. # But keep priority and "x"; they're short and may
item=${item#[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9] } # provide useful context.
# Remove any trailing whitespace; the Bash
# completion inserts a trailing space itself.
# Finally, limit the output to a single line just as
# a safety check of the ls action output.
local todo=$( \
TODOTXT_VERBOSE=0 todo.sh -@ -+ -p -x command ls "^ *${cur} " | \
sed -e 's/^ *[0-9]\+ //' -e 's/\((.) \)[0-9]\{2,4\}-[0-9]\{2\}-[0-9]\{2\} /\1/' \
-e 's/\([xX] \)\([0-9]\{2,4\}-[0-9]\{2\}-[0-9]\{2\} \)\{1,2\}/\1/' \
-e 's/[[:space:]]*$//' \
-e '1q' \
)
# Append task text as a shell comment. This # Append task text as a shell comment. This
# completion can be a safety check before a # completion can be a safety check before a
# destructive todo.txt operation. # destructive todo.txt operation.
[ "$item" ] && COMPREPLY[0]="$cur # $item" [ "$todo" ] && COMPREPLY[0]="$cur # $todo"
return 0 return 0
else else
return 0 return 0