From a27c0fc633efcd2b294c07e09f2565df258f83e8 Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Tue, 2 Feb 2010 23:46:04 -0500 Subject: [PATCH] Add optional statusline indicator --- doc/fugitive.txt | 9 +++++++++ plugin/fugitive.vim | 26 ++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/doc/fugitive.txt b/doc/fugitive.txt index 24f39b8..2301e24 100644 --- a/doc/fugitive.txt +++ b/doc/fugitive.txt @@ -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: diff --git a/plugin/fugitive.vim b/plugin/fugitive.vim index 5edd0d5..a1264ac 100644 --- a/plugin/fugitive.vim +++ b/plugin/fugitive.vim @@ -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: