3

I would like to define a file type that would enable me to ignore all files without extension in ack. In my .ackrc file I have added:

--type-set=csv:ext:csv,tsv

To handle CSV files that I often exclude from searches via --nocsv switch when running ack query. However, some of the files I would like to exclude have no CSV extension. Ideally, I would like to be able to arrive at a syntax:

ack --nocsv --nosansext searchStuff ~/SomeProjects

I would like for this command to:

  • Exclude CSV files
  • Exclude files without extension
  • Include all other syntax files that I have in SomeProjects folder.

Is it possible to define a file type in ack to capture files without extension?

Konrad
  • 313
  • 1
    Try --type-add 'csv:match:/^[^.]+$/'. – Satō Katsura May 11 '17 at 11:32
  • @SatoKatsura Thanks very much, it's a good suggestion. The command: ack --nocsv --type-add 'csv:match:/^[^.]+$/' searchPhrase ~/ worked as desired, would you care to explain how the 'csv:match:/^[^.]+$/' works? – Konrad May 11 '17 at 11:45
  • There are 3 other types of filters beyond ext: is, match, and firstlinematch. is and match match against filename, firstlinematch matches against the first line of the file. So --type-add 'csv:match:/^[^.]+$/' adds files without extension to the csv type. All straight from the manual, section "Defining your own types". – Satō Katsura May 11 '17 at 15:22

1 Answers1

3

You could use find to create the list of the files you want to inspect:

find ~/SomeProjects -type f -regex '\./[^.]*$' | ack searchStuff -x

I have a version of ack that has no support for the csv filetype. You can see all supported types with ack --help-types and you can find all types in your directory with: ack --show-types -f ~/SomeProjects. I found many text files without type but with extension, for example: .cfg, .md or .txt.

ctx
  • 2,495
  • Thanks very much, concerning the csv file, I've defined this type in .ackrc; my ambition was to add another type for files with no extension. In practical terms those are often CSV files that were saved like that in past, so I would like to exclude them as they get into results unnecessarily. – Konrad May 11 '17 at 11:27