如何让ack忽略*.orig文件?

38

我将以下内容放入了我的.ackrc文件中:

--type-set=DUMB=*.orig
--noDUMB

...但在我的ack结果中仍然看到了像main.py.orig这样的文件。我尝试使用代码--type-set=DUMB=*.*.orig,但也没有奏效。

更多信息

在我的命令行中运行(OSX Snow Leopard with :

timmfin at lorien in ~/dev/performable/rafa on landing-pages-csv-and-more!
± ack modules --python | grep '.orig'
src/rafa/main.py.orig:25:import rafa.ui.modules.helpers
src/rafa/main.py.orig:26:from rafa.ui.modules.performable_form import PerformableForm
src/rafa/main.py.orig:27:from rafa.ui.modules.page_form import PageEditForm
src/rafa/main.py.orig:28:from rafa.ui.modules.settings_form import SettingsForm
....

timmfin at lorien in ~/dev/performable/rafa on landing-pages-csv-and-more!
± cat ~/.ackrc 
--color
--sort-files
--smart-case

--type-set=sass=.sass
--type-set=coffee=.coffee

--ignore-dir=rafa/static
--ignore-dir=compiled
--ignore-dir=compressed

--ignore-dir=venv
--ignore-dir=build

timmfin at lorien in ~/dev/performable/rafa on landing-pages-csv-and-more!
± ack --version
ack 1.94
Running under Perl 5.10.0 at /usr/bin/perl
4个回答

89

现在ack 2.0已经发布:

--ignore-file=ext:orig

无论是在命令行还是在.ackrc文件中,都可以忽略特定的文件。

例如要忽略ctags生成的文件:

--ignore-file=is:tags

文档中可以找到不同用途的筛选器。


2
希望这个更新为“被接受的答案”,这是目前最好的方法! - jgillman
1
您可以使用正则表达式和 match 来匹配文件名,使用 ext 来匹配扩展名。排除 js 文件 --ignore-file=ext:js。排除名称为 foo 和 bar 的文件 --ignore-file='match:/foo|bar/'。如果正则表达式中包含 |,请用引号转义参数,以防 shell 将其作为管道执行。 - xtreak

20

针对 ack 版本 1.x

我发现,如果我去掉 Ackmate wiki 中的星号,这个方法就能够奏效。

--type-set=DUMB=.orig
--noDUMB

您可以通过运行以下命令(包括在 ~/.ackrc 文件中指定的文件类型)来查看 ackmate 支持哪些类型的文件:

~/Library/Application\ Support/TextMate/PlugIns/AckMate.tmplugin/Contents/Resources/ackmate_ack --help type

1

对于ack版本1.x,请使用以下方法。在我的情况下,我想忽略 .css 文件。我必须设置类型为 SOMETHING。然后将其设置为 --noSOMETHING 以从搜索中移除它。

 ack --type-set=SOMETHING=.css --noSOMETHING "My Bitcoin."

enter image description here


0

ack在一开始就不会识别.orig文件。我猜测你是从ackrcACK_OPTIONS中调用了ack -a


我主要使用AckMate插件在Textmate中使用Ack(除了我的.ackrc之外,我不确定它使用哪些选项),但我也在命令行上看到了来自ack的问题。为了更详细地说明问题,我更新了我的问题。 - timmfin
尝试使用--noenv并查看是否忽略了您的.orig文件。此外,您的ack是否可以别名为ack -a? 另外,使用ack -f获取ack感兴趣的所有文件的列表。 - Andy Lester
我收到了错误信息:在 ~/.ackrc 中有无效选项。 - nyxee
你什么时候收到了那个错误信息?你在 ~/.ackrc 中做了什么? - Andy Lester

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接