strigil
A minimal, dependency-free clone of grep, written in Rust using only the
standard library. Point it at a pattern and a file — or pipe it some standard
input — and it prints every matching line, with optional case-insensitive
matching and ANSI highlighting.
$ strigil the README.md
3:the end
Mission
strigil is built to be:
- Dependency-free — zero external crates. Only
std::fs,std::io, andstd::env. - Publishable — a single binary crate,
cargo publish --dry-runready. - Runnable —
cargo run -- <pattern> [<file>]from anywhere in the repo.
Features
- Manual CLI parsing — no clap, no derive macros:
strigil <pattern> [<file>] [--ignore-case] [--help] [--version]. - Standard input — omit the file (or pass
-) to search stdin, so it composes in pipelines. --helpand--version— informational flags that exit0.- Binary input detection — a NUL byte in the first chunk switches to raw-byte search with a grep-style "binary file matches" report.
- Buffered line-by-line reading via
std::io::BufReader. - Substring matching — a plain
find(), not a regex engine. --ignore-case— folds both the pattern and each line to lowercase before matching. The flag is accepted anywhere on the command line — before, between, or after the two positional arguments.- ANSI highlighting — set
COLOR=alwaysand the first match on each line is wrapped in red (\x1b[31m...\x1b[0m). - Predictable exit codes —
0match,1no match,2usage error,3I/O error.
Installation
From source (recommended)
From crates.io
Build locally
Usage
| Argument | Description |
|---|---|
<pattern> |
The literal substring to search for. |
<file> |
The file to read line by line; standard input when omitted or -. |
--ignore-case |
Match case-insensitively (accepted in any position). |
--help |
Print usage and exit 0. |
--version |
Print the version and exit 0. |
Note: matching is case-sensitive by default. There is no
-ishort flag.
Examples
# Find every line containing "fn main" in main.rs
# Case-insensitive search
# Flag order is flexible — before the positionals works too
# Highlight matches in red (single match per line only)
COLOR=always
# Search standard input — no file argument, or `-`
|
Exit codes
| Code | Meaning |
|---|---|
0 |
Matches found (or the input was empty). |
1 |
No matches found (but the input was read successfully). |
2 |
Usage error (wrong number of arguments or unknown flag). |
3 |
I/O error (file not found, permission denied, etc.). |
How it works
strigil is intentionally boring. main parses the arguments by hand, opens
the file with std::fs::File — or locks standard input when no file is given
— wraps it in std::io::BufReader, and iterates lines() one at a time. For each line it searches for the pattern with a
substring find(); when --ignore-case is given, both sides are folded to
lowercase first. On a match it prints {line_number}:{line} — with the first
occurrence wrapped in ANSI red when COLOR=always is set. Errors bubble up
with the ? operator and are mapped to the exit codes above.
There is no regex engine, no glob handling, and no memory beyond one line at a time (binary input is the exception: a small overlapping window is kept while scanning raw bytes) — that is the entire point of the project.
Development
Contributions are welcome — see CONTRIBUTING.md and please follow the Code of Conduct.
License
Licensed under the MIT License.