Missing quoting inside cleaninput() condensed multiple subsequent spaces into a single space, even when the user took pains to preserve whitespace by properly quoting the task in the shell.
The 'tr' command completely removed CR and LF characters instead of replacing them with a single space.
Add test cases for the whitespace handling to the add, append, prepend and replace actions.
Commit 8e4364f5e1 removed the deletion of the "|" character from cleaninput. That was okay for the cleaninput() use in _addto(), but not in those cases that used $input for replacement via sed.
Added corresponding tests for replace, append and prepend actions similar to what was added for the add action in the above commit.
To really fix the problem (and not just remove all "|" characters from the text), a separator character must be found that is not part of $input, and this must be used in the sed expression. As cleaninput() already modifies the global $input variable, another $inputSep global variable is used to pass back this information.
In addition, backslashes must be escaped in $input, or replacements like \1 wreak havoc.
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.
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).
- _list() now shows the capitalized filename in place of 'TODO:'.
For example, listing garden.txt produces a output prefixed by 'GARDEN:'
This eliminates the ' from $FILE' part of the _list() output. All tests
were adjusted to match this new output.
Using the cleaninput function, to escape &'s on certain actions.
Currently the actions needing escaped &'s are append, prepend and replace.
Other actions including add need unescaped &'s.
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>
Add a test_todo_session function to test-lib.sh that enables
easy recording of input and output from todo.sh (including
annotation of exit status for testing error cases).
Begin to port and re-factor testsuite.txt into smaller
test cases, starting with basic add list functionality
and replace functionality.
Thanks to Philippe Teuwen <phil@teuwen.org> for feedback
and improvements.
Signed-off-by: Emil Sit <sit@emilsit.net>