1
0
mirror of https://github.com/jdhao/nvim-config.git synced 2025-06-08 14:14:33 +02:00

Use custom git branch name for vim-airline

Airline relies on fugitive to get the branch name, but fugitive is
conditionally loaded. So the branch name is not shown. We need to
provide our own function to get the branch name.
This commit is contained in:
jdhao 2021-08-08 22:05:16 +08:00
parent 1ead4f7824
commit fe26dfa9c1
2 changed files with 12 additions and 0 deletions

View File

@ -159,3 +159,12 @@ function! utils#Inside_git_repo() abort
return v:true
endif
endfunction
function! utils#GetGitBranch()
let l:res = systemlist('git rev-parse --abbrev-ref HEAD')[0]
if match(l:res, 'fatal') != -1
return ''
else
return l:res
endif
endfunction

View File

@ -421,6 +421,9 @@ let g:airline_symbols.branch = '⎇'
let g:airline_symbols.paste = 'ρ'
let g:airline_symbols.spell = 'Ꞩ'
" Custom branch name
let g:airline#extensions#branch#custom_head = 'utils#GetGitBranch'
" Only show git hunks which are non-zero
let g:airline#extensions#hunks#non_zero_only = 1