nerdtree

A tree explorer plugin for vim.
Index Commits Files Refs
nerdtree_plugin/vcs.vim (2241B)
   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 " ============================================================================
  13 command! -n=? -complete=dir -bar NERDTreeVCS :call <SID>CreateTabTreeVCS('<args>')
  14 command! -n=? -complete=dir -bar NERDTreeToggleVCS :call <SID>ToggleTabTreeVCS('<args>')
  15 
  16 " FUNCTION: s:CreateTabTreeVCS(a:name) {{{1
  17 function! s:CreateTabTreeVCS(name)
  18     let l:path = g:NERDTreeCreator._pathForString(a:name)
  19     let l:path = s:FindParentVCSRoot(l:path)
  20     call g:NERDTreeCreator.createTabTree(empty(l:path) ? '' : l:path._str())
  21 endfunction
  22 
  23 " FUNCTION: s:ToggleTabTreeVCS(a:name) {{{1
  24 " Behaves the same as ToggleTabTree except roots directory at VCS root
  25 function! s:ToggleTabTreeVCS(name)
  26     let l:path = g:NERDTreeCreator._pathForString(a:name)
  27     let l:path = s:FindParentVCSRoot(l:path)
  28     call g:NERDTreeCreator.toggleTabTree(empty(l:path) ? '' : l:path._str())
  29 endfunction
  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.
  34 function! s:FindParentVCSRoot(path)
  35     let l:path = a:path
  36     while !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')
  43         let l:path = l:path.getParent()
  44     endwhile
  45     return (empty(l:path) || l:path._str() =~# '^\(\a:[\\\/]\|\/\)$') ? a:path : l:path
  46 endfunction
  47