4

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

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

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

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

--[no]buildr     .buildfile  .rake

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

4

1 回答 1

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 的开发进展。我很想得到你的帮助。

于 2012-03-01T06:08:56.893 回答