mirror of
https://github.com/vim-airline/vim-airline.git
synced 2025-12-23 20:31:27 +08:00
add gitgutter integration.
This commit is contained in:
@@ -128,6 +128,10 @@ function! airline#extensions#load()
|
||||
call airline#extensions#undotree#init(s:ext)
|
||||
endif
|
||||
|
||||
if g:airline_enable_hunks && exists('*GitGutterGetHunks')
|
||||
call airline#extensions#hunks#init(s:ext)
|
||||
endif
|
||||
|
||||
if g:airline_enable_tagbar && exists(':TagbarToggle')
|
||||
call airline#extensions#tagbar#init(s:ext)
|
||||
endif
|
||||
|
||||
31
autoload/airline/extensions/hunks.vim
Normal file
31
autoload/airline/extensions/hunks.vim
Normal file
@@ -0,0 +1,31 @@
|
||||
" MIT License. Copyright (c) 2013 Bailey Ling.
|
||||
" vim: et ts=2 sts=2 sw=2
|
||||
|
||||
function! airline#extensions#hunks#get_hunks()
|
||||
try
|
||||
" throws an error when first entering a buffer, so we gotta swallow it
|
||||
silent! let hunks = GitGutterGetHunks()
|
||||
let added = 0
|
||||
let removed = 0
|
||||
let changed = 0
|
||||
for hunk in hunks
|
||||
let diff = hunk[3] - hunk[1]
|
||||
if diff > 0
|
||||
let added += diff
|
||||
elseif diff < 0
|
||||
let removed -= diff
|
||||
else
|
||||
let changed += 1
|
||||
endif
|
||||
endfor
|
||||
return printf('+%s ~%s -%s', added, changed, removed)
|
||||
catch
|
||||
return ''
|
||||
endtry
|
||||
return ''
|
||||
endfunction
|
||||
|
||||
function! airline#extensions#hunks#init(ext)
|
||||
let g:airline_section_b .= '%{airline#extensions#hunks#get_hunks()} '
|
||||
endfunction
|
||||
|
||||
Reference in New Issue
Block a user