$ show jhspetersson/fselect
fselect is a Rust command-line tool that enables searching the filesystem using SQL-like queries. It parses a SELECT-FROM-WHERE-GROUP BY-HAVING-ORDER BY-LIMIT syntax, traverses directories, and extracts rich metadata from files including size, timestamps, permissions, media information (EXIF, audio/video dimensions, duration), cryptographic hashes, MIME types, extended attributes, ACLs, git status, and more. The tool supports aggregation functions, subqueries (both FROM-subselects and correlated IN/EXISTS), and multiple output formats (tabular, CSV, JSON, HTML). It can accelerate searches via external indexes (Everything on Windows, plocate on Linux) and includes an interactive REPL mode. The architecture is a single binary with clean separation of concerns: lexer/parser for query processing, a searcher module for filesystem traversal and expression evaluation, utilities for metadata extraction, and pluggable output formatters.
The LLM identified 3 files worth highlighting for reuse:
An efficient, bounded priority queue for maintaining top-N elements during ORDER BY with LIMIT. It uses a max-heap based on custom weight criteria and discards lower-ranked items automatically. The module is isolated (no internal dependencies beyond standard library traits) and can be reused in any Rust project that needs to stream-rank items and only retain the top k.
A wrapper around any Write implementor that ensures UTF-8 multi-byte sequences are never split across write calls. This prevents corruption when outputting text incrementally (e.g., CSV rows) where partial characters would otherwise be emitted. Demonstrates careful byte-level buffering and can be extracted for any Rust project that writes encoded text in chunks.
Defines the `ResultsFormatter` trait with methods for outputting query results (headers, rows, footers). Implementations provide tabular, lines, list, CSV, JSON, and HTML formatting. The trait isolates output logic from core search, enabling easy addition or replacement of formats. This pattern can be repurposed for any system needing multiple serialization backends with a consistent interface.