diff --git a/autoload/airline/formatter/short_path.vim b/autoload/airline/formatter/short_path.vim new file mode 100644 index 00000000..675704e2 --- /dev/null +++ b/autoload/airline/formatter/short_path.vim @@ -0,0 +1,8 @@ +scriptencoding utf-8 + +function! airline#formatter#short_path#format(val) abort + if get(g:, 'airline_stl_path_style', 'default') ==# 'short' + return '%{pathshorten(expand("'.a:val.'"))}%' + endif + return a:val +endfunction diff --git a/autoload/airline/init.vim b/autoload/airline/init.vim index b3191d8d..f23562b0 100644 --- a/autoload/airline/init.vim +++ b/autoload/airline/init.vim @@ -146,7 +146,7 @@ function! airline#init#bootstrap() \ 'function': 'airline#parts#readonly', \ 'accent': 'red', \ }) - call airline#parts#define_raw('file', '%f%m') + call airline#parts#define_raw('file', airline#formatter#short_path#format('%f%m')) call airline#parts#define_raw('path', '%F%m') call airline#parts#define('linenr', { \ 'raw': '%{g:airline_symbols.linenr}%l', diff --git a/t/init.vim b/t/init.vim index 6cc5620e..a6a4a4f1 100644 --- a/t/init.vim +++ b/t/init.vim @@ -33,6 +33,11 @@ describe 'init sections' Expect g:airline_section_c == '%<%f%m %#__accent_red#%{airline#util#wrap(airline#parts#readonly(),0)}%#__restore__#%#__accent_bold#%#__restore__#' end + it 'section c should be file and coc_status short style' + let g:airline_stl_path_style = 'short' + Expect g:airline_section_c == '%<%{airline#formatter#short_path#format("%f%m")}% %#__accent_red#%{airline#util#wrap(airline#parts#readonly(),0)}%#__restore__#%#__accent_bold#%#__restore__#' + end + it 'section x should be filetype' Expect g:airline_section_x == '%{airline#util#prepend("",0)}%{airline#util#prepend("",0)}%{airline#util#prepend("",0)}%{airline#util#prepend("",0)}%{airline#util#wrap(airline#parts#filetype(),0)}' end