the_silver_searcher: problems with --ignore

what’s the format of the --ignore pattern? If I do

ag --ignore '*.min.js' time website/public/vendor/ | less

ag still looks into website/public/vendor/jquery-ui.min.js

I’ve tried also ‘.*.min.js’, ‘.min.js$’ etc with no results. I’m on OSX 10.9 with ag compiled through homebrew.

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Reactions: 2
  • Comments: 30 (7 by maintainers)

Commits related to this issue

Most upvoted comments

I seem to be having luck with **.min.js or **.min.*

In the first example of your previous comment, you put a forward slash at the start of your ignore pattern. That is, the pattern started with /. If it starts with /, that means "ignore only in the current directory. If it ends in a /, that means “only match if it’s a directory.”

Examples:

  • doc ignores any file or directory anywhere that is called “doc”.
  • /doc ignores any file or directory in the root dir called “doc”.
  • doc/ ignores any directory anywhere that’s called “doc”.
  • /doc/ ignores any directory in the root called “doc”.

These examples are typical behavior for .gitignore and .hgignore. Ag isn’t doing anything strange here.

Second point: If you run ag blah elxir, that’s the same as cd elixer && ag blah. That means “doc” is in the root. An ignore pattern like .*/doc/.* will only match doc directories in a sub-directory. Actually, I’m not even sure that will match anything sane. Ignore patterns are fnmatch() patterns, not PCREs.

@joechrysler With the latest version, I have the same problem for *~.

I put *~ in ~/.agignore, but it does not work. Thus I am now using

*~
*/*~
*/*/*~
*/*/*/*~
*/*/*/*/*~
*/*/*/*/*/*~

It is a workaround for me.