vim-airline/autoload/airline/extensions/fugitiveline.vim

46 lines
1.1 KiB
VimL
Raw Normal View History

" MIT License. Copyright (c) 2017 Cimbali.
" vim: et ts=2 sts=2 sw=2
scriptencoding utf-8
if !exists('*fugitive#head')
finish
endif
if exists("+autochdir") && &autochdir == 1
let s:fmod = ':p'
else
let s:fmod = ':.'
endif
function! airline#extensions#fugitiveline#bufname()
2017-12-23 14:18:39 +00:00
if exists('b:fugitive_name')
return b:fugitive_name
endif
let b:fugitive_name = fnamemodify(bufname('%'), s:fmod)
try
let buffer = fugitive#buffer()
if buffer.type('blob')
2017-12-23 14:18:39 +00:00
let b:fugitive_name = fnamemodify(buffer.repo().translate(buffer.path()), s:fmod)
endif
catch
endtry
2017-12-23 14:18:39 +00:00
return b:fugitive_name
endfunction
function! airline#extensions#fugitiveline#init(ext)
if exists("+autochdir") && &autochdir == 1
" if 'acd' is set, vim-airline uses the path section, so we need to redefine this here as well
call airline#parts#define_raw('path', '%<%{airline#extensions#fugitiveline#bufname()}%m')
else
call airline#parts#define_raw('file', '%<%{airline#extensions#fugitiveline#bufname()}%m')
endif
2017-12-23 14:18:39 +00:00
autocmd ShellCmdPost,CmdwinLeave * unlet! b:fugitive_name
autocmd User AirlineBeforeRefresh unlet! b:fugitive_name
endfunction