The only reason for using ack these days is if you’re already invested in a Perl workflow and can use some of the Perl magic powers, and don’t care about comparatively poor performance. That’s not many people.
The only reason for using ack these days is if you’re already invested in a Perl workflow and can use some of the Perl magic powers, and don’t care about comparatively poor performance. That’s not many people.
Other reasons that you may want to use ack:
* You want to define your own filetypes
* You want to define your own output using Perl regexes
* You need the portability of an uncompiled tool in a single source file that you can drop into your ~/bin when you can't install or compile anything on the box.
* You don't want to have to deal with a Rust runtime.
You can define your own file types with ripgrep on the command line (albeit not in a config file, so you end up needing a wrapper script or an alias).
ripgrep has pre-compiled binaries that work out of the box on Windows, Mac and Linux.
"Rust runtime" isn't really a thing. It's like you saying you don't want to deal with a C runtime.
I'm glad to see that ripgrep lets you define your own types. That ripgrep does it with globbing vs. the ways that ack allows is just another of the differences between the tools that people have to decide about.
I believe that defining the output using Perl regexes was what I was referring to with “Perl magic powers”. I work at FastMail, the backend of which is mostly Perl, and have been unable to convince most people to use ripgrep because they like Perl and ack and occasionally use some of that fancy superpower. I, on the other hand, lack that experience (I’m most used to Python, Rust and JavaScript, and have never seriously worked in Perl) and thus don’t really get anything out of ack over ripgrep, without putting in a fair bit of effort to figure out what I need to do in a particular case. I’m more likely to feed the output through sed or vim if I want to rewrite it, actually!
I’m very glad that ack existed; it led the way with better tools, and I used it heavily for some years. Thanks for making it!
One of the things I'm working on right now is a cookbook that will ship with ack 3, currently about thisclose from going to beta. I want to show examples of the magic powers and see how powerful it can be. Your comment reinforces in my mind that it's an important thing to have.
> I’m very glad that ack existed; it led the way with better tools, and I used it heavily for some years. Thanks for making it!
You're very welcome. I'm continually pleased to see what's come out after it. A search tool arms race is a good thing.
It's interesting how git grep makes the ack feature of "ignore your VCS dirs" not so important any more. I wonder how the grep-alike tool world would look if git weren't so dominant, and/or git didn't include its own grep.
So I can have regex like 'abc\K(def)(?=ghi)'. That will highlight ONLY 'def' in the text but only if that string is preceeded by 'abc' and 'ghi' follows.
- ripgrep cannot do that as it does not support PCRE
ag support --passthrough, but I haven't yet felt the need to try that as ack --passthru has been baked into my workflow and aliases for ages.
I use ripgrep (rg) otherwise by default.
I'm pretty sure the PCRE lookaround support you're referring to is exactly what the GP meant by "Perl magic powers."
# 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):.*)' \\
"Example in the linux repo:
rg --color always PM_RESUME | rg '^|PM_SUSPEND' --colors 'match:fg:green'