Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CtrlP: ignore files in subdirectory within a git repo

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.

like image 960
octref Avatar asked Nov 01 '14 20:11

octref


1 Answers

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.

like image 98
octref Avatar answered Sep 28 '22 08:09

octref