ack

How can I modify a type in ack?


I know how to set a new type. What I want to do is modify an existing type. I want to add haml files to the ruby type. I could probably use --set-type and redefine the ruby type but I don't know how to redefine it and still include files called 'Rakefile' and files where the first line indicates that it is an executable Ruby script (First line matches /^#!.*\bruby/)

Here is the existing documentation for the ruby type:

ruby         .rb .rhtml .rjs .rxml .erb .rake .spec; Rakefile; First line matches /^#!.*\bruby/

Solution

  • There are three arguments that let you work with type definitions. From ack --help:

    File type specification:
      --type-set=TYPE:FILTER:ARGS   Files with the given ARGS applied to the given
                                    FILTER are recognized as being of type TYPE.
                                    This replaces an existing definition for TYPE.
      --type-add=TYPE:FILTER:ARGS   Files with the given ARGS applied to the given
                                    FILTER are recognized as being type TYPE.
      --type-del=TYPE               Removes all filters associated with TYPE.
    

    If all you want to do is add .haml files to the existing Ruby spec, use

    --type-add=ruby:ext:haml
    

    If you want to see how existing types are defined, use --dump.

    $ ack --dump | ack ruby
      --type-add=ruby:ext:rb,rhtml,rjs,rxml,erb,rake,spec
      --type-add=ruby:firstlinematch:/^#!.*\bruby/
      --type-add=ruby:is:Rakefile