CtrlP: ignore files in subdirectory within a git repo
Asked Answered
E

2

10

For my repo, suppose it's called top

top\
  .gitignore
  foo\
  bar\

I want CtrlP to list files that are

  1. Under foo\
  2. Is not ignored by .gitignore defined in top\

If I cd into top\foo\, and open vim from there, 1 would be satisfied but not 2.
If I open vim on top\, 2 would be satisfied but not 1.

How do I achieve both 1 and 2?

I tried this gitignore vim script, but it only parses gitignore when I open vim in the root folder of a repo, so I can't do both 1 and 2 together.
Same for let g:ctrlp_user_command = 'ag %s -l --nocolor -g ""', ag doesn't try to go up to the repo root and read gitignore from there.
Setting g:ctrlp_working_path_mode as r let CtrlP honors .gitignore in the top folder, but everything under top\ would be listed by CtrlP. I just want files in foo\.

Thanks.

Evslin answered 1/11, 2014 at 20:52 Comment(4)
What about CtrlP foo?Palila
@Palila This works but I'd have to type in :CtrlP foo everytime. If foo is deep below the project root then it's very hard to use.Evslin
can't you modify the vim script to reccursively search for .gitgnore in parent directories ?Hexamethylenetetramine
I set my CtrlP to use git ls-files as it's file lister. This ignores the .gitignore files but also looses untracked files. For untracked files I just use git add and they suddenly become tracked and CtrlP will pick them up.Rump
C
12

From its home page it looks like you can use

let g:ctrlp_user_command = [
    \ '.git', 'cd %s && git ls-files . -co --exclude-standard',
    \ 'find %s -type f'
    \ ]

which will have the advantage of honoring all of git's ignore-pattern processing, not just the toplevel positive .gitiginore patterns.

Cleanshaven answered 4/11, 2014 at 6:39 Comment(0)
E
2

Seems there is no apparent way to do it, so I just followed @kamaradclimber 's suggestion, spent an hour and made this: RootIgnore
Never coded in VimScript before so it took me some time :-)

You can install it using Vundle.
It searches upward recursively for .git dir, gets the .gitignore in the same dir as the .git dir, and sets wildignore accordingly.

Update:
@jthill's method works better than mine.
But CtrlP has custom search commands while CommandT does not. So my plugin can still be useful to CommandT users.

Evslin answered 3/11, 2014 at 1:21 Comment(1)
I'm coming from the future. Apparently CommandT has this functionality built in by now.Imbibe

© 2022 - 2024 — McMap. All rights reserved.