Add optional statusline indicator
This commit is contained in:
parent
315eb92abd
commit
a27c0fc633
@ -195,6 +195,15 @@ HEAD^:Makefile The file named Makefile in the parent of HEAD
|
||||
:3 The current file in the merged branch during a conflict
|
||||
:/foo The most recent commit with "foo" in the message
|
||||
|
||||
STATUSLINE *fugitive-statusline*
|
||||
|
||||
*fugitive#statusline()*
|
||||
Add %{fugitive#statusline()} to your statusline to get an indicator including
|
||||
the current branch and the currently edited file's commit. If you don't have
|
||||
a statusline, this one matches the default when 'ruler' is set:
|
||||
>
|
||||
set statusline=%<%f\ %h%m%r%{fugitive#statusline()}%=%-14.(%l,%c%V%)\ %P
|
||||
<
|
||||
ABOUT *fugitive-about*
|
||||
|
||||
Grab the latest version or report a bug on Github:
|
||||
|
@ -1608,6 +1608,32 @@ function! s:GF(mode) abort
|
||||
endtry
|
||||
endfunction
|
||||
|
||||
" }}}1
|
||||
" Statusline {{{1
|
||||
|
||||
function! s:repo_head_ref() dict abort
|
||||
return readfile(s:repo().dir('HEAD'))[0]
|
||||
endfunction
|
||||
|
||||
call s:add_methods('repo',['head_ref'])
|
||||
|
||||
function! fugitive#statusline(...)
|
||||
if !exists('b:git_dir')
|
||||
return ''
|
||||
endif
|
||||
let status = 'Git'
|
||||
if s:buffer().commit() != ''
|
||||
let status .= ':' . s:buffer().commit()[0:7]
|
||||
endif
|
||||
let head = s:repo().head_ref()
|
||||
if head =~# '^ref: '
|
||||
let status .= s:sub(head,'^ref: %(refs/%(heads/|remotes/|tags/)=)=','(').')'
|
||||
elseif head =~# '^\x\{40\}$'
|
||||
let status .= '('.head[0:7].')'
|
||||
endif
|
||||
return '['.status.']'
|
||||
endfunction
|
||||
|
||||
" }}}1
|
||||
|
||||
" vim:set ft=vim ts=8 sw=2 sts=2:
|
||||
|
Loading…
Reference in New Issue
Block a user