The regexp for the priority wasn't anchored to the beginning of the task. (As the filtering is done inside the _list pipeline, the task number has already been prepended.)
Also, by passing the regexp directly to _list, a case-insensitive search was performed, so despite [A-Z], lowercase characters were picked up, too. Need to make use of post_filter_command to inject a separate, case-sensitive grep into the pipeline.
Bonus: Added test for highlighting of listpri command.
This even simplified the argument handling, since there can be no invalid priority any more; all other strings are taken as TERMs. And the check for empty ${1:-} was superfluous, anyway. Apart from these simplifications, it's basically just passing $@ to _list.
Again, Bash's global pattern substitution can be used. This only depends on the "extquote" shell option, which is set by default, but we set this just to be sure.
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.
Despite its hard-coded use of $input, this can be useful in addons, too.
(I, for example, use this in a "todo.sh subst" addon that delegates to the "todo.sh replace" action after performing a sed-style replacement on the passed pattern and replacement.)
Improving on the previous fix and commit, no search for an unused substitution separator is actually needed; sed supports escaping of the substitution separator. Revert the $inputSep abstraction in favor of the former, hard-coded "|" character.
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.
Encoding the actions that require the additional sed-escaping inside cleaninput() is cumbersome and error-prone. Instead, let the calling action tell cleaninput() that it wants this.
* Added more flags to give action developers more control over commands
that are leveraged inside their actions.
* Writing a better message for the help screen
When using the -+ or -@ option to hide project or context names in list
output, the color reset sequence was being deleted if the project/context
was at the end of the line.
For example, with the following tasks:
(B) with priority, ending in a +project
task that shouldn't be highlighted
Running 'todo.sh -+ list' would hide the "+project" from the first task,
but would also remove the color reset sequence ^[[0m at the end. The
color from the prioritized task would continue to the next lines.
This commit fixes the problem and adds a test to verify the fix.
* inkarkat/master:
Cosmetics: Corrected inconsistent indentation.
Skipping 'nonexecutable action' test on Cygwin.
Factored out generation of custom action scripts.
Fixed test environment for escaped test output.
MINOR: Removed unnecessary empty & reference in sed substitution.
Avoiding todo.sh help error when .todo.actions.d contains subdirs.
BUG: interpretation of \033 escape sequences in task
BUG: task listing aborted on embedded \c escape sequence
BUG: tr: extra operand `d' error caused by missing quoting
On Cygwin, clearing the executable flag may have no effect, as the Windows ACL may still grant execution rights. In this case, we skip the test instead of failing.
- Reduced duplication via common make_action() function.
- ENH: Adding proper shebang line to the custom action scripts.
- Changed output of custom action to better differentiate from todo.sh output.
- test-lib uses 'read -r' to parse the test session input literally, without interpretation of backslashes.
- FIX: Use quoting to maintain original whitespace (tabs and multiple spaces) from the test session input (instead of condensing into a single space).
- Using Bash instead of POSIX shell for t1340-listescapes.sh, so that the interpretation of escape sequences is not dependent on the POSIX shell being used.
- Changed Makefile so that the shell selected by the shebang line is actually used when invoking tests, not the POSIX shell.
- Above changes obsolete the multiple escaping of the test session data; now, the test session can actually be pasted as-is into a test script, even when it contains backslashes. (I.e. works as expected now.)
I have placed tests for my custom todo actions in ~/.todo.actions.d/tests/; this causes a ".../.todo.actions.d/tests: is a directory" error on todo.sh help.
Added condition for regular files to the executable check in order to exclude subdirectories.
The global substitution in the AWK highlighting of prioritized and done tasks also affected the task text itself, not just the inserted color definitions.
Factored out the evaluation of the color variables and interpretation of \033 into a highlight() AWK function.
Added test cases which check that \a, \t, \n, \x.. and \0.. escape characters in the task text are listed as-is, without interpretation.
Fixed by removing the -e option that causes the echo command to interpret escape characters. Coloring of done tasks (the only step in the _list pipeline that required this interpretation) has been moved into the AWK pipeline step which is responsible for the priority coloring, and which does the escape character interpretation internally.
As a nice side effect, this shortening of the _list pipeline should also speed up the listing a wee bit.
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.
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.
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.
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.
- 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.
- 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.
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.
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).