ack - Binding an actual file name to a filetype
Asked Answered
ack
F

1

4

For me ack is essential kit (its aliased to a and I use it a million times a day). Mostly it has everything I need so I'm figuring that this behavior is covered and I just can't find it.

I'd love to be able to restrict it to specific kinds of files using a type. the problem is that these files have a full filename rather than an extension. For instance I'd like to restrict it to build files for buildr so i can search them with --buildr (Similar would apply for mvn poms). I have the following defined in my .ackrc

--type-set=buildr=buildfile,.rake

The problem is that 'buildfile' is the entire filename, not an extension, and I'd like ack to match completely on this name. However if I look at the types bound to 'buildr' it shows that .buildfile is an extension rather than the whole filename.

--[no]buildr     .buildfile  .rake

The ability to restrict to a particular filename would be really useful for me as there are numerous xml usecases (e.g. ant build.xml or mvn pom.xml) that it would be perfect for. I do see that binary, Makefiles and Rakefiles have special type configuration and maybe that's the way to go. I'd really like to be able to do it within ack if possible before resorting to custom functions. Anyone know if this is possible?

Fluoro answered 29/2, 2012 at 23:38 Comment(0)
C
4

No, you cannot do it. ack 1.x only uses extensions for detecting file types. ack 2.0 will have much more flexible capabilities, where you'll be able to do stuff like:


# There are four different ways to match
# is: Match the filename exactly
# ext: Match the extension of the filename exactly
# match: Match the filename against a Perl regular expression
# firstlinematch: Match the first 80 characters of the first line
# of text against a Perl regular expression. This is only for
# the --type-add option.


--type-add=make:ext:mk
--type-add=make:ext:mak
--type-add=make:is:makefile
--type-add=make:is:gnumakefile


# Rakefiles http://rake.rubyforge.org/
--type-add=rake:is:Rakefile

# CMake http://www.cmake.org/
--type-add=cmake:is:CMakeLists.txt
--type-add=cmake:ext:cmake

# Perl http://perl.org/
--type-add=perl:ext:pod
--type-add=perl:ext:pl
--type-add=perl:ext:pm
--type-add=perl:firstlinematch:/perl($|\s)/

You can see what development on ack 2.0 is doing at https://github.com/petdance/ack2. I'd love to have your help.

Callihan answered 1/3, 2012 at 6:8 Comment(3)
Apologies for the cryopost, but If I put this in my .ackrc: --type-add=mvn,is,pom.xml I get %> ack --mvn org invalid filter specification 'mvn,is,pom.xml' at /System/Library/Perl/5.18/Getopt/Long.pm line 589. Unknown option: mvnHightower
You want --type-add=mvn:is:pom.xml. See ack --dump for examples.Callihan
Note that you can add multiple specifications so that you can use :is: and :ext: for the same type, e.g., --type-set build:ext:gradle --type-add buid:is:module-info.java. (@AndyLester consider editing the answer since 2.0 is mature now.)Rawlins

© 2022 - 2024 — McMap. All rights reserved.