It can be useful to filter for non-consecutive priority ranges. By enforcing uppercase in that added syntax, overlap with general TERM(s) (e.g. "foo-bar") can be mostly avoided (and in the rare case of having to filter by all-uppercase TERM(s) one can always pass the default A-Z filter, anyway).
To indicate that something went wrong (e.g. the task already was unprioritized).
Note: For actions that handle multiple ITEMs in a loop, we cannot use die() as that would abort processing of any following ITEM(s). Instead, use a status variable and set it to 1 on error, then exit at the end.
I've seen strange readline editing behavior when the editing doesn't start at the first column: I can actually backspace into the prepended message (with Del, Ctrl-W or Ctrl-U), and then the whole edit becomes messed up.
read can output a prompt on its own (hopefully in all versions of Bash that we aim to support - the tests will tell), and that doesn't have this problem, and it's also a bit cleaner and shorter.
The prompt is only displayed if input is coming from a terminal. For the tests (currently only deletion and move confirmations are covered), this means that the prompt itself cannot be covered, and an empty line instead has to be expected. (On the positive side, this removes the ugly trick with $SPACE.)
So that any combination of priority / date entered in the replacement will replace the corresponding original ones, but if they are left out, the original ones will be kept.
In essence, omitted stuff will be kept, added stuff will override, only deletion of existing stuff is not possible (but this is replace, after all).
Fixes#386
I didn't know about printf's capability when I introduced quoting 10 years ago. The %q format will do the quoting, and "-v VAR" can be used to reassign to the variable.
Note: The shellquote() function has been exported for reuse by add-ons. I don't think anyone has ever used that (it was mostly intended for my own, extensive extensions, and I never used it), and is trivial to move away from, anyway.
Instead of potentially falling back to the built-in action that a custom action was intended to override, but (e.g. due to file system reorganizations) now results in a broken link. The extension functionality that is then skipped may result in undesired results, but this may not be immedately obvious to the user (if the extension is not particularly verbose), so some data corruption could occur if this remains undetected.
To avoid duplicating (or somehow extracting) all the built-in actions, simply detect _any_ broken symlink; i.e. offer a superset of the required functionality. So this would also complain about a broken symlink to a non-executable custom (auxiliary) file (rarely used) if that is mistakenly passed as a custom action (unlikely).
Fixes#359
* fix whitespace
* fix spelling
* fix whitespace
* unify headers of tests
* fix some issues in tests, identified by shellcheck
* fix bash completions
bash completion files are not supposed to be executable
* fix some issues identified by shellcheck
Co-authored-by: Ali Karbassi <ali@karbassi.com>
* Tests: Add coverage for del / move without -f, but with prompting
Supplying the user confirmation via "yes".
* Cosmetics: Align inconsistent spacing for before (y/n) prompt
* Refactoring: Extract confirm() function
The user confirmation query had been duplicated (once) in the code.
* Refactoring: confirm(): Leave early if forced
* Return from user prompt without requiring Enter
By just reading a single character (y for yes, anything else: no).
* Tests: Ensure that only a single "y" concludes the confirmation
By switching from "yes" (that endlessly prints newline-separated "y"s) to "printf y".
* t1800-del: Add coverage for negative confirmation
Negative means "anything but y", so "n", "x", and Enter all apply.
* Cosmetics: Add trailing space after (y/n) prompt
So that the user's typed answer is not recorded directly after it, but with separation: "Foo? (y/n) y" instead of "Foo? (y/n)y".
*Compatibility: "read -N 1" is only available in Bash 4.1+
Mac OS still ships with Bash 3.2 :-( Fall back to the original prompting that requires conclusion via Enter then.
Note: Even though the tests use "printf y", this still gets accepted, as there'll be EOF after that. In real use (when stdin from the terminal stays open), a concluding Enter is mandatory, though.
Closes#152
* Refactoring: Replace serial checks for `TODOTXT_CFG_FILE` and `TODO_ACTIONS_DIR` with loops
Two fallbacks (like for the actions dir) may still be fine, but we're now supporting so many config locations that a loop is much shorter, and the various locations are much easier to see.
For consistency, also apply this to the actions dir lookup, although it's less of a problem there.
* Refactoring: Apply the first default for `TODOTXT_CFG_FILE` also in the loop
There's no need to handle this separately; either an exported environment variable already exists, or it got assigned via `-d CONFIG_FILE`, or the `test -e` will fail on an empty (or bad non-existing) value, and we enter the fallback loop.
* Mention the actual config file locations in the help for `-d`
Extract the list of default locations into a `configFileLocations` array and join that into a string that then gets interpolated into the help output for `-d` (that so far only mentioned the first default location).
* Comments: Don't favor a single config location in the requirement
* Documentation: Mention `~/.todo/config` as just one of the defaults
As there are several others, now shown in the help for `-d`.
I don't want to duplicate the entire list here, as there's a high risk of those lists diverging.
Fixes#342
Uses current priority logic and option tests just running multiple times until item and priority pairs are exhausted or stops on first error.
Tests for multiple priorities, multiple re-prioritization and a couple of errors.
* Documentation: Clarify basic regexp syntax of TERM in todo.sh list
And give hints about escaping.
Issue raised by https://github.com/todotxt/todo.txt-cli/discussions/334
* Documentation: Correct quoting in todo.sh help list
Though the double quoting doesn't do harm when the single backslash is followed by the | character (\| is no valid escape sequence), it's technically more correct to use single quotes, and also is more in line with the quoting advice given directly below it.
* ENH: Allow to customize what can be before / inside / after +project and @context
I noticed that todo.sh mistakenly picks up some random stuff as projects and contexts. The todo.txt specification is very lenient in what makes those (allowing any length of non-whitespace characters), but in practice, every user has its own idea of the set of used words. This change allows (expert) users to tweak the pattern (via TODOTXT_SIGIL_VALID_PATTERN), to be able to reduce the amount of "false positives" that listproj and listcon show.
Additionally, there's a (mainly unspecified) extension mechanism in the form of key:value, which often is used to implement custom "markers", like w:something to make a task blocked and waiting for "something". It would be nice to be able to refer to @contexts (and maybe also +projects), but the default syntax (which requires whitespace around those) doesn't allow it, and these context then don't show up in searches, which is unfortunate. The added TODOTXT_SIGIL_BEFORE_PATTERN and TODOTXT_SIGIL_AFTER_PATTERN allow to tweak the syntax to accommodate this.
The implementation just exchanges grep with a corresponding sed pipeline step, which shouldn't negatively affect the performance at all (as sed is one of the main commands used thoughout the script), but which allows for the additional matching flexibility.
* FIX: Compatibility: sed \? multi not supported on MacOS
Use the POSIX \{0,1\} instead.
* FIX: Compatibility: sed \| multi not supported on MacOS
Concatenate both alternatives as optional matches; this is only an approximation but satisfies the test case here. It would probably be better if the entire sed code used extended regular expression syntax (-E) instead of basic ones (-e), but that change would also affect all add-ons. As this is an optional customization feature, uses who really need this either also have to work around, or supply a GNU sed port on MacOS.
* FIX: Compatibility: sed \+ multi not supported on MacOS
Use the POSIX \{1,\} instead.
Co-authored-by: Ali Karbassi <ali@karbassi.com>
* add highlighting of dates, item numbers, and metadata
* add test for highlighting of dates, item numbers, and metadata
Co-authored-by: Ali Karbassi <ali@karbassi.com>
* Handle missing EOL in todo.txt
This can happen easily with certain editors (such as Mousepad) that do not automatically add a newline character at the end of a file.
In _addto(), ensure a trailing newline via sed (taken from https://unix.stackexchange.com/a/31955/18876).
Fixes#294
* Tests: Add basic coverage of move
* Handle missing EOL in todo.txt for move, too
This can happen easily with certain editors (such as Mousepad) that do not automatically add a newline character at the end of a file.
* Refactoring: Extract fixMissingEndOfLine()
* FIX: Compatibility: sed \+ multi not supported on MacOS
Use the POSIX \{1,\} instead.
Co-authored-by: Ali Karbassi <ali@karbassi.com>
Adds the config / env variable `TODOTXT_PRIORITY_ON_ADD`, which when set to one of the capital letters `A` to `Z` is given as a priority to a new task, if a priority is not given on command line.
The use of the default read command will not allow the user to use arrow keys and shortcuts to enter the data when doing a replace or entering any input, which can be frustrating. Besides, backslashed are interpreted and can be mangled.
- Using the `-e` option will trigger the use of the readline library: you can then, as expected in bash, use the arrow keys and all shortcuts to move around the line before pressing enter.
- Using the `-r` option will prevent the interpretation of the "" and insert them as typed, useful when pasting code:
Addons can be placed in subfolders with the same name as the action,
in order to be able to e.g. clone git repos into the TODO_ACTIONS_DIR
rather than having to download addons and manage updates manually.
Closes#120
Because @contexts and +projects are metadata as much as they are text,
it can be nice to highlight them independently of the coloring of the line
that contains them. This is tough to do correctly in
a TODOTXT_FINAL_FILTER because doing it at that layer requires
re-parsing the text of the line to find the appropriate PRI_$x color to
reset to after coloring the word, or trying to reverse engineer where
the color codes inserted by todo.sh end and the user's text begins (and
vice versa).
Closes#119
Request from exatto (http://article.gmane.org/gmane.comp.diary.todotxt/4699), who doesn't want to use done.txt and report.txt.
Also consider character devices (-c; /dev/null is one) in the file existence checks so that no empty file is then created.
If not found elsewhere, look for the config file in /etc/todo/config.
`make install` installs a global config file, setting TODO_DIR=~/.todo.
todo.sh creates TODO_DIR if it doesn't exist.
The user may need the help to solve any fatal error that appears while todo.sh isn't properly set up. As the help actions do not depend on any setting that the fatal errors check, we can still invoke them.
Factor out dieWithHelp() and use that for printing the fatal errors.
POSIX sed doesn't support regex branches; I don't want to switch to modern regexp (via -E), since that makes more characters special. Rather, expand the alternatives into two sed commands.