12 ms·
How would you do colorization of matches outside of grep, other than reimplementing grep?
by BeeOnRope 8y ago
How would you do colorization of matches outside of grep, other than reimplementing grep?
- blihp 8y agoBy optionally emitting generic structural markup which you could then use to format via colorization (or whatever other means you wanted) in a terminal, a GUI, a web page, etc. That would have been more consistent with the 'one tool, one job' philosophy of Unix. So then you could do something along the lines of 'grep --emit-markup ... | colorize-markup' (completely made up switch and command names) and use aliases/environment variables/etc. so that to a user could type something like 'cgrep' to get colorized output.
- markrages 8y agobut the structure generator and decoder would be so closely coupled they might as well be the same program. Alternatively, you could have grep take a list of colors from a config file or environment variable and blindly interpolate those strings to make colored output[1]. This also allows color to show up automatically for interactive use. [1] this is in fact how grep works.
- hvis 8y agoThat's not all one might want to do the structured out. Think of converting to HTML, as one example.
- markrages 8y agolsusb | grep --color=always Linux | aha > grepped.html
- burntsushi 8y agoripgrep does have a JSON output mode, if you're curious. Of course, ripgrep handles coloring like GNU grep does.