1

Ag works fine most of the time. But sometimes, I want to do a search in, say, all XML files by using --xml, but not any .dtd files. Unfortunately, ag looks at .dtd files when asked to examine --xml.

I tried as a wild guess ag --no-dtd. Doesn't work. The --ignore options aren't for this.

I know there's a ~/.agignore file, but being absent minded and often interrupted, I don't want to bother edit that for just one or two searches and have to remember to put it back. I'm looking for a one-off easy way to avoid a certian file type.
Other examples could be wanting to look at C++ files but wanting to see only .c, .cpp, .cxx and such but not .h or .hpp, for just one time.

DarenW
  • 16,549
  • 7
  • 63
  • 102

1 Answers1

2

Two approaches.

  1. Use the file extension (-G) to limit the scope of what ag looks at. For example, if you just want to search xml files: ag -G '\.xml$' search_token

  2. Roll your own new file type.
    Download the source and modify the /src/lang.c file to include your own file types, then (re)compile. Instructions to download and build ag are kept here: https://gist.github.com/k-takata/5124445; sounds like a hassle, but it's easy and fast to do.

Note: BTW, .agignore has been renamed to just .ignore.

gregory
  • 10,969
  • 2
  • 30
  • 42