beyondgrep / ack2

**ack 2 is no longer being maintained. ack 3 is the latest version.**
https://github.com/beyondgrep/ack3/
Other
1.48k stars 140 forks source link

Handle Qt pro and pri files #677

Closed MartinDelille closed 5 years ago

MartinDelille commented 5 years ago

I'll be happy to be able to look into my Qt projects files (pro / pri / qrc).

Unfortunately the following command doesn't work:

$ ack mypattern --type=pri
Unknown type 'pri' at /usr/local/Cellar/perl/5.28.1/lib/perl5/5.28.1/Getopt/Long.pm line 606.
ack: Invalid option on command line

Would it be possible to add them to the supported type?

I also tried the following command without success:

$ ack mypattern --files-from=**/*.pri
fish: No matches for wildcard '--files-from=**/*.pri'. See `help expand`.
ack widgets --files-from=**/*.pri

I'm using ack 2.24 installed via Homebrew on macOS and I'm using http://fishshell.com/

petdance commented 5 years ago

You want the --type-add command. It sounds like you want something like this:

--type-add=qtproject:ext:pro,pri,qrc

Then you could do ack --qtproject widgets. I like to keep names longer than I need to, so I can abbreviate as --qtp most of the time but spell out --qtproject if I need to for clarity of someone else reading it. Of course, you can call the filetype whatever you want.

You can put that on the command line, but more likely you're going to want to put it in an .ackrc file. You can either put it in ~/.ackrc in your home directory, or in a .ackrc that will localize that specification only to that directory tree.

Please let me know how it goes. I'm currently working on the docs for the --type-add and --type-set options and also a chapter on them in my upcoming book about ack.


Also, the --files-from specifies a file that has a list of files to search. If you had a list of all the files to search in a file myfiles.txt you could say ack --files-from=myfiles.txt.

MartinDelille commented 5 years ago

That sounds a nice feature!

What I don't understand is which effect has the --type-add command? Does it modify the default configuration? Where is it stored?

I would indeed prefer to add it to my ~/.ackrc file but what is the syntax then?

I'll be happy to help you to review the documentation by the way!

petdance commented 5 years ago

You store the --type-add command in your ~/.ackrc file. That file is checked every time you run ack. That basically makes it a default every time you run ack.

You can also put it in a public /etc/ackrc file and then everyone on that machine who runs ack will get that --type-add.

You can also put it in a project-level .ackrc that will only apply when you're in that directory tree.

MartinDelille commented 5 years ago

Ok great thank you! I realized how .ackrc file work: it appends each line as a parameter to the ack command.