GothenburgBitFactory / GothenburgBitFactory/taskwarrior
[TW-299] Make regular expressions behave more sed- or perl-like
- Dominant language
- C++
- Stars
- 6.1k
- Forks
- 423
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 11
Description
_Vivenzio Pagliari on 2013-08-07T19:11:00Z says:_
# Current behaviour
Currently, _task_ has basic support for regular expressions in filtering and modifying task. This regex support is available setting:
(at)rc.regex = yes@
However, the current implementation is limited regarding substitution as compared to tools like _sed_ or _grep_, as it
does not support "capture groups". This is quite useful for "batch operations" on similar tasks.
Consider the following example:
$ for issue in \#1174 \#1315 ; do task add Fix $issue on DEVBRANCH ; done
$ for br in 2.x 2.4.0 ; do task '/^Fix #[0-9]+/' duplicate "/Fix (#[0-9]+) on DEVBRANCH/backport \1 to $br/" ; done
The output is not as expected:
$ task nextID Age Urg Description
1 3m 0 Fix #1174 on DEVBRANCH
2 3m 0 Fix #1315 on DEVBRANCH
3 2m 0 backport \1 to 2.x
4 2m 0 backport \1 to 2.x
5 2m 0 backport \1 to 2.4.0
6 2m 0 backport \1 to 2.4.06 tasks
Note that a user accustomed to _sed_ behaviour would have likely written the last command (creation of backport tasks) as:
1. Leave pattern in subsitution empty, this would be repetitive; like in: $ sed '/foo/ s//bar/'
$ for br in 2.x 2.4.0 ; do task '/^Fix (#[0-9]+) on DEVBRANCH/' duplicate "//backport \1 to $br/" ; done
Such a thing is possible in _sed_ (and I think in _perl_ as well) as there the regex match from the "filter" (address in sed-speak)
is remembered and need not be repeated in the pattern to substitute. If the to-be-substituted pattern is empty, the match from the
address is used.
However, this command produces a totally unexpected results:
$ task
[task next]ID Age Urg Description
7 2s 0.9 Fix #1174 on DEVBRANCH
8/7/2013 / /backport \1 to 2.x/
8/7/2013 / /backport \1 to 2.4.0/
8 2s 0.9 Fix #1315 on DEVBRANCH
8/7/2013 / /backport \1 to 2.x/
8/7/2013 / /backport \1 to 2.4.0/
3 5s 0.8 Fix #1174 on DEVBRANCH
8/7/2013 / /backport \1 to 2.x/
4 5s 0.8 Fix #1315 on DEVBRANCH
8/7/2013 / /backport \1 to 2.x/
5 2s 0.8 Fix #1174 on DEVBRANCH
8/7/2013 / /backport \1 to 2.4.0/
6 2s 0.8 Fix #1315 on DEVBRANCH
8/7/2013 / /backport \1 to 2.4.0/
1 14s 0 Fix #1174 on DEVBRANCH
2 14s 0 Fix #1315 on DEVBRANCH8 tasks
# Requested modification
1. Support capture groups correctly, so that they can be back-referenced in substitutions.
1. When the substitution command has an empty pattern and the filter contains a regex, let that match be used.
# Additional notes
The feature request [[#1174]] asks for sed-like substitution command, which might be seen as related.
Contributor guide
Assessment
This issue has not been assessed yet.