Open AndydeCleyre opened 4 years ago
I think what you are looking for is "positive lookbehind". I did not test it but it should look something like:
(?<=\d{4}-)\d{2}-\d{2}
I didn't realize that was supported here, thanks, I'll play with this. I also found this particular example goal can be achieved with
rainbow --blue-after '^\[\d{4}-' --reset-all-before 'T\d\d:\d\d:\d\d'
EDIT: Yes, thank you, your suggestion indeed works. I still like the --groups
syntax idea, but it does seem unnecessary now. Please close this if you like. Is the specific regex syntax supported mentioned anywhere?
Adding here, maybe just for documentation, that positive lookahead can also be used, as here in the --bold
switch:
when () { # <pkgname-filter>
((( $+commands[rainbow] )) &&
grep -aEi "ed [^ ]*$1" /var/log/pacman.log \
| rainbow \
--blue '(?<=^\[\d{4}-)\d{2}-\d{2}' \
--blue reinstalled \
--green installed \
--yellow upgraded \
--red removed \
--bold '[^ \(]+(?=\)$)' \
--cyan $1
) ||
grep -aEi "ed [^ ]*$1" /var/log/pacman.log
}
Example log output:
Example goal: colorize the
<month>-<day>
part of each line, if present.Current best possibility, as far as I know:
This also colorizes the
T
, which is useful for matching, but it would be nice to optionally specify a subset of each match to apply the color to.One possible approach: add up to one
--groups GROUPS
switch after each style-pattern switch, to limit the styling to specific parenthesized groups in the match:If it turns out to be better or simpler to work on exclusion instead, that's just as effective: