Repository navigation
fix(grep): translate --include/--exclude to rg --glob - #2607
vegetablechicken233 wants to merge 1 commit into
Conversation
grep's --include=GLOB / --exclude=GLOB have no ripgrep equivalent, so rtk forwarded them to rg verbatim; rg rejected them (exit 2) and the grep_capture fallback (rtk-ai#2543/rtk-ai#2550) re-ran the query through system grep. That works but gives up ripgrep's speed for a very common idiom. Translate them up front to ripgrep's -g GLOB / -g !GLOB (rg negates a glob with a leading !) so the fast rg path serves them directly. Only the = form is handled — the sole spelling GNU/BSD grep accept for these flags. The grep fallback keeps the originals untranslated, so an rg-rejected invocation still works there. Builds on the approach proposed in rtk-ai#2131, reworked for the current grep_capture structure. Co-Authored-By: Claude Fable 5 <[email protected]>
|
Hi! Small, self-contained follow-up in the grep area: it translates GNU grep's |
|
Hi @vegetablechicken233, thanks for your PR. Before I review it, if this work is based on someone else’s contributions, please add a Co-authored-by: trailer to the commit message so they’re properly credited. Example: This helps ensure accurate attribution for all contributors. Thanks! |
|
Thanks for this. The rg path this targets is gone: PR #2641 (merged 2026-06-26) removed src/cmds/system/grep_cmd.rs and made RTK run the engine you actually invoked rather than substituting rg for grep, so |
What
Translate grep's
--include=GLOB/--exclude=GLOBinto ripgrep's-g GLOB/-g !GLOBin the rg path, so the fast ripgrep path handles file-type filtering directly.Why
ripgrep has no
--include. Today rtk forwards--includeto rg verbatim; rg rejects it (exit 2), and thegrep_capturefallback (#2543 / #2550) re-runs the query through system grep, which understands--includenatively. That works, but it gives up ripgrep's speed and means a very common grep idiom always takes the slow fallback path. Translating the flag lets the rg path serve it.How
translate_grep_globs()rewrites--include=GLOB→-g GLOBand--exclude=GLOB→-g !GLOB(ripgrep negates a glob with a leading!); every other arg is forwarded unchanged.grep_capture, so both the main and passthrough call sites benefit. The grep fallback path keeps the untranslated originals, so an rg-rejected invocation still works there.=spelling is handled — the sole form GNU/BSD grep accept for these flags.Tests
Unit tests for the translation (include, exclude, mixed-with-passthrough, no-op).
fmt/clippy/test --allgreen locally (new tests + 2240 existing unit tests pass). Verified end-to-end on macOS (Apple Silicon):rtk grep --include='*.rs'and--exclude='*.txt'now filter correctly through the rg path, and plain searches are unaffected.Credit
Builds on the approach proposed in #2131 by @goodmood-creator, reworked for the current
grep_capturestructure — that PR predates the grep refactors (#2333, #2550) and no longer applies cleanly.🤖 Generated with Claude Code