瀏覽代碼

Check user options properly

References #220.
Marco Hinz 9 年之前
父節點
當前提交
3c3a835d8d
共有 1 個文件被更改,包括 9 次插入16 次删除
  1. 9 16
      autoload/startify.vim

+ 9 - 16
autoload/startify.vim

@@ -420,17 +420,17 @@ function! s:open_buffer(entry)
   if a:entry.type == 'special'
     execute a:entry.cmd
   elseif a:entry.type == 'session'
-    execute a:entry.cmd a:entry.path
+    execute a:entry.cmd fnameescape(a:entry.path)
   elseif a:entry.type == 'file'
     if line2byte('$') == -1
-      execute 'edit' a:entry.path
+      execute 'edit' fnameescape(a:entry.path)
     else
       if a:entry.cmd == 'tabnew'
         wincmd =
       endif
-      execute a:entry.cmd a:entry.path
+      execute a:entry.cmd fnameescape(a:entry.path)
     endif
-    call s:check_user_options()
+    call s:check_user_options(a:entry.path)
   endif
 endfunction
 
@@ -757,22 +757,15 @@ function! s:sort_by_tick(one, two)
 endfunction
 
 " Function: s:check_user_options {{{1
-function! s:check_user_options() abort
-  let path    = expand('%')
-  let session = path . s:sep .'Session.vim'
+function! s:check_user_options(path) abort
+  let session = a:path . s:sep .'Session.vim'
 
-  " change to VCS root directory
   if get(g:, 'startify_session_autoload') && filereadable(session)
     execute 'source' session
   elseif get(g:, 'startify_change_to_vcs_root')
-    call s:cd_to_vcs_root(path)
-  " change directory
+    call s:cd_to_vcs_root(a:path)
   elseif get(g:, 'startify_change_to_dir', 1)
-    if isdirectory(path)
-      lcd %
-    else
-      lcd %:p:h
-    endif
+    execute 'lcd' fnameescape(isdirectory(a:path) ? a:path : fnamemodify(a:path, ':h'))
   endif
 endfunction
 
@@ -782,7 +775,7 @@ function! s:cd_to_vcs_root(path) abort
   for vcs in [ '.git', '.hg', '.bzr', '.svn' ]
     let root = finddir(vcs, dir .';')
     if !empty(root)
-      execute 'cd '. fnamemodify(root, ':h')
+      execute 'cd '. fnameescape(fnamemodify(root, ':h'))
       return
     endif
   endfor