ggreer / the_silver_searcher

A code-searching tool similar to ack, but faster.

Home Page:http://geoff.greer.fm/ag/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

.agignore patterns: how to create a pattern for a specific directory?

jerkstorecaller opened this issue · comments

Hi, I would like to always omit a specific directory from ag searches, hopefully by adding it to ~/.agignore.

Consider the following structure:

$ cd ~
$ ag -l hello
proj1/common/proj1file
proj2/common/proj2file

I want ag to not search proj2/common.

Absolute path doesn't work:

$ echo "/home/user/proj2/common/" > ~/.agignore
$ ag -l hello
proj1/common/proj1file
proj2/common/proj2file

A directory name pattern works, but is dependent on from where I conduct the search. So it works if I'm in home where the proj2 part can be matched, but not if I'm in proj2.

$ echo "proj2/common" > ~/.agignore
$ ag -l hello
proj1/common/proj1file    (yay)
$ cd proj2
$ ag -l hello
common/proj2file          ($!@!)

Any advice?

UPDATE: this is embarassing, but I found this by chance by doing some more googling (trust me i googled before posting). This project has a wiki page which provides more up to date info not found in the README or manpage, unfortunately it's not mentioned anywhere so I didn't know this wiki existed.

https://github.com/ggreer/the_silver_searcher/wiki/Advanced-Usage

TLDR:

  1. .agignore has been removed in favor of .ignore. .agignore still works kinda if you put it in your home, so it has some effect. But you shouldn't use it anymore.
  2. .ignore is meant to be like .gitignore in terms of patterns and behaviors
  3. Therefore, like git with .gitignore, it will look for a .ignore file in each directory it touches. If it's called .agignore it doesn't work, it has to be .ignore.

So to solve my issue, I created proj2/.ignore which contains "common/", and now no matter where I search that directory is excluded.

I'll leave this issue open in case it might help others looking for this answer. Greer, feel free to close it when you feel it's outstayed its welcome.