Просмотр исходного кода

Merge pull request 42 from bling

Marco Hinz 12 лет назад
Родитель
Сommit
d6932388c6
2 измененных файлов с 23 добавлено и 0 удалено
  1. 15 0
      autoload/startify.vim
  2. 8 0
      doc/startify.txt

+ 15 - 0
autoload/startify.vim

@@ -431,6 +431,9 @@ function! s:check_user_options() abort
   " autoload session
   if get(g:, 'startify_session_autoload') && filereadable(session)
     execute 'source' session
+  " change to VCS root directory
+  elseif get(g:, 'startify_change_to_vcs_root')
+    call s:cd_to_vcs_root(path)
   " change directory
   elseif get(g:, 'startify_change_to_dir', 1)
     if isdirectory(path)
@@ -441,6 +444,18 @@ function! s:check_user_options() abort
   endif
 endfunction
 
+" Function: s:cd_to_vcs_root {{{1
+function! s:cd_to_vcs_root(path) abort
+  let dir = fnamemodify(a:path, ':p:h')
+  for vcs in [ '.git', '.hg', '.bzr', '.svn' ]
+    let root = finddir(vcs, dir .';')
+    if !empty(root)
+      execute 'cd '. fnamemodify(root, ':h')
+      return
+    endif
+  endfor
+endfunction
+
 " Function: s:close {{{1
 function! s:close() abort
   if len(filter(range(0, bufnr('$')), 'buflisted(v:val)'))

+ 8 - 0
doc/startify.txt

@@ -185,6 +185,14 @@ Automatically update sessions before exiting Vim.
 When opening a file or bookmark, change to its directory.
 
 
+============-                                    *g:startify_change_to_vcs_root*
+
+    let g:startify_change_to_vcs_root = 0
+
+When opening a file or bookmark, seek and change to the root directory of the
+VCS (if there is one).
+
+
 ============-                                              *g:startify_skiplist*
 
     let g:startify_skiplist = []