Created
October 3, 2013 22:43
-
-
Save mhinz/6818264 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
if has_key(g:toplevel, 'cdlist') | |
let s:cdlist = g:toplevel.cdlist | |
else | |
let s:cdlist = [ | |
\ [ '.git', 'finddir' ], | |
\ [ '.hg', 'finddir' ], | |
\ [ '.bzr', 'finddir' ], | |
\ [ 'foo', 'find' ], | |
\ ] | |
endif | |
" toplevel#cd#find {{{1 | |
function! toplevel#cd#find(bang) abort | |
if exists('b:toplevel_cd') | |
return toplevel#cd_to_root(a:bang, b:toplevel_cd) | |
endif | |
let curdir = resolve(expand('<afile>:p:h')) .';' | |
for dir in s:cdlist | |
let root = (dir[1] == 'finddir') ? finddir(dir[0], curdir) : findfile(dir[0], curdir) | |
if !empty(root) | |
let b:toplevel_cd = fnamemodify(root, ':p:h:h') | |
return toplevel#cd_to_root(a:bang, b:toplevel_cd) | |
endif | |
endfor | |
echohl ErrorMsg | |
echo 'No VCS found.' | |
echohl NONE | |
endfunction |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment