forsooth!

By necessity, by proclivity, and by delight, we all quote.

Ignore directories in projectile


Problem

Putting a .projectile into a directory is enough to make it a project root in spacemacs, making it easy to search the entire directory and list its files.

Listing files in a project is easily done with SPC p f. There is a native mode and an alien mode, the former uses Emacs code to do the file listing, the latter uses external programs. The default is alien and usually that’s fine and much faster. It will use git inside a git repository, find when there’s just a .projectile.

See the projectile documentation for details.

However, if you have projects, like me, that have several subdirectories that contain git repositories, like so:

.
└── src
    ├── repo1
    │   └── .git
    ├── repo2
    │   └── .git
    └── repo3
        └── .git

then projectile cannot use git to list files, as it would, if the root were a git repository. It uses find and with that it also lists all .git directories. Adding “.git” to .projectile or projectile-globally-ignored-directories doesn’t help in this case. At least I couldn’t make it work.

Solution

So I ended up just adjusting the find command projectile uses.

(setq projectile-generic-command
  "find . -type f ! -ipath '.git*' ! -ipath '*/.git*' ! -ipath '*/build/*' -print0")

That also hides files in build subdirectories. And the file list becomes much more manageable.

#+TITLE: Ignore directories in projectile
#+DATE: <2017-10-10 Tue>
#+AUTHOR: @or
#+CATEGORY: tech
#+SUMMARY: Ignore directories like .git in projectile helm
#+SLUG: projectile-ignore-directories
#+TAGS: spacemacs, helm

** Problem
Putting a =.projectile= into a directory is enough to make it a project root in
spacemacs, making it easy to search the entire directory and list its files.

Listing files in a project is easily done with =SPC p f=. There is a =native=
mode and an =alien= mode, the former uses Emacs code to do the file listing, the
latter uses external programs. The default is =alien= and usually that's fine
and much faster. It will use =git= inside a git repository, =find= when there's
just a =.projectile=.

See the [[http://batsov.com/projectile/][projectile documentation]] for details.

However, if you have projects, like me, that have several subdirectories that
contain git repositories, like so:
#+begin_example
.
└── src
    ├── repo1
    │   └── .git
    ├── repo2
    │   └── .git
    └── repo3
        └── .git
#+end_example

then projectile cannot use =git= to list files, as it would, if the root were a
git repository. It uses =find= and with that it also lists all =.git= directories.
Adding ".git" to =.projectile= or =projectile-globally-ignored-directories=
doesn't help in this case. At least I couldn't make it work.

** Solution
So I ended up just adjusting the =find= command projectile uses.

#+begin_src emacs-lisp
(setq projectile-generic-command
  "find . -type f ! -ipath '.git*' ! -ipath '*/.git*' ! -ipath '*/build/*' -print0")
#+end_src

That also hides files in =build= subdirectories. And the file list becomes much
more manageable.