TQUERY: Interactive tui querying

Last modification on

Motivation

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

I figured adding interactive search to plocate would be the most straight-forward way to achieve my goal, and went about creating an initial version, tlocate. To faciliate the interactive querying, we 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 (newline by default). The rest is just a matter of using ncurses to display and navigate the entries.

Eventually, I realized that this approach generalizes quite well to querying arbitrary other programs, not just plocate, and named the new, more UNIX-like version of the program tquery.

Features

The program fits inside a single, small C file. Granted, I am using liballoc and libdvec for the vector implementation, but even without these dependencies the total LOC would not exceed 1000 (~500 LOC atm). You can find the source code at https://git.sinitax.com/sinitax/tquery.

To keep the program simple, I've limited the amount of commandline options, and dont intend to add many more. By allowing selection of input 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 path search

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

Local line search

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