Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
stephenmckinney opened this issue Dec 10, 2012 · 23 comments
Closed

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

stephenmckinney opened this issue Dec 10, 2012 · 23 comments

Comments

@stephenmckinney
Copy link

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

ag "layout" --rb

@stevenharman
Copy link

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
Copy link
Author

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
Copy link
Owner

ggreer commented Dec 13, 2012

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
Copy link

@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
Copy link

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
Copy link

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
Copy link

acook commented Mar 10, 2013

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
Copy link

kergoth commented Mar 21, 2013

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
Copy link

atropo commented Mar 25, 2013

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

@beaumartinez
Copy link

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

@j1wilmot j1wilmot mentioned this issue Nov 29, 2013
@brondsem
Copy link

Looks like #283 has implemented this.

@stevenharman
Copy link

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

@beaumartinez
Copy link

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
Copy link

I'm on it

@kevinburke
Copy link

Docs here: #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//issues/128#issuecomment-32985043
.

@macarthy
Copy link

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

@matthewrankin
Copy link

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
Copy link
Contributor

mcphail commented Jan 29, 2014

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

@mcphail
Copy link
Contributor

mcphail commented Jan 29, 2014

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

@matthewrankin
Copy link

@mcphail PR #332 looks great. Many thanks!

@ches
Copy link

ches commented Mar 23, 2014

This issue seems closable in light of #283.

@ggreer
Copy link
Owner

ggreer commented Mar 24, 2014

Oh yeah, totally implemented.

@ggreer ggreer closed this as completed Mar 24, 2014
@zx1986
Copy link

zx1986 commented Dec 24, 2015

ag --list-file-types

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 a pull request may close this issue.