mirror of
https://github.com/vim-airline/vim-airline-themes.git
synced 2024-12-05 00:13:34 +08:00
restore original directory change detection. also resolves #474.
This commit is contained in:
parent
d111e4edb3
commit
a37f0b9ae0
|
@ -2,7 +2,6 @@
|
||||||
" vim: et ts=2 sts=2 sw=2
|
" vim: et ts=2 sts=2 sw=2
|
||||||
|
|
||||||
let s:has_fugitive = exists('*fugitive#head')
|
let s:has_fugitive = exists('*fugitive#head')
|
||||||
let s:has_fugitive_detect = 0 " TODO: figure out alternative
|
|
||||||
let s:has_lawrencium = exists('*lawrencium#statusline')
|
let s:has_lawrencium = exists('*lawrencium#statusline')
|
||||||
let s:has_vcscommand = get(g:, 'airline#extensions#branch#use_vcscommand', 0) && exists('*VCSCommandGetStatusLine')
|
let s:has_vcscommand = get(g:, 'airline#extensions#branch#use_vcscommand', 0) && exists('*VCSCommandGetStatusLine')
|
||||||
|
|
||||||
|
@ -10,8 +9,30 @@ if !s:has_fugitive && !s:has_lawrencium && !s:has_vcscommand
|
||||||
finish
|
finish
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
let s:git_dirs = {}
|
||||||
|
function! s:get_git_branch(path)
|
||||||
|
if has_key(s:git_dirs, a:path)
|
||||||
|
return s:git_dirs[a:path]
|
||||||
|
endif
|
||||||
|
|
||||||
|
let dir = fugitive#extract_git_dir(a:path)
|
||||||
|
if empty(dir)
|
||||||
|
let name = ''
|
||||||
|
else
|
||||||
|
try
|
||||||
|
let line = join(readfile(dir . '/HEAD'))
|
||||||
|
let name = strpart(line, 16)
|
||||||
|
catch
|
||||||
|
let name = ''
|
||||||
|
endtry
|
||||||
|
endif
|
||||||
|
|
||||||
|
let s:git_dirs[a:path] = name
|
||||||
|
return name
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! airline#extensions#branch#head()
|
function! airline#extensions#branch#head()
|
||||||
if exists('b:airline_head')
|
if exists('b:airline_head') && !empty(b:airline_head)
|
||||||
return b:airline_head
|
return b:airline_head
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
@ -20,9 +41,8 @@ function! airline#extensions#branch#head()
|
||||||
if s:has_fugitive && !exists('b:mercurial_dir')
|
if s:has_fugitive && !exists('b:mercurial_dir')
|
||||||
let b:airline_head = fugitive#head()
|
let b:airline_head = fugitive#head()
|
||||||
|
|
||||||
if empty(b:airline_head) && s:has_fugitive_detect && !exists('b:git_dir')
|
if empty(b:airline_head) && !exists('b:git_dir')
|
||||||
call fugitive#detect(getcwd())
|
let b:airline_head = s:get_git_branch(getcwd())
|
||||||
let b:airline_head = fugitive#head()
|
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
@ -84,5 +104,5 @@ function! airline#extensions#branch#init(ext)
|
||||||
call airline#parts#define_function('branch', 'airline#extensions#branch#get_head')
|
call airline#parts#define_function('branch', 'airline#extensions#branch#get_head')
|
||||||
|
|
||||||
autocmd BufReadPost * unlet! b:airline_file_in_root
|
autocmd BufReadPost * unlet! b:airline_file_in_root
|
||||||
autocmd CursorHold * unlet! b:airline_head
|
autocmd CursorHold,ShellCmdPost,CmdwinLeave * unlet! b:airline_head
|
||||||
endfunction
|
endfunction
|
||||||
|
|
Loading…
Reference in New Issue
Block a user