ack - 将实际文件名绑定到文件类型

时间:2012-02-29 23:38:55

标签: ack

对我来说,ack是必不可少的工具包(它别名为a,我每天使用它一百万次)。大多数情况下它拥有我需要的一切,所以我认为这种行为已被覆盖,而我却找不到它。

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

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

问题是'buildfile'是整个文件名,而不是扩展名,我希望ack完全匹配此名称。但是,如果我查看绑定到'buildr'的类型,则表明.buildfile是扩展名而不是整个文件名。

--[no]buildr     .buildfile  .rake

限制为特定文件名的能力对我来说非常有用,因为有许多xml用例(例如ant build.xml或mvn pom.xml),它们非常适合。我确实看到二进制文件,Makefile和Rakefiles有特殊的类型配置,也许这​​就是要走的路。在使用自定义函数之前,如果可能的话,我真的希望能够在ack内完成。有人知道这是否可行?

1 个答案:

答案 0 :(得分: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)/

您可以在https://github.com/petdance/ack2查看ack 2.0正在进行的开发。我很乐意帮助你。