4

私にとって ack は不可欠なキットです (その別名は a で、1 日に何百万回も使用しています)。ほとんどの場合、必要なものはすべて揃っているので、この動作がカバーされていて、見つけられないだけだと考えています。

タイプを使用して特定の種類のファイルに制限できるようにしたいと思います。問題は、これらのファイルに拡張子ではなく完全なファイル名があることです。たとえば、buildr のビルド ファイルに制限したいので、--buildr で検索できます (同様のことが mvn poms に適用されます)。私は .ackrc で以下を定義しています

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

問題は、'buildfile' が拡張子ではなくファイル名全体であることです。ack をこの名前に完全に一致させたいのです。ただし、「buildr」にバインドされたタイプを見ると、.buildfile がファイル名全体ではなく拡張子であることがわかります。

--[no]buildr     .buildfile  .rake

build.xml特定のファイル名に制限する機能は、最適な xml ユースケース ( antや mvn など)が多数あるため、私にとって非常に便利ですpom.xml。バイナリ、Makefile、および Rakefile には特別なタイプの構成があり、おそらくそれが進むべき道であることがわかります。カスタム関数に頼る前に、可能であれば 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)/

ack 2.0 の開発状況はhttps://github.com/petdance/ack2で確認できます。助けていただければ幸いです。

于 2012-03-01T06:08:56.893 に答える