Add FugitiveFilename() to determine corresponding real file
This commit is contained in:
parent
b571bff9ec
commit
cc9d8d93c8
@ -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
|
||||
|
@ -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!
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user