11

Everytime I try add a type in ack seem to fail i.e add a type (log) in ack

ack --type-set log:ext:log
ack: No regular expression found.

or

ack --type-add log:ext:log
ack: No regular expression found.

Anyone has a clue about this or it only

Ratatouille
  • 1,372
  • 5
  • 23
  • 50

2 Answers2

10

If you want to try out a new type in place, then use a command like this:

ack --type-set proj:ext:csproj --type proj "some search pattern"

this will show you search results for the given type.

If you want to save the type permanently, then you have to add the following line to your $HOME/.ackrc:

--type-set=proj:ext:csproj

Two things to note:

  • The first command doesn't set the configuration permanently, only let's you try it.
  • The second line in the .ackrc file should have = (equals) instead of a space.

UPDATE (figured out from the Andy Lester's answer):

Instead of --type your_type_name you can just write shortcut --your_type_name.

Sergey Kostrukov
  • 1,143
  • 15
  • 24
  • to summarize: what the questioner was missing was telling ack to *use* the type that was (correctly) specified. (either `--type log` or `--log` – Joshua Goldberg Feb 01 '19 at 19:56
  • 1
    @JoshuaGoldberg I think the other aspect that the questioner was missing (or at least the part that I missed when looking for the answer to the same question) is that the `--type-set` and `--type-add` options don't edit the `$HOME/.ackrc` file for you. Maybe it is the use of the words `set`, `add`, and `del`, but this is the (incorrect) assumption that I made when looking at the `--help`. – daveraja Aug 17 '21 at 01:00
3

Do it like this:

ack --type-set=log:ext:log --log searchterm

or if you're trying to ignore log files.

ack --type-set=log:ext:log --nolog searchterm

If this log format is something you're going to refer to a lot, then you'll want to add the line to your .ackrc file. The arguments in your .ackrc get executed every time you run ack.

For more information, see "Defining your own types" after running "ack --man".

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
Andy Lester
  • 91,102
  • 13
  • 100
  • 152
  • It doesn't help :( Unknown option: log/nolog – Sergey Kostrukov Jan 13 '15 at 13:52
  • This is probably not the best place to discuss this. I suggest posting to the ack-users mailing list, or at worst, filing an issue in ack's GitHub queue: https://github.com/petdance/ack2/ – Andy Lester Jan 13 '15 at 14:36
  • 1
    Sorry, I just thought that the SO is the right place to have technical discussions. :) I found the solution btw, see my answer above. It just wan't clear from your answer: is the `--log` an extra switch with some predefined meaning, our a short way of using type named 'log`. – Sergey Kostrukov Jan 13 '15 at 14:53