2012-02-29 24 views
4

对我来说,ack是必不可少的工具包(它的别名和我每天使用它一百万次)。大多数情况下,它包含了我需要的一切,所以我认为这种行为已被覆盖,我无法找到它。ack - 将实际的文件名绑定到文件类型

我希望能够限制它使用类型的特定种类的文件。问题是这些文件有一个完整的文件名,而不是一个扩展名。例如,我想限制它为buildr构建文件,所以我可以用--buildr(类似的将适用于mvn poms)搜索它们。我有以下我.ackrc

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

的问题是,“构建文件”是完整的文件名,而不是扩展模块定义,我想ACK给这名完全一致。但是,如果我看看绑定到'buildr'的类型,它会显示.buildfile是扩展名而不是整个文件名。

--[no]buildr  .buildfile .rake 

限制到特定的文件名,因为有无数的XML usecases(例如蚂蚁build.xml或MVN pom.xml)将是对我非常有用,这将是完美的能力。我确实看到了二进制文件,Makefiles和Rakefiles有特殊的类型配置,也许这​​就是要走的路。我希望能够在采用自定义功能之前尽可能在ack内完成。任何人都知道这是可能的吗?

回答

4

不,你不能这样做。 ack 1.x仅使用扩展名来检测文件类型。 ACK 2.0将有更多的灵活的功能,在这里你就可以做的东西一样:


# 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)/ 

你可以看到什么样的发展上ACK 2.0在https://github.com/petdance/ack2在做什么。我很乐意为您提供帮助。

+0

对于cryopost的道歉,但如果我把它放在我的.ackrc中:'--type-add = mvn,is,pom.xml'我得到'%> ack --mvn org 无效的过滤器规范'mvn,是,pom.xml'位于/System/Library/Perl/5.18/Getopt/Long.pm第589行。 未知选项:mvn' – 2014-11-22 00:02:19

+1

您想要'--type-add = mvn:is:pom.xml'。有关示例,请参阅'ack --dump'。 – 2014-11-24 14:41:59

相关问题