_list: Fix line/item counting, accounting for blank lines.
If a file had blank lines or was totally empty, _list would result in an in-correct count of total items (either "" or the number of lines, instead of the number of items). This commit splits the filtering into three phases: line numbering, filtering (optional), and post-processing, and then does counting separately, if desired. Signed-off-by: Emil Sit <sit@emilsit.net> Signed-off-by: Gina Trapani <ginatrapani@gmail.com>
This commit is contained in:
24
todo.sh
24
todo.sh
@@ -438,13 +438,20 @@ _list() {
|
|||||||
LINES=$( sed -n '$ =' "$src" )
|
LINES=$( sed -n '$ =' "$src" )
|
||||||
PADDING=${#LINES}
|
PADDING=${#LINES}
|
||||||
|
|
||||||
## Number, sort, and mangle the file, then run the filter command,
|
## Number the file, then run the filter command,
|
||||||
## then mangle the file some more
|
## then sort and mangle output some more
|
||||||
command=$(
|
items=$(
|
||||||
sed = "$src" \
|
sed = "$src" \
|
||||||
| sed "N; s/^/ /; s/ *\(.\{$PADDING,\}\)\n/\1 /" \
|
| sed "N; s/^/ /; s/ *\(.\{$PADDING,\}\)\n/\1 /" \
|
||||||
| grep -v "^[0-9]\+ *$" \
|
| grep -v "^[0-9]\+ *$"
|
||||||
| eval ${filter_command:-cat} \
|
)
|
||||||
|
if [ "${filter_command}" ]; then
|
||||||
|
filtered_items=$(echo -ne "$items" | eval ${filter_command})
|
||||||
|
else
|
||||||
|
filtered_items=$items
|
||||||
|
fi
|
||||||
|
filtered_items=$(
|
||||||
|
echo -ne "$filtered_items" \
|
||||||
| sed '''
|
| sed '''
|
||||||
s/^ /00000/;
|
s/^ /00000/;
|
||||||
s/^ /0000/;
|
s/^ /0000/;
|
||||||
@@ -467,13 +474,14 @@ _list() {
|
|||||||
s/'${HIDE_CONTEXTS_SUBSTITUTION:-^}'//g
|
s/'${HIDE_CONTEXTS_SUBSTITUTION:-^}'//g
|
||||||
''' \
|
''' \
|
||||||
)
|
)
|
||||||
echo -ne "$command${command:+\n}"
|
echo -ne "$filtered_items${filtered_items:+\n}"
|
||||||
|
|
||||||
if [ $TODOTXT_VERBOSE -gt 0 ]; then
|
if [ $TODOTXT_VERBOSE -gt 0 ]; then
|
||||||
NUMTASKS=$( echo -ne "$command" | sed -n '$ =' )
|
NUMTASKS=$( echo -ne "$filtered_items" | sed -n '$ =' )
|
||||||
|
TOTALTASKS=$( echo -ne "$items" | sed -n '$ =' )
|
||||||
|
|
||||||
echo "--"
|
echo "--"
|
||||||
echo "TODO: ${NUMTASKS:-0} of $LINES tasks shown from $FILE"
|
echo "TODO: ${NUMTASKS:-0} of ${TOTALTASKS:-0} tasks shown from $FILE"
|
||||||
fi
|
fi
|
||||||
if [ $TODOTXT_VERBOSE -gt 1 ]
|
if [ $TODOTXT_VERBOSE -gt 1 ]
|
||||||
then
|
then
|
||||||
|
|||||||
Reference in New Issue
Block a user