2019-03-25 07:27:10 -04:00
|
|
|
" MIT License. Copyright (c) 2017-2019 Cimbali et al
|
2017-11-22 16:11:58 -05:00
|
|
|
" vim: et ts=2 sts=2 sw=2
|
|
|
|
|
|
|
|
scriptencoding utf-8
|
|
|
|
|
2018-06-04 11:31:13 -04:00
|
|
|
if !airline#util#has_fugitive()
|
2017-11-22 16:11:58 -05:00
|
|
|
finish
|
|
|
|
endif
|
|
|
|
|
2019-03-25 07:34:09 -04:00
|
|
|
function! s:ModifierFlags()
|
|
|
|
return (exists("+autochdir") && &autochdir) ? ':p' : ':.'
|
|
|
|
endfunction
|
2017-11-22 16:11:58 -05:00
|
|
|
|
|
|
|
function! airline#extensions#fugitiveline#bufname()
|
2018-01-09 14:07:54 -05:00
|
|
|
if !exists('b:fugitive_name')
|
|
|
|
let b:fugitive_name = ''
|
|
|
|
try
|
2018-07-21 21:09:36 -04:00
|
|
|
if bufname('%') =~? '^fugitive:' && exists('*FugitiveReal')
|
|
|
|
let b:fugitive_name = FugitiveReal(bufname('%'))
|
2018-06-27 18:07:59 -04:00
|
|
|
elseif exists('b:git_dir')
|
|
|
|
let buffer = fugitive#buffer()
|
|
|
|
if buffer.type('blob')
|
|
|
|
let b:fugitive_name = buffer.repo().translate(buffer.path('/'))
|
|
|
|
endif
|
2018-01-09 14:07:54 -05:00
|
|
|
endif
|
|
|
|
catch
|
|
|
|
endtry
|
2017-12-23 09:18:39 -05:00
|
|
|
endif
|
|
|
|
|
2019-03-25 07:34:09 -04:00
|
|
|
let fmod = s:ModifierFlags()
|
2018-01-09 14:07:54 -05:00
|
|
|
if empty(b:fugitive_name)
|
2019-03-25 07:34:09 -04:00
|
|
|
return fnamemodify(bufname('%'), fmod)
|
2018-01-09 14:07:54 -05:00
|
|
|
else
|
2019-03-25 07:34:09 -04:00
|
|
|
return fnamemodify(b:fugitive_name, fmod). " [git]"
|
2018-01-09 14:07:54 -05:00
|
|
|
endif
|
2017-11-22 16:11:58 -05:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! airline#extensions#fugitiveline#init(ext)
|
2019-03-25 07:34:09 -04:00
|
|
|
if exists("+autochdir") && &autochdir
|
2017-11-22 16:11:58 -05:00
|
|
|
" 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 09:18:39 -05:00
|
|
|
autocmd ShellCmdPost,CmdwinLeave * unlet! b:fugitive_name
|
|
|
|
autocmd User AirlineBeforeRefresh unlet! b:fugitive_name
|
2017-11-22 16:11:58 -05:00
|
|
|
endfunction
|