Unable to add a type in ack
Asked Answered
ack
M

2

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

Merylmes answered 24/7, 2014 at 9:2 Comment(0)
T
11

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.

Trump answered 13/1, 2015 at 14:13 Comment(2)
to summarize: what the questioner was missing was telling ack to use the type that was (correctly) specified. (either --type log or --logAkerboom
@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.Skeptical
C
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".

Congdon answered 25/7, 2014 at 20:26 Comment(3)
It doesn't help :( Unknown option: log/nologTrump
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: github.com/petdance/ack2Congdon
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`.Trump

© 2022 - 2024 — McMap. All rights reserved.