【问题标题】:How can I modify a type in ack?如何修改 ack 中的类型?
【发布时间】:2021-02-15 15:03:19
【问题描述】:

我知道如何设置新类型。我想要做的是修改现有类型。我想将 haml 文件添加到 ruby​​ 类型。我可能会使用 --set-type 并重新定义 ruby​​ 类型,但我不知道如何重新定义它并仍然包含名为“Rakefile”的文件以及第一行表明它是可执行 Ruby 脚本的文件(第一行匹配/^#!.*\bruby/)

这是 ruby​​ 类型的现有文档:

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

【问题讨论】:

    标签: ack


    【解决方案1】:

    您可以使用三个参数来处理类型定义。来自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.
    

    如果您只想将 .haml 文件添加到现有的 Ruby 规范,请使用

    --type-add=ruby:ext:haml
    

    如果您想查看现有类型是如何定义的,请使用--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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多