15

I basically just want to do ack foo *.citrus and have ack drill down and find the string 'foo' in all Citrus files in the current directory and below. The trouble is that this won't work if there aren't any Citrus files in the current directory.

I tried messing with -G without success. Do I really need to add a file type in .ackrc just to limit the search to files with a given extension?

Mark Wilden
  • 2,080
  • 1
  • 15
  • 15

3 Answers3

16

As suggested by Andy Lester, you can also create a typeset without taking the trouble to add it in your .ackrc file:

ack --type-set=cit=.citrus --cit "foo"
Sebastián Palma
  • 32,692
  • 6
  • 40
  • 59
Sébastien
  • 13,831
  • 10
  • 55
  • 70
12

By default, ack searches only in files with known types ( like *.java, *.cpp etc. ). It doesn't know about files *.citrus, so to search in such files you must use -a cmd line switch:

$ack -a -G '\.citrus$' foo
1.d/1.citrus
1:foo_bar
Andrey Starodubtsev
  • 5,139
  • 3
  • 32
  • 46
  • 1
    or you can use this tip: http://stackoverflow.com/questions/3870611/how-to-let-ack-support-more-filetypes – Andrey Starodubtsev Feb 25 '12 at 07:18
  • 1
    The -a is overkill. --type-set is the way to go. – Andy Lester Feb 26 '12 at 05:14
  • 1
    This is logical, but less than optimally useful. Such a simple task -"search files with this extension" - requires you to tell it not only the extension using a regular extension (-G), but that you do want it to actually search those files (-a or --type-set - even this choice is controversial). You gotta love Unix. – Mark Wilden Apr 11 '12 at 15:05
4

You don't have to set it in .ackrc if you don't want. You can also set ACK_OPTIONS in your environment, or specify --type-set arguments on the command line. ack doesn't care.

Andy Lester
  • 91,102
  • 13
  • 100
  • 152