Skip to content

Commit

Permalink
add a probe_use_gitignore option
Browse files Browse the repository at this point in the history
This lets you automatically ignore any files or directories in
.gitignore (or any other input files to the git exclude mechanism).
  • Loading branch information
campbellr committed May 30, 2016
1 parent 9ac3457 commit cfb935e
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
31 changes: 29 additions & 2 deletions autoload/probe/file.vim
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,12 @@ function! probe#file#scan()
let s:file_cache_order = s:file_cache_order[1:]
endif

" recursively scan for files
let s:file_caches[s:hash] = s:scan_files(getcwd(), [], 0, {})
" scan for files
if g:probe_use_gitignore && s:is_git()
let s:file_caches[s:hash] = s:scan_git()
else
let s:file_caches[s:hash] = s:scan_files(getcwd(), [], 0, {})
endif

if g:probe_cache_dir != ''
cal s:save_cache(s:cache_filepath(), s:file_caches[s:hash])
Expand All @@ -72,6 +76,29 @@ function! probe#file#scan()
return s:file_caches[s:hash]
endfunction

function! s:is_git()
let metadir_name = fnamemodify(s:find_metadir(), ':t')
return metadir_name == '.git'
endfunction

function! s:scan_git()
let files = []
echo "Scanning " . s:find_repo_root()

let cmd = "git ls-files -c -o --exclude-standard;" .
\ "git submodule foreach -q " .
\ "'for file in $(git ls-files -c -o --exclude-standard); " .
\ "do echo \"$path/$file\"; done'"
for name in split(system(cmd), "\n")
if len(files) >= g:probe_max_file_cache_size
break
endif
cal add(files, fnamemodify(name, ':.'))
endfor
return files
endfunction


function! probe#file#open(filepath)
let filepath = escape(a:filepath, '\\|%# "')
exe printf('edit %s', filepath)
Expand Down
8 changes: 8 additions & 0 deletions doc/probe.txt
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,14 @@ OPTIONS *probe-options*

g:probe_ignore_files still functions normally when this option is set.

|g:probe_use_gitignore| *g:probe_use_gitignore*
When in a git repository, ignore any file excluded by .gitignore (or
other relevent exclude files) when scanning for files.
Default: (boolean) 0

g:probe_ignore_files and g:probe_use_wildignore still function normally
when this option is set.

|g:probe_mappings| *g:probe_mappings*
Dict used to customize mappings. If a mapping is given for some operation
the default mapping will not be created.
Expand Down
6 changes: 5 additions & 1 deletion plugin/probe.vim
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
if exists('g:probe_loaded')
"TODO
"finish
"finish
endif
let g:probe_loaded = 1

Expand Down Expand Up @@ -54,6 +54,10 @@ if !exists('g:probe_mappings')
let g:probe_mappings = {}
endif

if !exists('g:probe_use_gitignore')
let g:probe_use_gitignore = 0
endif

command! -bar Probe call probe#file#find_in_repo()
command! ProbeFindFile call probe#file#find()
command! ProbeFindInRepo call probe#file#find_in_repo()
Expand Down

0 comments on commit cfb935e

Please sign in to comment.