2012-02-29 69 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