From ca44fd467c1e94d05b9aca58c37697dbdb7fce44 Mon Sep 17 00:00:00 2001 From: Bailey Ling Date: Fri, 27 Feb 2015 22:04:13 -0500 Subject: [PATCH] support display only tail end of a branch; as well as custom format functions. resolves #710. --- autoload/airline/extensions/branch.vim | 16 ++++++++++++++++ doc/airline.txt | 18 ++++++++++++++++-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/autoload/airline/extensions/branch.vim b/autoload/airline/extensions/branch.vim index 6decaf16..f779fc9f 100644 --- a/autoload/airline/extensions/branch.vim +++ b/autoload/airline/extensions/branch.vim @@ -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 diff --git a/doc/airline.txt b/doc/airline.txt index 2a8886fb..489c090a 100644 --- a/doc/airline.txt +++ b/doc/airline.txt @@ -296,13 +296,27 @@ vcscommand < * 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