One tool that makes my life as a software developer easier is OpenGrok - it lets me quickly find application code
and it knows more context than a simple
grep. It has a built-in web interface, but sometimes I want to work with
search results from the command line (particularly for automated tasks). Since I couldn’t find an API, I created a
command to load and parse results using symfony/console and xpath.
It’s straightforward to use, just provide the OpenGrok server, project to search, and the query. Mimicking grep, the output format should look familiar:
When run from an ANSI-friendly terminal, the output is nicely colorized. And just like the web interface, the
argument can include operators, nested queries, field specifiers, and wildcard searches.
It also has a
--list option to only output paths. Useful if I’m in the repository’s top-level and I want to work
through all the results with
I published the code to dpb587/opengrok-cli. Check the
README, but it’s easy to get started:
Or take the easier route and use the pre-compiled version: