beyondgrep / ack3

ack is a grep-like search tool optimized for source code.
https://beyondgrep.com/
Other
713 stars 66 forks source link

Add a -X that acts like -x but obeys the --type filters #368

Open petdance opened 1 year ago

petdance commented 1 year ago

ack -x ignores type filters. This is surprising to some users, and there have been repeated calls for -x to respect the --type filters.

It's too late to change the behavior of -x, but perhaps we add another flag, maybe -X, that obeys the type filters.

Let's discuss.

jakebman commented 1 year ago

I might ask to consider having the flag be independent of -x - this behavior is also confusing on the command line.

(Also, this way it can be embeded in ackrc)

petdance commented 1 year ago

What does "independent of -x" mean? Which behavior is also confusing on the command line? Which way it can be embedded in ackrc?

jakebman commented 1 year ago

Independent of -x: -x is just a specialization of --files-from, right? It feels weird to have type filtering apply only to stdin, and not any other file you could read your starting set from.
I'd really like it if it could be applied to any other --files-from, and additionally to the starting set specified on the command line (otherwise the "consistent with *.pl --noperl" consistency is broken)

Behavior on the command line: It's confusing that --noperl doesn't exclude .pl files from a starting set. This behavior is equally confusing from the command line and -x. This behavior is surprising/confusing/non-DWIM in both contexts, and I'm asking for a fix to it to be considered to be able to resolved in both contexts.

Specify in ackrc: Even though we can't break existing scripts, I personally want this feature to be the default ack behavior, and that's what ackrc is for: to have personal default settings. Having this as an independent flag I can tuck into my ackrc basically gives me that power. I wouldn't be able to do that with -X.

None of this is an argument against -X as a new flag. I'm just asking to consider making the behavior broader (to cover --files-from, and the CLI starting set), and allow -X to mean "-x, but respecting type filters" in the same way that --some-new-flag-name would cause type filters to be respected in non-stdin --files-from, or on the CLI.

n1vux commented 1 year ago

Ability to use ack type filters in xargs mode is some setting i'd use. Our filters are more expressive than e.g. finds.