fugitiveline: leading zeros dropped in buffername

fixes #2533
This commit is contained in:
Christian Brabandt 2022-05-05 20:17:45 +02:00
parent be5bda1f1d
commit 0241bdb804
No known key found for this signature in database
GPG Key ID: F3F92DA383FDDE09

View File

@ -8,9 +8,7 @@ if !airline#util#has_fugitive()
finish finish
endif endif
function! s:ModifierFlags() let s:has_percent_eval = v:version > 802 || (v:version == 802 && has("patch2854"))
return (exists("+autochdir") && &autochdir) ? ':p' : ':.'
endfunction
function! airline#extensions#fugitiveline#bufname() abort function! airline#extensions#fugitiveline#bufname() abort
if !exists('b:fugitive_name') if !exists('b:fugitive_name')
@ -32,14 +30,15 @@ function! airline#extensions#fugitiveline#bufname() abort
endtry endtry
endif endif
let fmod = s:ModifierFlags() let fmod = (exists("+autochdir") && &autochdir) ? ':p' : ':.'
let result=''
if empty(b:fugitive_name) if empty(b:fugitive_name)
if empty(bufname('%')) if empty(bufname('%'))
return &buftype ==# 'nofile' ? '[Scratch]' : '[No Name]' return &buftype ==# 'nofile' ? '[Scratch]' : '[No Name]'
endif endif
return fnamemodify(bufname('%'), fmod) return s:has_percent_eval ? '%f' : fnamemodify(bufname('%'), fmod)
else else
return fnamemodify(b:fugitive_name, fmod). " [git]" return s:has_percent_eval ? '%f [git]' : (fnamemodify(b:fugitive_name, fmod). " [git]")
endif endif
endfunction endfunction
@ -50,18 +49,20 @@ function! s:sh_autocmd_handler()
endfunction endfunction
function! airline#extensions#fugitiveline#init(ext) abort function! airline#extensions#fugitiveline#init(ext) abort
let prct = s:has_percent_eval ? '%' : ''
if exists("+autochdir") && &autochdir if exists("+autochdir") && &autochdir
" if 'acd' is set, vim-airline uses the path section, so we need to redefine this here as well " if 'acd' is set, vim-airline uses the path section, so we need to redefine this here as well
if get(g:, 'airline_stl_path_style', 'default') ==# 'short' if get(g:, 'airline_stl_path_style', 'default') ==# 'short'
call airline#parts#define_raw('path', '%<%{pathshorten(airline#extensions#fugitiveline#bufname())}%m') call airline#parts#define_raw('path', '%<%{'. prct. 'pathshorten(airline#extensions#fugitiveline#bufname())' . prct . '}%m')
else else
call airline#parts#define_raw('path', '%<%{airline#extensions#fugitiveline#bufname()}%m') call airline#parts#define_raw('path', '%<%{' . prct . 'airline#extensions#fugitiveline#bufname()' . prct . '}%m')
endif endif
else else
if get(g:, 'airline_stl_path_style', 'default') ==# 'short' if get(g:, 'airline_stl_path_style', 'default') ==# 'short'
call airline#parts#define_raw('file', '%<%{pathshorten(airline#extensions#fugitiveline#bufname())}%m') call airline#parts#define_raw('file', '%<%{' . prct . 'pathshorten(airline#extensions#fugitiveline#bufname())' . prct . '}%m')
else else
call airline#parts#define_raw('file', '%<%{airline#extensions#fugitiveline#bufname()}%m') call airline#parts#define_raw('file', '%<%{' . prct . 'airline#extensions#fugitiveline#bufname()' . prct . '}%m')
endif endif
endif endif
autocmd ShellCmdPost,CmdwinLeave * call s:sh_autocmd_handler() autocmd ShellCmdPost,CmdwinLeave * call s:sh_autocmd_handler()