Set $TODO_SH to just be $(basename "$0") at the beginning
of the script and use it in all usage messages.
This happens to simplify testing because it allows us to refer to
the script as "todo.sh" in all output. For general use, if the
user has aliased to file to something else, the usage messages will
still reflect that alias.
Signed-off-by: Emil Sit <sit@emilsit.net>
Users are probably unlikely to change the definition
of colors like $BLACK so just define them in todo.sh
and comment them out in todo.cfg. Similarly, leave
default values for priority coloring available but
commented out.
Signed-off-by: Emil Sit <sit@emilsit.net>
There were a couple places where $action was used without quotes
that caused a problem if the .todo.actions.d had a parent directory
path that included spaces (e.g. /cygdrive/c/Documents\ and\ Settings/jo-user).
This was in the section that calls the addons with the 'usage' arg.
Signed-off-by: Gina Trapani <ginatrapani@gmail.com>
Implement listcon and listproj in terms of grep -w -o, which prints
words that match the given regular expression, and sort -u, which
obviates uniq. This probably only works with GNU grep, which seems
better than having to rely on gawk (which is used nowhere else).
Signed-off-by: Emil Sit <sit@emilsit.net>
Signed-off-by: Gina Trapani <ginatrapani@gmail.com>
Single space after colon.
No end-of-line whitespace.
Replace tabs with whitespace.
Signed-off-by: Emil Sit <sit@emilsit.net>
Signed-off-by: Gina Trapani <ginatrapani@gmail.com>
When generating the distribution files, prepare todo.sh
by subbing in the current version so that users will
get a proper version number.
Tries to detect VERSION-FILE for running from
the development directory but this doesn't work well
when $PWD is not the top of the git repo.
Signed-off-by: Emil Sit <sit@emilsit.net>
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>
Put the old help message under a "help" command. The
short help message just lists the available commands and
should fit on a single screen.
Signed-off-by: Gina Trapani <ginatrapani@gmail.com>
The rewrite of ls functionality may have allowed blank but numbered
lines to creep into the ls display. Search for such lines and
exclude them.
Signed-off-by: Emil Sit <sit@emilsit.net>
Signed-off-by: Gina Trapani <ginatrapani@gmail.com>
Commit f55f5e8b5f introduced a known regression on Windows that
prevented users from using configuration files starting with C:\. The
following logic fixes this:
+ ## If the file starts with a "/" use absolute path. Otherwise,
+ ## try to find it in either $TODO_DIR or using a relative path
+ if [ "${1:0:1}" == / ]
+ then
+ ## Absolute path
+ src="$FILE"
+ elif [ -f "$TODO_DIR/$FILE" ]
+ then
+ ## Path relative to todo.sh directory
+ src="$TODO_DIR/$1"
+ elif [ -f "$FILE" ]
+ then
+ ## Path relative to current working directory
+ src="$FILE"
+ else
+ echo "TODO: File $FILE does not exist."
+ exit 1
+ fi
New _list function takes a filename and a list of search expressions.
We no longer use exec to call ourselves recursively.
Implemented several suggestions by Jacobo de Vera:
> 1. [lines 539-551]: [...] replace the for loop with simply this:
> PADDING=${#LINES}
> 2. [line 558]: As the script now supports a 6 digit number of tasks,
> the first substitution should add 5 spaces instead of 2
> 3. [lines 606-613]: The first search item is processed before the for
> loop, and the loop does the same for the rest. Wouldn't making this
> more general make the code more readable?
The changes for suggestion #3 let me add a new feature: when VERBOSE is
enabled, the summary line prints more info -- and it prints it on every
run:
$ todo.sh ls "buy a"
34 Buy a portable gas can @errands +safe
--
TODO: 1 of 49 tasks shown from /home/harding/var/git/todo/todo.txt
Also, generalizing and centralizing the code added a small but
measurable speed increase.
No new known regressions were introduced.
Essentially,
ls)
shift
exec "$TODO_SH" listfile "$TODO_FILE" "$@"
;;
lsa)
shift
cat "$TODO_FILE" "$DONE_FILE" > "$TMP_FILE"
exec $TODO_SH listfile "$TMP_FILE" "$@"
;;
lsp)
shift ## was "listpri"
shift ## was priority
exec $TODO_SH listfile "$TODO_FILE" "$pri" "$@"
;;;
Also adds the following features:
1. Numbers are padded with up to five zeros (but only the minimum
necessary), letting you list up to 999,999 tasks with the same
formatting.
2. All ls-family commands hide context, priority, and project when
the user sets those hide options.
3. Quoted arguments are passed on to grep as whole arguments,
enabling the following:
$ todo.sh ls buy a | head -n2
34 Buy a portable gas can
22 Buy door
$ todo.sh ls "buy a"
34 Buy a portable gas can
4. listfile can take an absolute path. Any filename starting with a
"/" will be treated as an absolute path; any other filename will
be treated as relative to $TODO_DIR. Since a leading "/" would be
striped by the operating system anyway under the old code, this
is fully backward compatible.
Contains the following regressions:
1. The ls verbose line count messages are more generic.
2. There is no verbose line count line for lspri.
3. I don't think listfile's absolute path feature will work on
Windows. If it doesn't, either this patch needs to be thrown
away, listall needs to be rewritten, or (my preference) $TMP_FILE
needs to set as relative to $TODO_DIR.