Skip to content

fix(grep): translate GNU grep --include/--exclude to rg --glob - #2131

Closed
goodmood-creator wants to merge 1 commit into
rtk-ai:developfrom
goodmood-creator:fix/grep-include-exclude
Closed

goodmood-creator wants to merge 1 commit into
rtk-ai:developfrom
goodmood-creator:fix/grep-include-exclude

Conversation

@goodmood-creator

Copy link
Copy Markdown

Problem

rtk grep forwards extra_args directly to ripgrep, but ripgrep has no
--include/--exclude (it uses --glob/-g). Running the common GNU grep
form breaks the search instead of filtering:

rtk grep "pattern" . --include="*.kt"   # rg rejects --include → search breaks

This also bites the Claude Code / agent workflow, where a shell grep --include
gets rewritten to rtk grep and the --include is effectively swallowed.

Fix

Translate GNU grep include/exclude flags to rg globs inside the extra_args
loop in grep_cmd.rs:

  • --include=GLOB / --include GLOB → --glob GLOB
  • --exclude=GLOB / --exclude GLOB → --glob !GLOB
  • every other flag is passed through unchanged
  • --include-dir/--exclude-dir are out of scope (rg has no directory-only glob)

Tests

Added unit tests for the =/space forms, the exclude ! prefix, and
pass-through of unrelated flags (incl. --include-dir not being misparsed).

cargo fmt --all --check && cargo clippy --all-targets && cargo test pass locally.

rtk grep passes extra_args straight to ripgrep, but ripgrep has no
--include/--exclude (it uses --glob). A user running the common GNU grep
form 'rtk grep PATTERN . --include=*.kt' therefore hits an unrecognized
flag and the search breaks instead of filtering by glob.

Translate --include=GLOB / --include GLOB to '--glob GLOB' and
--exclude=GLOB / --exclude GLOB to '--glob !GLOB' in the extra_args loop,
passing every other flag through unchanged. --include-dir/--exclude-dir
remain out of scope (rg has no directory-only glob).

Add unit tests covering the =/space forms, the exclude '!' prefix, and
pass-through of unrelated flags.

Signed-off-by: sai <[email protected]>
@CLAassistant

CLAassistant commented May 28, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@KuSh

KuSh commented Jun 27, 2026

Copy link
Copy Markdown
Collaborator

Hi @goodmood-creator, thanks for your work.

This has been superseded by #2607; please feel free to comment or review that PR to help it move forward.

@KuSh KuSh closed this Jun 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants