fugitiveline: simplify modify logic

The 'autochdir' option could be toggled on later in a session.
So do not set the has_autochdir flag once the file is read, but evaluate
it every time the corresponding function is called.

While at it, get rid of the s:fmod variable. Instead let a helper
function return the correct modifier flags depending on the value of the
'autochdir' option.
This commit is contained in:
Christian Brabandt 2019-03-25 12:34:09 +01:00
parent c8a36e14e9
commit 1fb184305b
No known key found for this signature in database
GPG Key ID: F3F92DA383FDDE09
1 changed files with 7 additions and 10 deletions

View File

@ -7,13 +7,9 @@ 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! s:ModifierFlags()
return (exists("+autochdir") && &autochdir) ? ':p' : ':.'
endfunction
function! airline#extensions#fugitiveline#bufname()
if !exists('b:fugitive_name')
@ -31,15 +27,16 @@ function! airline#extensions#fugitiveline#bufname()
endtry
endif
let fmod = s:ModifierFlags()
if empty(b:fugitive_name)
return fnamemodify(bufname('%'), s:fmod)
return fnamemodify(bufname('%'), fmod)
else
return fnamemodify(b:fugitive_name, s:fmod). " [git]"
return fnamemodify(b:fugitive_name, fmod). " [git]"
endif
endfunction
function! airline#extensions#fugitiveline#init(ext)
if s:has_autochdir
if exists("+autochdir") && &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