nerdtree
46 строк · 2.2 Кб
1" ============================================================================
2" File: vcs.vim
3" Description: NERDTree plugin that provides a command to open on the root of
4" a version control system repository.
5" Maintainer: Phil Runninger
6" License: This program is free software. It comes without any warranty,
7" to the extent permitted by applicable law. You can redistribute
8" it and/or modify it under the terms of the Do What The Fuck You
9" Want To Public License, Version 2, as published by Sam Hocevar.
10" See http://sam.zoy.org/wtfpl/COPYING for more details.
11"
12" ============================================================================
13command! -n=? -complete=dir -bar NERDTreeVCS :call <SID>CreateTabTreeVCS('<args>')
14command! -n=? -complete=dir -bar NERDTreeToggleVCS :call <SID>ToggleTabTreeVCS('<args>')
15
16" FUNCTION: s:CreateTabTreeVCS(a:name) {{{1
17function! s:CreateTabTreeVCS(name)
18let l:path = g:NERDTreeCreator._pathForString(a:name)
19let l:path = s:FindParentVCSRoot(l:path)
20call g:NERDTreeCreator.createTabTree(empty(l:path) ? '' : l:path._str())
21endfunction
22
23" FUNCTION: s:ToggleTabTreeVCS(a:name) {{{1
24" Behaves the same as ToggleTabTree except roots directory at VCS root
25function! s:ToggleTabTreeVCS(name)
26let l:path = g:NERDTreeCreator._pathForString(a:name)
27let l:path = s:FindParentVCSRoot(l:path)
28call g:NERDTreeCreator.toggleTabTree(empty(l:path) ? '' : l:path._str())
29endfunction
30
31" FUNCTION: s:FindParentVCSRoot(a:path) {{{1
32" Finds the root version control system folder of the given path. If a:path is
33" not part of a repository, return the original path.
34function! s:FindParentVCSRoot(path)
35let l:path = a:path
36while !empty(l:path) &&
37\ l:path._str() !~# '^\(\a:[\\\/]\|\/\)$' &&
38\ !isdirectory(l:path._str() . '/.git') &&
39\ !isdirectory(l:path._str() . '/.svn') &&
40\ !isdirectory(l:path._str() . '/.hg') &&
41\ !isdirectory(l:path._str() . '/.bzr') &&
42\ !isdirectory(l:path._str() . '/_darcs')
43let l:path = l:path.getParent()
44endwhile
45return (empty(l:path) || l:path._str() =~# '^\(\a:[\\\/]\|\/\)$') ? a:path : l:path
46endfunction
47
48