Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Silver Searcher - How to ignore a file

Tags:

powershell

cmd

ag

According to the docs, it should be

--ignore PATTERN

I have a file containing tags, named "tags". I have tried the following, each of them still searches through the tag file..

ag -Qt --ignore ".*tags" "asdf"

ag -Qt --ignore .*tags "asdf"

ag -Qt --ignore "tags" "asdf"

ag -Qt --ignore tags "asdf"

ag -Qt --ignore *tags

and none of them works.

If I use what's suggested here, then ag doesn't accept it at all

I tried to work around it by renaming it to temp.tags and using *.tags pattern to try and ignore it, but it still doesn't work.

Any ideas?

like image 654
Jacob Wang Avatar asked Apr 10 '14 21:04

Jacob Wang


8 Answers

Put the list of files to exclude in .agignore.

Note: as @DenilsonSáMaia mentioned, .agignore will be deprecated in favor of .ignore geoff.greer.fm/2016/09/26/ignore

like image 115
Mukesh Soni Avatar answered Sep 27 '22 16:09

Mukesh Soni


Add just multiple --ignore, at least this works for me:

ag -Qt --ignore ".*tags" --ignore asdf

If you don't put quotes it's interpreted as directory if you put quotes as PATTERN

like image 44
NexusStar Avatar answered Sep 29 '22 16:09

NexusStar


After some research, it seems that it is a known issue documented here. Where if you do an --all-text (-t) search it'll override --ignore since it's searching for all texts. This issue is present for --unrestricted too.

like image 39
Jacob Wang Avatar answered Sep 29 '22 16:09

Jacob Wang


I've found that --ignore doesn't take a regex.

This should help:

ag --ignore="*_test.rb" "SomeAwesomeClass"
like image 30
Artur Małecki Avatar answered Sep 27 '22 16:09

Artur Małecki


As of v2.2.0 (most likely earlier versions as well; I'm just going off the version I have) all these answers don't seem to work. What did work for me was:

ag searchterm --ignore=*.log --ignore=*.txt

Note the = after the ignore option.

like image 29
youngrrrr Avatar answered Sep 27 '22 16:09

youngrrrr


You can also create .ignore files to ignore things that are in your source repository. .ignore uses the same patterns as .gitignore and .hgignore. Using .ignore can drastically improve search speeds. .

If you want a global .ignore file, consider adding this alias:

alias ag='ag --ignore ~/.ignore' 

to your ~/.bash_profile (or similar) file. there is also

to temporarily disable vcs ignores you can run with --skip-vcs-ignores

like image 36
lfender6445 Avatar answered Sep 30 '22 16:09

lfender6445


For me, the following works (in ag version 0.18.1):

ag --ignore TAGS;*.pdf;*.json "search_term"
like image 43
jco Avatar answered Sep 27 '22 16:09

jco


I just placed .agignore file into my user root folder and it works.

By default, ag will ignore files matched by patterns in .gitignore, .hgignore, or .agignore. These files can be anywhere in the directories being searched. Ag also ignores files matched by the svn:ignore property in subversion repositories. Finally, ag looks in $HOME/.agignore for ignore patterns. Binary files are ignored by default as well.

https://manpages.ubuntu.com/manpages/trusty/man1/ag.1.html

like image 26
Lajos Avatar answered Sep 30 '22 16:09

Lajos