17

I've recently learned how to let ack support more filetypes (adding the following to .ackrc):

--type-add
latte=.latte

Unfortunately, that produces an info line on every ack search I use, even ones with 0 results.

$ ack --latte dump
ack: --type-add: Type "latte" does not exist, creating with ".latte" ...

Is there a way to make this a more permanent addition? (i.e. get rid of this info line) This looks to me like it's adding this new type on every ack call. Is it a problem with my installation of ack?

I'm on Mac OS X 10.5.8 with ack 1.92 (Running under Perl 5.10.1)

Martin Tóth
  • 842
  • 1
  • 10
  • 18
  • Regarding 10.6->10.5.8: I really have no idea why I wrote 10.6, I've always had 10.5.8... And when I realized it, I changed it... – Martin Tóth Feb 28 '11 at 14:51
  • 1
    Odd revision history: @Mehper started editing within the 5 minute grace period, and then (after Mehper *started*, but before he *saved*) Martin changed "10.6" to "10.5.8". Next, the change was undone when Mehper saved the edits to the (then) older text — which for the history was still the same revision due to the grace period, hence listing Mehper as changing the version. If you're bothered about this, then consider voting for [After saving, alert when post was meanwhile saved by someone else](http://meta.stackexchange.com/questions/20658/after-saving-alert-when-post-was-meanwhile-saved). – Arjan Feb 28 '11 at 15:12
  • +1 I was using --type-set following the documentation but had no idea the types should be in a new line – Marcelo Diniz Mar 02 '13 at 18:14

3 Answers3

18

Seems to me that the documentation claims you need --type-set instead:

--type-set
latte=.latte

Whereas --type-add is for, emphasis mine:

Files with the given EXTENSION(s) are recognized as being of (the existing) type TYPE.

Arjan
  • 30,974
  • 14
  • 75
  • 112
0

Create or edit .ackrc in your $HOME directory and add --type-add=cpp:ext:inl.

This adds the file extension inl as a match for the existing type "cpp".

~/.ackrc:

# C++
--type-add=cpp:ext:inl

Usage:

ack --cpp Foo

In addition to match type ext for file extension, there is also is for exact filename match, match for regex match, and firstlinematch (also a regex, but matches against the first line of each file).

T Percival
  • 229
  • 1
  • 4
0

Hmmm... ack is basically a Perl script... which is quite easy to edit:

%mappings = (
    actionscript => [qw( as mxml )],
    ada         => [qw( ada adb ads )],
...
    latte       => [qw( latte )],
...
    yaml        => [qw( yaml yml )],
    xml         => [qw( xml dtd xslt ent )],
);

But still, is there another solution to this?

Martin Tóth
  • 842
  • 1
  • 10
  • 18
  • 4
    If you edit ack-grep itself you lose the benefit of subsequent upgrades because upgrading would overwrite your changes. The configuration can be done in .ackrc which is a superior solution. – Niels Bom Oct 19 '12 at 15:09