Made fugitive and lawrencium coexist in peace,
meaning that branches retrieved from those are now displayed side by side. The order can be customised with g:airline#extensions#branch#vcs_priority. The VCS name is now prepended to the branch name to be able to tell which is which. The VSCCommand behaviour is unchanged. Also restructured the code a little bit, and made found_fugitive_head variable behave as its name suggests.
This commit is contained in:
parent
7c234a0139
commit
d6a42528a1
|
@ -30,6 +30,12 @@ endif
|
|||
|
||||
let s:git_dirs = {}
|
||||
function! s:get_git_branch(path)
|
||||
if !s:has_fugitive
|
||||
return ''
|
||||
endif
|
||||
|
||||
let name = fugitive#head(7)
|
||||
if empty(name)
|
||||
if has_key(s:git_dirs, a:path)
|
||||
return s:git_dirs[a:path]
|
||||
endif
|
||||
|
@ -50,48 +56,58 @@ function! s:get_git_branch(path)
|
|||
let name = ''
|
||||
endtry
|
||||
endif
|
||||
endif
|
||||
|
||||
let s:git_dirs[a:path] = name
|
||||
return name
|
||||
endfunction
|
||||
|
||||
function! s:get_hg_branch()
|
||||
if s:has_lawrencium
|
||||
return lawrencium#statusline()
|
||||
endif
|
||||
return ''
|
||||
endfunction
|
||||
|
||||
function! airline#extensions#branch#head()
|
||||
if exists('b:airline_head') && !empty(b:airline_head)
|
||||
return b:airline_head
|
||||
endif
|
||||
|
||||
let b:airline_head = ''
|
||||
let l:heads = {}
|
||||
let l:vcs_priority = get(g:, "airline#extensions#branch#vcs_priority", ["git", "mercurial"])
|
||||
let found_fugitive_head = 0
|
||||
|
||||
if s:has_fugitive && !exists('b:mercurial_dir')
|
||||
let b:airline_head = fugitive#head(7)
|
||||
let l:git_head = s:get_git_branch(expand("%:p:h"))
|
||||
let l:hg_head = s:get_hg_branch()
|
||||
|
||||
if !empty(l:git_head)
|
||||
let found_fugitive_head = 1
|
||||
|
||||
if empty(b:airline_head) && !exists('b:git_dir')
|
||||
let b:airline_head = s:get_git_branch(expand("%:p:h"))
|
||||
endif
|
||||
let l:heads.git = (!empty(l:hg_head) ? "git:" : '') . s:format_name(l:git_head)
|
||||
endif
|
||||
|
||||
if empty(b:airline_head)
|
||||
if s:has_lawrencium
|
||||
let b:airline_head = lawrencium#statusline()
|
||||
endif
|
||||
if !empty(l:hg_head)
|
||||
let l:heads.mercurial = (!empty(l:git_head) ? "hg:" : '') . s:format_name(l:hg_head)
|
||||
endif
|
||||
|
||||
if empty(b:airline_head)
|
||||
if empty(l:heads)
|
||||
if s:has_vcscommand
|
||||
call VCSCommandEnableBufferSetup()
|
||||
if exists('b:VCSCommandBufferInfo')
|
||||
let b:airline_head = get(b:VCSCommandBufferInfo, 0, '')
|
||||
let b:airline_head = s:format_name(get(b:VCSCommandBufferInfo, 0, ''))
|
||||
endif
|
||||
endif
|
||||
else
|
||||
for vcs in l:vcs_priority
|
||||
if has_key(l:heads, vcs)
|
||||
if !empty(b:airline_head)
|
||||
let b:airline_head = b:airline_head . " | "
|
||||
endif
|
||||
|
||||
if empty(b:airline_head) || !found_fugitive_head && !s:check_in_path()
|
||||
let b:airline_head = ''
|
||||
let b:airline_head = b:airline_head . l:heads[vcs]
|
||||
endif
|
||||
endfor
|
||||
endif
|
||||
|
||||
let b:airline_head = s:format_name(b:airline_head)
|
||||
|
||||
if exists("g:airline#extensions#branch#displayed_head_limit")
|
||||
let w:displayed_head_limit = g:airline#extensions#branch#displayed_head_limit
|
||||
|
@ -100,6 +116,9 @@ function! airline#extensions#branch#head()
|
|||
endif
|
||||
endif
|
||||
|
||||
if empty(b:airline_head) || !found_fugitive_head && !s:check_in_path()
|
||||
let b:airline_head = ''
|
||||
endif
|
||||
return b:airline_head
|
||||
endfunction
|
||||
|
||||
|
|
|
@ -317,6 +317,10 @@ 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 = ''
|
||||
<
|
||||
* define the order in which the branches of different vcs systems will be
|
||||
displayed on the statusline (currently only for fugitive and lawrencium) >
|
||||
let g:airline#extensions#branch#vcs_priority = ["git", "mercurial"]
|
||||
<
|
||||
* use vcscommand.vim if available >
|
||||
let g:airline#extensions#branch#use_vcscommand = 0
|
||||
<
|
||||
|
|
Loading…
Reference in New Issue