1

I am using counsel-git to find and open files.

Is there any way to ignore folders and files that are ending with specific pattern.

For example: ignore folders named: .idea ; and files ended with *.save and *.xml or specific as -i or .gitignore. All the folders starting with . always show up on top; I just want to ignore some of them which I do not use.


config file:

(ivy-mode 1)
(setq ivy-use-virtual-buffers t)
(setq enable-recursive-minibuffers t)

(global-set-key (kbd "C-c g") 'counsel-git)
1

counsel-git is calling counsel-git-cands to build the list of files.
counsel-git-cands is running the shell command, which is stored in variable counsel-git-cmd, which has the value "git ls-files -z --full-name --".

So you have two different options:

  1. modify the result of function counsel-git-cands to remove files from the list, you do not want. i.e. add an advice, which filters the results: (advice-add 'counsel-git-cands :filter-return #'my-filter-counsel-git-cands). Read more about advicing at the elisp manual.
  2. change the shell command line git ls-files.... to sort out files you do not want. i.e. by using the command line option --exclude. You need to experiment with git ls-files a bit with that here. Read man page of git-ls-files (1).
5
  • For example I have changed it into git ls-files -z --full-name -- *[^.xml] but still it returns "xml" files – alper Nov 22 '20 at 17:06
  • Please read the manpage of git-ls-files! or use method 1. – jue Nov 22 '20 at 22:32
  • *[^.xml] lets to exclude files that are ending with xml but when I make that change on the consel.el file it does not make any change in the emacs itself – alper Nov 22 '20 at 22:55
  • I'm not familiar with git's command line, but this -- looks supicious. Normaly this is some sort of parameter separator for command line options. – jue Nov 22 '20 at 23:04
  • I have followed this guide : stackoverflow.com/a/53083343/2402577 ; for example ':!:test/*' ':!:*/test/*' stands out to prevent folders but even it works in the terminal, within emacs it does not – alper Nov 23 '20 at 15:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.