We have a huge, old, horrible codebase that makes it nearly impossible to find things when you need it. We're working on improving it, sure... but I often find myself doing massive recursive greps to search through the contents of files to find where things are used.
Is there a tool I can use to build a fulltext index of text files in a directory and then query that from the command-line?
Prefer something that can be run in user-space and doesn't need a daemon. We have many users on our dev server, so I want something that I can search through my instance of the codebase.
I'm a big fan of "gid" (aka "id-utils"):
- http://www.gnu.org/software/idutils/manual/idutils.html
Usage is simple:
Install id-utils with your favorite package manager (e.g. "sudo apt-get install" or "yum")
"cd" to the root of a source directory and run "mkid"
You can use it from the command line
You can also use it from "vim" or any number of other tools.
Russ Cox wrote a series of articles describing how the Google Code Search algorithm worked. He reimplements a simplified version of the algorithm in a set of command-line tools that can do fast regex searches over a local codebase.
An alternative is to use something like ctags to create an index of identifiers used in the code. Many editors (including Vim, which I use) can use this tags file to quickly jump to definitions of identifiers.
cd /path/to/project
ctags -R
this will create a tags
file that vim will use, then:
vim -t someFunctionName
will open vim in the function definition!
There's also some keyboard shortcuts to make life simpler.
CRTL+] will jump to the definition of the method under the cursor
CRTL+t will go back
I have a similar need to work on a large C++ project. After surveying some tools, I found that id-utils is the best choice because it's really fast on building index and searching patterns.
Based on id-utils, I made a command line tool and vim plugin to fix my need:
https://github.com/fcamel/gj
Hope it helps.