File search: can print lines and line numbers - #9740
Merged
Conversation
BackSlasher
marked this pull request as ready for review
July 2, 2026 14:43
6 tasks
BackSlasher
force-pushed
the
file-search-print-lines
branch
from
July 2, 2026 15:48
9077ac3 to
7060002
Compare
martinvonz
reviewed
Jul 4, 2026
BackSlasher
force-pushed
the
file-search-print-lines
branch
3 times, most recently
from
July 6, 2026 14:13
82571c9 to
10f9a34
Compare
BackSlasher
force-pushed
the
file-search-print-lines
branch
from
July 14, 2026 15:53
10f9a34 to
9e5f02a
Compare
Contributor
Author
|
Rebased because drifted from main. Anything I can do to help this land? |
yuja
reviewed
Jul 16, 2026
Default output changes from `<path>` to `<path>:<matched line>`, one per match, matching `git grep`'s default. `-l`/`--files-with-matches` restores path-only output.
Prefixes each match with its 1-based line number, matching `git grep -n`. Mutually exclusive with `-l` (clap-enforced).
BackSlasher
force-pushed
the
file-search-print-lines
branch
from
July 16, 2026 13:39
9e5f02a to
9bf647d
Compare
yuja
approved these changes
Jul 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #9399
Two commits:
--name-only-nAs specced in #9399 by @martinvonz
Testing
path:linedefault output.--name-onlyrestores path-only output.-n/--line-numberprefixes matches with 1-based line numbers.--name-onlycombined with-nerrors out (clap-enforced).--name-onlycollapses to one line per file.--name-onlydeduplicates across matching add-sides.-nnumbers lines within each side independently.Known issue: Binary files
Because we now emit matched-line contents (not just paths), a search that happens to match bytes in a binary file will dump raw bytes, potentially including terminal control codes, to stdout.
Addressed in the follow-up PR #9742 (mirrors
git grep:Binary file <path> matchesby default,-a/--textand-I/--no-binaryoverrides).Not in scope
--template): the bigger stretch goal on FR: Allow seeing the matched lines forfile searchcommand #9399.TODOin the code.read_all, which will inflate process memory on big files. Can be moved to streaming but wanted to keep this PR small.TODOin the code.Checklist
If applicable:
CHANGELOG.mdREADME.md,docs/,demos/)cli/src/config-schema.json)how it works, how it's organized), including any code drafted by an LLM.
an eye towards deleting anything that is irrelevant, clarifying anything
that is confusing, and adding details that are relevant. This includes,
for example, commit descriptions, PR descriptions, and code comments.