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,69 +30,85 @@ endif
|
||||||
|
|
||||||
let s:git_dirs = {}
|
let s:git_dirs = {}
|
||||||
function! s:get_git_branch(path)
|
function! s:get_git_branch(path)
|
||||||
if has_key(s:git_dirs, a:path)
|
if !s:has_fugitive
|
||||||
return s:git_dirs[a:path]
|
return ''
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let dir = fugitive#extract_git_dir(a:path)
|
let name = fugitive#head(7)
|
||||||
if empty(dir)
|
if empty(name)
|
||||||
let name = ''
|
if has_key(s:git_dirs, a:path)
|
||||||
else
|
return s:git_dirs[a:path]
|
||||||
try
|
endif
|
||||||
let line = join(readfile(dir . '/HEAD'))
|
|
||||||
if strpart(line, 0, 16) == 'ref: refs/heads/'
|
let dir = fugitive#extract_git_dir(a:path)
|
||||||
let name = strpart(line, 16)
|
if empty(dir)
|
||||||
else
|
|
||||||
" raw commit hash
|
|
||||||
let name = strpart(line, 0, 7)
|
|
||||||
endif
|
|
||||||
catch
|
|
||||||
let name = ''
|
let name = ''
|
||||||
endtry
|
else
|
||||||
|
try
|
||||||
|
let line = join(readfile(dir . '/HEAD'))
|
||||||
|
if strpart(line, 0, 16) == 'ref: refs/heads/'
|
||||||
|
let name = strpart(line, 16)
|
||||||
|
else
|
||||||
|
" raw commit hash
|
||||||
|
let name = strpart(line, 0, 7)
|
||||||
|
endif
|
||||||
|
catch
|
||||||
|
let name = ''
|
||||||
|
endtry
|
||||||
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let s:git_dirs[a:path] = name
|
let s:git_dirs[a:path] = name
|
||||||
return name
|
return name
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! s:get_hg_branch()
|
||||||
|
if s:has_lawrencium
|
||||||
|
return lawrencium#statusline()
|
||||||
|
endif
|
||||||
|
return ''
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! airline#extensions#branch#head()
|
function! airline#extensions#branch#head()
|
||||||
if exists('b:airline_head') && !empty(b:airline_head)
|
if exists('b:airline_head') && !empty(b:airline_head)
|
||||||
return b:airline_head
|
return b:airline_head
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let b:airline_head = ''
|
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
|
let found_fugitive_head = 0
|
||||||
|
|
||||||
if s:has_fugitive && !exists('b:mercurial_dir')
|
let l:git_head = s:get_git_branch(expand("%:p:h"))
|
||||||
let b:airline_head = fugitive#head(7)
|
let l:hg_head = s:get_hg_branch()
|
||||||
|
|
||||||
|
if !empty(l:git_head)
|
||||||
let found_fugitive_head = 1
|
let found_fugitive_head = 1
|
||||||
|
let l:heads.git = (!empty(l:hg_head) ? "git:" : '') . s:format_name(l:git_head)
|
||||||
if empty(b:airline_head) && !exists('b:git_dir')
|
|
||||||
let b:airline_head = s:get_git_branch(expand("%:p:h"))
|
|
||||||
endif
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if empty(b:airline_head)
|
if !empty(l:hg_head)
|
||||||
if s:has_lawrencium
|
let l:heads.mercurial = (!empty(l:git_head) ? "hg:" : '') . s:format_name(l:hg_head)
|
||||||
let b:airline_head = lawrencium#statusline()
|
|
||||||
endif
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if empty(b:airline_head)
|
if empty(l:heads)
|
||||||
if s:has_vcscommand
|
if s:has_vcscommand
|
||||||
call VCSCommandEnableBufferSetup()
|
call VCSCommandEnableBufferSetup()
|
||||||
if exists('b:VCSCommandBufferInfo')
|
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
|
||||||
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
|
||||||
|
let b:airline_head = b:airline_head . l:heads[vcs]
|
||||||
|
endif
|
||||||
|
endfor
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if empty(b:airline_head) || !found_fugitive_head && !s:check_in_path()
|
|
||||||
let b:airline_head = ''
|
|
||||||
endif
|
|
||||||
|
|
||||||
let b:airline_head = s:format_name(b:airline_head)
|
|
||||||
|
|
||||||
if exists("g:airline#extensions#branch#displayed_head_limit")
|
if exists("g:airline#extensions#branch#displayed_head_limit")
|
||||||
let w:displayed_head_limit = g:airline#extensions#branch#displayed_head_limit
|
let w:displayed_head_limit = g:airline#extensions#branch#displayed_head_limit
|
||||||
if len(b:airline_head) > w:displayed_head_limit - 1
|
if len(b:airline_head) > w:displayed_head_limit - 1
|
||||||
|
@ -100,6 +116,9 @@ function! airline#extensions#branch#head()
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
if empty(b:airline_head) || !found_fugitive_head && !s:check_in_path()
|
||||||
|
let b:airline_head = ''
|
||||||
|
endif
|
||||||
return b:airline_head
|
return b:airline_head
|
||||||
endfunction
|
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 >
|
* change the text for when no branch is detected >
|
||||||
let g:airline#extensions#branch#empty_message = ''
|
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 >
|
* use vcscommand.vim if available >
|
||||||
let g:airline#extensions#branch#use_vcscommand = 0
|
let g:airline#extensions#branch#use_vcscommand = 0
|
||||||
<
|
<
|
||||||
|
|
Loading…
Reference in New Issue