2021-01-01 20:57:00 +08:00
|
|
|
" MIT License. Copyright (c) 2017-2021 Cimbali et al
|
2019-11-09 03:18:04 +08:00
|
|
|
" Plugin: https://github.com/tpope/vim-fugitive
|
2017-11-23 05:11:58 +08:00
|
|
|
" vim: et ts=2 sts=2 sw=2
|
|
|
|
|
|
|
|
scriptencoding utf-8
|
|
|
|
|
2018-06-04 23:31:13 +08:00
|
|
|
if !airline#util#has_fugitive()
|
2017-11-23 05:11:58 +08:00
|
|
|
finish
|
|
|
|
endif
|
|
|
|
|
2022-05-06 02:17:45 +08:00
|
|
|
let s:has_percent_eval = v:version > 802 || (v:version == 802 && has("patch2854"))
|
2017-11-23 05:11:58 +08:00
|
|
|
|
2021-07-12 01:22:43 +08:00
|
|
|
function! airline#extensions#fugitiveline#bufname() abort
|
2018-01-10 03:07:54 +08:00
|
|
|
if !exists('b:fugitive_name')
|
|
|
|
let b:fugitive_name = ''
|
|
|
|
try
|
2018-07-22 09:09:36 +08:00
|
|
|
if bufname('%') =~? '^fugitive:' && exists('*FugitiveReal')
|
|
|
|
let b:fugitive_name = FugitiveReal(bufname('%'))
|
2019-04-24 21:48:16 +08:00
|
|
|
elseif exists('b:git_dir') && exists('*fugitive#repo')
|
|
|
|
if get(b:, 'fugitive_type', '') is# 'blob'
|
|
|
|
let b:fugitive_name = fugitive#repo().translate(FugitivePath(@%, ''))
|
|
|
|
endif
|
|
|
|
elseif exists('b:git_dir') && !exists('*fugitive#repo')
|
2018-06-28 06:07:59 +08:00
|
|
|
let buffer = fugitive#buffer()
|
|
|
|
if buffer.type('blob')
|
|
|
|
let b:fugitive_name = buffer.repo().translate(buffer.path('/'))
|
|
|
|
endif
|
2018-01-10 03:07:54 +08:00
|
|
|
endif
|
|
|
|
catch
|
|
|
|
endtry
|
2017-12-23 22:18:39 +08:00
|
|
|
endif
|
|
|
|
|
2022-05-06 02:17:45 +08:00
|
|
|
let fmod = (exists("+autochdir") && &autochdir) ? ':p' : ':.'
|
|
|
|
let result=''
|
2018-01-10 03:07:54 +08:00
|
|
|
if empty(b:fugitive_name)
|
2021-04-14 14:30:03 +08:00
|
|
|
if empty(bufname('%'))
|
|
|
|
return &buftype ==# 'nofile' ? '[Scratch]' : '[No Name]'
|
|
|
|
endif
|
2022-05-06 02:17:45 +08:00
|
|
|
return s:has_percent_eval ? '%f' : fnamemodify(bufname('%'), fmod)
|
2018-01-10 03:07:54 +08:00
|
|
|
else
|
2022-05-06 02:17:45 +08:00
|
|
|
return s:has_percent_eval ? '%f [git]' : (fnamemodify(b:fugitive_name, fmod). " [git]")
|
2018-01-10 03:07:54 +08:00
|
|
|
endif
|
2017-11-23 05:11:58 +08:00
|
|
|
endfunction
|
|
|
|
|
2021-04-30 19:25:26 +08:00
|
|
|
function! s:sh_autocmd_handler()
|
|
|
|
if exists('#airline')
|
|
|
|
unlet! b:fugitive_name
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2021-07-12 01:22:43 +08:00
|
|
|
function! airline#extensions#fugitiveline#init(ext) abort
|
2022-05-06 02:17:45 +08:00
|
|
|
let prct = s:has_percent_eval ? '%' : ''
|
|
|
|
|
2019-03-25 19:34:09 +08:00
|
|
|
if exists("+autochdir") && &autochdir
|
2017-11-23 05:11:58 +08:00
|
|
|
" if 'acd' is set, vim-airline uses the path section, so we need to redefine this here as well
|
2021-07-12 01:22:43 +08:00
|
|
|
if get(g:, 'airline_stl_path_style', 'default') ==# 'short'
|
2022-05-06 02:17:45 +08:00
|
|
|
call airline#parts#define_raw('path', '%<%{'. prct. 'pathshorten(airline#extensions#fugitiveline#bufname())' . prct . '}%m')
|
2021-07-12 01:22:43 +08:00
|
|
|
else
|
2022-05-06 02:17:45 +08:00
|
|
|
call airline#parts#define_raw('path', '%<%{' . prct . 'airline#extensions#fugitiveline#bufname()' . prct . '}%m')
|
2021-07-12 01:22:43 +08:00
|
|
|
endif
|
2017-11-23 05:11:58 +08:00
|
|
|
else
|
2021-07-12 01:22:43 +08:00
|
|
|
if get(g:, 'airline_stl_path_style', 'default') ==# 'short'
|
2022-05-06 02:17:45 +08:00
|
|
|
call airline#parts#define_raw('file', '%<%{' . prct . 'pathshorten(airline#extensions#fugitiveline#bufname())' . prct . '}%m')
|
2021-07-12 01:22:43 +08:00
|
|
|
else
|
2022-05-06 02:17:45 +08:00
|
|
|
call airline#parts#define_raw('file', '%<%{' . prct . 'airline#extensions#fugitiveline#bufname()' . prct . '}%m')
|
2021-07-12 01:22:43 +08:00
|
|
|
endif
|
2017-11-23 05:11:58 +08:00
|
|
|
endif
|
2021-04-30 19:25:26 +08:00
|
|
|
autocmd ShellCmdPost,CmdwinLeave * call s:sh_autocmd_handler()
|
|
|
|
autocmd User AirlineBeforeRefresh call s:sh_autocmd_handler()
|
2017-11-23 05:11:58 +08:00
|
|
|
endfunction
|