support display only tail end of a branch; as well as custom format

functions. resolves #710.
This commit is contained in:
Bailey Ling 2015-02-27 22:04:13 -05:00
parent f0492b5aea
commit ca44fd467c
2 changed files with 32 additions and 2 deletions

View File

@ -9,6 +9,21 @@ if !s:has_fugitive && !s:has_lawrencium && !s:has_vcscommand
finish
endif
let s:head_format = get(g:, 'airline#extensions#branch#format', 0)
if s:head_format == 1
function! s:format_name(name)
return fnamemodify(a:name, ':t')
endfunction
elseif type(s:head_format) == type('')
function! s:format_name(name)
return call(s:head_format, [a:name])
endfunction
else
function! s:format_name(name)
return a:name
endfunction
endif
let s:git_dirs = {}
function! s:get_git_branch(path)
if has_key(s:git_dirs, a:path)
@ -79,6 +94,7 @@ function! airline#extensions#branch#head()
endif
endif
let b:airline_head = s:format_name(b:airline_head)
return b:airline_head
endfunction

View File

@ -296,13 +296,27 @@ vcscommand <http://www.vim.org/scripts/script.php?script_id=90>
<
* change the text for when no branch is detected >
let g:airline#extensions#branch#empty_message = ''
<
* use vcscommand.vim if available >
let g:airline#extensions#branch#use_vcscommand = 0
<
* truncate long branch names to a fixed length >
let g:airline#extensions#branch#displayed_head_limit = 10
<
* customize formatting of branch name >
" default value leaves the name unmodifed
let g:airline#extensions#branch#format = 0
" to only show the tail, e.g. a branch 'feature/foo' show 'foo'
let g:airline#extensions#branch#format = 1
" if a string is provided, it should be the name of a function that
" takes a string and returns the desired value
let g:airline#extensions#branch#format = 'CustomBranchName'
function! CustomBranchName(name)
return '[' . a:name . ']'
endfunction
<
------------------------------------- *airline-syntastic*
syntastic <https://github.com/scrooloose/syntastic>