6

I know I can use "SPC p f" to search for a file in the current project, which means git repository for me. Now, in my current project we have multiple git repos, and I'd like to search for files in all of them. Luckily, they all reside in the same directory (e.g. ~/projects/x/).

Is there a command in Spacemacs that lets me search for files in all the git repos under ~/projects/x?

daniel kullmann
  • 13,653
  • 8
  • 51
  • 67

4 Answers4

7

I believe you can do it with SPC s f. When you activate it:

  1. Prompts you to select a directory to search
  2. Allow you to enter a search string, showing results in the HELM window

In general, SPC s shows all keybindings for general search, where f is for files.

phss
  • 1,012
  • 10
  • 22
2

I dug through the available helm commands again and found helm-projects-find-files, which does exactly what I want.

I put this in ~/.spacemacs into the function dotspacemacs/user-config:

(setq-default helm-locate-project-list (list "~/projects"))
(spacemacs/set-leader-keys "fm" 'helm-projects-find-files))

For searching in those files, you can use spacemacs/helm-project-smart-do-search-in-dir:

Put this somewhere in ~/.spacemacs:

(defun mine/search-in-projects ()
  "Search in all my projects (i.e. what is checked out in ~/projects)"
  (interactive)
  (spacemacs/helm-project-smart-do-search-in-dir "~/projects"))

And this in ~/.spacemacs into the function dotspacemacs/user-config:

(spacemacs/set-leader-keys "sm" 'mine/search-in-projects)

(I used SPC-sm as key combination because the project name starts with an "m").

daniel kullmann
  • 13,653
  • 8
  • 51
  • 67
1

Oh, I just realized I can just put a marker that projectile respects (like a .projectile file) into my ~/projects/x directory. Now I can switch to the ~/projects/x project, and still am able to also narrow it to specific sub-projects by selecting e.g. ~/projects/x/p1/.

So all I needed to do was:

    touch ~/projects/.projectile

Update: I realized that when doing this, I can't narrow down to a sub-project. So it's not really the best answer.

daniel kullmann
  • 13,653
  • 8
  • 51
  • 67
1

You can put this in your .spacemacs to bind SPC p f to search all projects.

(spacemacs/set-leader-keys "pf" 'helm-projectile-find-file-in-known-projects)