ggreer / the_silver_searcher

A code-searching tool similar to ack, but faster.
http://geoff.greer.fm/ag/
Apache License 2.0
26.12k stars 1.43k forks source link

Question: Plans for limiting search to file types? #128

Closed stephenmckinney closed 10 years ago

stephenmckinney commented 11 years ago

Similar to ack, e.g. limit to Ruby files:

ag "layout" --rb

stevenharman commented 11 years ago

This would be most welcome! This morning I started an experiment - replacing ack with ag (both in my shell and in Vim via ack.vim) and I already miss being able to only search certain file types. Especially when I can categorize kinds of files:

# ~/.ackrc
--type-add=ruby=.haml,.rake,.builder
--type-add=html=.erb,.haml,.slim
--type-add=css=.scss,.sass,.less
--type-set=sass=.scss,.sass

Allowing for ack foobar --css to only search CSS-like files (.css, .scss, .sass, and .less in this case).

stephenmckinney commented 11 years ago

While using Ack, I thought I was using the file type switch simply to speed things up, now that I'm using ag I find I need it to narrow results. Even if those results are returned much faster.

ggreer commented 11 years ago

I never used this feature in Ack, which is why I didn't write it in Ag. I'd like for it to exist, but I'm not sure of the best way to go about it yet. Adding search by file-type would be a pretty big change. While Ag has plenty of code for blacklisting/ignoring, it doesn't have much whitelisting. I'll give this problem some more thought.

One more thing: I'm going on vacation for the next couple of weeks. I doubt I'll be online much.

stevenharman commented 11 years ago

@ggreer

I never used this feature in Ack, which is why I didn't write it in Ag.

That's certainly fair. I wish I could be of more help with implementing a feature like this, but it's been a long time since I last flexed by C muscles.

Have a great holiday!

dave1010 commented 11 years ago

For now, I'm using bash globbing with ag, which I presume is going to be much slower. E.g:

shopt -s globstar
ag main-menu **/*css
silouanwright commented 11 years ago

Yeah this is sort of a deal breaker for me. When you said "replacement" for grep & ack but no mention of file types... (I had to really search for this issue), I wouldn't say it's a replacement, definitely a fast alternative though.

acook commented 11 years ago

Yeah, I use this feature. My .ackrc (which was partially borrowed from alindeman) contains additional filetypes that I want to search either generally or specifically - otherwise ack will ignore them if it doesn't know what they are.

kergoth commented 11 years ago

For basic extension-based type stuff, I've been using aliases with -G, personally. E.g.:

alias bbag="ag -G '\.(bb|bbappend|inc|conf)$'"

Not ideal, but it gets the job done for now, until ag gets better file type support.

atropo commented 11 years ago

I agree I've got many customs file types in my .ackrc. This is a feature I'm missing in Ag.

beaumartinez commented 10 years ago

+1, this feature is essential when dealing with larger codebases.

brondsem commented 10 years ago

Looks like #283 has implemented this.

stevenharman commented 10 years ago

Perhaps someone who know how it work could document this feature in the README, or perhaps in the Wiki?

beaumartinez commented 10 years ago

Good shout @brondsem!

@stevenharman I've just upgraded my version of ag, and it now emulates the way ack works. So you can do—

ag --python tweets

To search for tweets in Python files only.

kevinburke commented 10 years ago

I'm on it

kevinburke commented 10 years ago

Docs here: https://github.com/ggreer/the_silver_searcher/pull/327

Kevin Burke | Twilio phone: 925.271.7005 | kev.inburke.com

On Tue, Jan 21, 2014 at 5:26 PM, Beau notifications@github.com wrote:

Good shout @brondsem https://github.com/brondsem!

@stevenharman https://github.com/stevenharman I've just upgraded my version of ag, and it now emulates the way ack works. So you can do—

ag --python tweets

To search for tweets in Python files only.

— Reply to this email directly or view it on GitHubhttps://github.com/ggreer/the_silver_searcher/issues/128#issuecomment-32985043 .

macarthy commented 10 years ago

This is great. Only thing is I can't find a method to add your own mapping ? E.g search only logs

matthewrankin commented 10 years ago

Is there a way to print the list of filetypes? I know that we can view the source to see the list in the lang.c file; however, it would be nice to have the equivalent of ack --help=types.

mcphail commented 10 years ago

I could have a look at listing the file types this evening if I get a chance. Should be quite a simple patch.

mcphail commented 10 years ago

Have a look at PR #332 and tell me what you think.

matthewrankin commented 10 years ago

@mcphail PR #332 looks great. Many thanks!

ches commented 10 years ago

This issue seems closable in light of #283.

ggreer commented 10 years ago

Oh yeah, totally implemented.

zx1986 commented 8 years ago

ag --list-file-types