Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

You don't need an explicit `--passthru` option. `rg '^|foo|bar|baz'` will print every line in the input while highlighting `foo`, `bar` and `baz`.

I'm pretty sure the PCRE lookaround support you're referring to is exactly what the GP meant by "Perl magic powers."



Thanks. That's good to know, though it's impossible for rg to do something like this at the moment.. highlight different regexes in different colors. Note that support of \K from PCRE is really crucial for this.

    # Do "ack2 --help" to learn more (or "ack2 --man" to learn even more).
    alias ack_passthru '\ack2 -h --flush --passthru --color \!:*'

    # USAGE: SIM_COMMAND | hllog
    alias hllog "ack_passthru   --color-match='white on_red'   '(\*[FE],\w+):' \\
                 | ack_passthru --color-match='white on_red'   '^(Error-\[.*?\].*)' \\
                 | ack_passthru --color-match='white on_red'   '(\*[FE],\w+)\b.*?([a-zA-Z_.0-9]+),(\d+)|\d+' \\
                 | ack_passthru --color-match='white on_red'   '^FOO Info\s+::\s+\K([1-9][0-9]* Runs (Failed|Missing))' \\
                 | ack_passthru --color-match='red'            '^UVM_[EF][ROATL]+\s+:\s+[1-9][0-9]*' \\
                 | ack_passthru --color-match='black on_white' '(\*W,\w+):' \\
                 | ack_passthru --color-match='black on_white' '(\*W,\w+)\b.*?([a-zA-Z_.0-9]+),(\d+)|\d+' \\
                 | ack_passthru --color-match='black on_white' '^(Warning-\[.*?\].*)' \\
                 | ack_passthru --color-match='yellow'         '^UVM_WARNING\s+:\s+[1-9][0-9]*' \\
                 | ack_passthru --color-match='yellow'         '^FOO Info\s+::\s+\K([1-9][0-9]* Runs with Warnings)' \\
                 | ack_passthru --color-match='yellow'         '^(FOO Warning\s+::.*)' \\
                 | ack_passthru --color-match='white on_red'   '^(FOO Error)\s+::' \\
                 | ack_passthru --color-match='white on_red'   '^(FOO Fatal)\s+::' \\
                 | ack_passthru --color-match='yellow'         '^(\*WARNING\*[, ].*)' \\
                 | ack_passthru --color-match='white on_red'   '^(\*ERROR\*)' \\
                 | ack_passthru --color-match='white on_red'   '^\s*(ERROR:)' \\
                 | ack_passthru --color-match='white on_red'   '^:\s*(ERROR:.*)' \\
                 | ack_passthru --color-match='red'            '^:\s*(FAILURE:.*)' \\
                 | ack_passthru --color-match='yellow'         '^:\s*((WARNING|LIMITATION):.*)' \\
                "


Huh? You can pretty much do exactly the same thing with ripgrep. There's no need for any fancy magic powers.

Example in the linux repo:

    rg --color always PM_RESUME | rg '^|PM_SUSPEND' --colors 'match:fg:green'




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: