lizmat / App-Rak

21st century grep / find / ack / ag / rg on steroids
Artistic License 2.0
152 stars 7 forks source link

Option to include the first line of any searched file in the output #45

Closed MasterDuke17 closed 3 days ago

MasterDuke17 commented 1 year ago

I'm frequently searching CSV files with 20-30 columns, and when there's a hit it can be hard to know what the columns are. An option to print the first line of a file (either always, or only if that file had a match to the pattern) in addition to any hits would be nice.

lizmat commented 3 months ago

Are you using --cvs-per-line for this?

In other words: I guess you'd only want the first line if it is a CSV file, right?

Or are you searching pure on text?

MasterDuke17 commented 3 months ago

I didn't know about/wasn't using --csv-per-line. I guess I generally know it's they're CSV files, but for some reason I'm thinking of the print-first-line as a general option.

lizmat commented 3 months ago

Then I guess you'd only want that printed if there is actually a match anywhere in the file. Not just for all files that are being searched, right?

lizmat commented 3 months ago

How about a --accept-first[=N] option. This would accept the first N lines as matches (with N being 1 if specified as a flag).

This would then always show the first line of any file inspected.

lizmat commented 4 days ago

@MasterDuke17

So I'm thinking of adding:

--always-first[=N] This will basically not call the matcher for the first N lines (with N defaulting to 1), but will always produce them as if they matched.

--also-first[=N] This is basically a special type of context: if there is a match, it will produce the first N (with N defaulting to 1) as context.

Would that make sense?

MasterDuke17 commented 4 days ago

Yep, that's pretty much exactly what I was thinking.

lizmat commented 3 days ago

Implemented with 0.3.9 so closing