diff --git a/autoload/fugitive.vim b/autoload/fugitive.vim index c020d09..a90094e 100644 --- a/autoload/fugitive.vim +++ b/autoload/fugitive.vim @@ -66,6 +66,14 @@ function! s:shellslash(path) abort endif endfunction +function! s:PlatformSlash(path) abort + if exists('+shellslash') && !&shellslash + return tr(a:path, '/', '\') + else + return a:path + endif +endfunction + let s:executables = {} function! s:executable(binary) abort @@ -429,6 +437,25 @@ call s:add_methods('repo',['keywordprg']) " Section: Buffer +function! s:UrlSplit(path) abort + let vals = matchlist(s:shellslash(a:path), '\c^fugitive://\(.\{-\}\)//\(\w\+\)\(/.*\)\=$') + if empty(vals) + return ['', '', ''] + endif + return [vals[1], (vals[2] =~# '^.$' ? ':' : '') . vals[2], vals[3]] +endfunction + +function! fugitive#Filename(url) abort + let [dir, rev, file] = s:UrlSplit(a:url) + if len(dir) + return s:PlatformSlash(FugitiveTreeForGitDir(dir) . file) + elseif a:url =~# '^[\\/]\|^\a:[\\/]' + return s:PlatformSlash(a:url) + else + return '' + endif +endfunction + let s:buffer_prototype = {} function! s:buffer(...) abort diff --git a/plugin/fugitive.vim b/plugin/fugitive.vim index f69aa0c..8d522c3 100644 --- a/plugin/fugitive.vim +++ b/plugin/fugitive.vim @@ -138,6 +138,15 @@ function! FugitiveHead(...) abort return fugitive#repo().head(a:0 ? a:1 : 0) endfunction +function! FugitiveFilename(...) abort + let file = fnamemodify(a:0 ? a:1 : @%, ':p') + if file =~? '^fugitive:' + return fugitive#Filename(file) + else + return file + endif +endfunction + augroup fugitive autocmd!