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

51 lines
1.4 KiB
VimL
Raw Normal View History

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