Created
March 23, 2012 13:08
-
-
Save kien/2170481 to your computer and use it in GitHub Desktop.
VCS directory extension
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" ============================================================================= | |
" File: autoload/ctrlp/vcsdir.vim | |
" Description: VCS directory extension | |
" Author: Kien Nguyen <github.com/kien> | |
" ============================================================================= | |
" User Configuration {{{1 | |
" Enable: | |
" let g:ctrlp_extensions = ['vcsdir'] | |
" Create A Command: | |
" com! -n=? -com=dir CtrlPVCSDir cal ctrlp#init(ctrlp#vcsdir#id(), <q-args>) | |
"}}} | |
" Init {{{1 | |
if exists('g:loaded_ctrlp_vcsdir') && g:loaded_ctrlp_vcsdir | |
fini | |
en | |
let [g:loaded_ctrlp_vcsdir, g:ctrlp_newvcs] = [1, 0] | |
fu! ctrlp#vcsdir#opts() | |
let opts = { | |
\ 'g:ctrlp_vcsdir': ['s:marker', '.git/'], | |
\ } | |
for [ke, va] in items(opts) | |
exe 'let' va[0] '=' string(exists(ke) ? eval(ke) : va[1]) | |
endfo | |
endf | |
cal ctrlp#vcsdir#opts() | |
let s:vcsdir_var = { | |
\ 'init': 'ctrlp#vcsdir#init()', | |
\ 'accept': 'ctrlp#vcsdir#accept', | |
\ 'lname': 'vcs dirs', | |
\ 'sname': 'vcs', | |
\ 'type': 'path', | |
\ 'opts': 'ctrlp#vcsdir#opts()', | |
\ } | |
let g:ctrlp_ext_vars = exists('g:ctrlp_ext_vars') && !empty(g:ctrlp_ext_vars) | |
\ ? add(g:ctrlp_ext_vars, s:vcsdir_var) : [s:vcsdir_var] | |
let s:id = g:ctrlp_builtins + len(g:ctrlp_ext_vars) | |
" Utilities {{{1 | |
fu! s:globdirs(dir) | |
if type(s:marker) == 3 | |
sil! cal ctrlp#progress('Finding '.join(s:marker, ", ").'...') | |
for each in s:marker | |
cal extend(g:ctrlp_allvcsdirs, split(globpath(a:dir, '**/'.each, 1), "\n")) | |
endfo | |
elsei type(s:marker) == 1 | |
sil! cal ctrlp#progress('Finding '.s:marker.'...') | |
let g:ctrlp_allvcsdirs = split(globpath(a:dir, '**/'.s:marker, 1), "\n") | |
en | |
retu map(g:ctrlp_allvcsdirs, 'fnamemodify(v:val, ":h:h")') | |
endf | |
" Public {{{1 | |
fu! ctrlp#vcsdir#init(...) | |
let s:cwd = getcwd() | |
let cadir = ctrlp#utils#cachedir().ctrlp#utils#lash().s:vcsdir_var['sname'] | |
let cafile = cadir.ctrlp#utils#lash().ctrlp#utils#cachefile(s:vcsdir_var['sname']) | |
if g:ctrlp_newvcs || !filereadable(cafile) | |
let g:ctrlp_allvcsdirs = [] | |
cal s:globdirs(s:cwd) | |
cal ctrlp#rmbasedir(g:ctrlp_allvcsdirs) | |
let read_cache = 0 | |
el | |
let g:ctrlp_allvcsdirs = ctrlp#utils#readfile(cafile) | |
let read_cache = 1 | |
en | |
if !read_cache | |
cal ctrlp#utils#writecache(g:ctrlp_allvcsdirs, cadir, cafile) | |
let g:ctrlp_newvcs = 0 | |
en | |
retu g:ctrlp_allvcsdirs | |
endf | |
fu! ctrlp#vcsdir#accept(mode, str) | |
cal ctrlp#setdir(s:cwd.ctrlp#utils#lash().a:str, 'cd!') | |
cal ctrlp#switchtype(0) | |
cal ctrlp#recordhist() | |
cal ctrlp#prtclear() | |
endf | |
fu! ctrlp#vcsdir#id() | |
retu s:id | |
endf | |
"}}} | |
" vim:fen:fdm=marker:fmr={{{,}}}:fdl=0:fdc=1:ts=2:sw=2:sts=2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment