Skip to content

TQUERY: An interactive command query tool

I recently found myself searching for an alternative to the great, Windows-based file search tool Everything on Linux.

Many Linux alternatives exist, fsearch, plocate, docfetcher, recoll to name a few, but all of them were either trying to do too much in a single application (fsearch, docfetcher, recoll), or did not have the advantage of interactive search (plocate).

Implementation

Adding interactive search to plocate seemed like the most straight-forward way to achieve my goal. To faciliate the interactive querying, we can simply fork plocate every time the query changes, and collect the output through a pipe. To quickly and memory efficently index the entries, they are stored in a single chunk, and a second array keeps track of the offsets in that chunk which correspond to the entry delimeter. The rest is just a matter of using ncurses to display and navigate the entries.

This approach generalizes quite well to querying arbitrary other programs, not just plocate, so I refactored the functionality out into this tool.

Features

The program fits inside a single, small C file. You can find the source code at https://git.sinitax.com/sinitax/tquery.

By allowing selection of entries, and outputting them to stdout, tquery can be used in combination with other programs. Below are some useful examples.

Examples

Sytem-wide file search

tquery -o -s -- plocate --literal --ignore-case -- | xargs --open-tty vim

Regex full path search

tquery -o -- find . -iname | xargs --open-tty vim

Local line search

tquery -o -- grep -rn . -e | cut -d':' -f1 | xargs --open-tty vim