Last active
December 30, 2015 03:49
-
-
Save qstrahl/7771446 to your computer and use it in GitHub Desktop.
Cool statusline and tabline settings with fugitive support
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function! MyTabLine() | |
let s = '' | |
let s .= '%#TabLine#' | |
let s .= '%<' | |
let s .= '%(%{fnamemodify(getcwd(), ":~")} %)' | |
if (exists('*fugitive#buffer')) | |
let s .= '%(⌥ %{exists("b:git_dir")?fugitive#head(7):""} %)' | |
endif | |
let s .= '%=' | |
let s .= '%([%{tabpagenr("$") > 1 ? tabpagenr()."/".tabpagenr("$") : ""}]%)' | |
return s | |
endfunction | |
function! MyStatusLine() | |
let s = '' | |
let s .= '%(%{&buftype=="help"?"Ⓗ":""} %)' | |
let s .= '%(%{&buftype=="quickfix"?MyQuickfixIndicator(bufnr("%")):""} %)' | |
let s .= '%(%{&previewwindow?"Ⓟ":""} %)' | |
let s .= '%<' | |
let s .= '%{MyBufferName(bufnr("%"))}' | |
let s .= '%( ⌥ %{MyGitCommit(bufnr("%"))}%)' | |
let s .= '%( %{&modified?"+":""}%)' | |
let s .= '%( %{!&modified && &modifiable?"✓":""}%)' | |
let s .= '%( %{!&modifiable||&readonly?"⚓":""}%)' | |
let s .= ' %l,%c' | |
return s | |
endfunction | |
function! MyBufferName(buf) | |
let name = bufname(a:buf) | |
if &buftype == 'quickfix' | |
let name = exists('w:quickfix_title') ? w:quickfix_title : '[Quickfix List]' | |
elseif name == '' | |
let name = '[No Name]' | |
else | |
try | |
let buf = fugitive#buffer(a:buf) | |
let repo = buf.repo() | |
let path = buf.path() | |
let tree = repo.tree() | |
if strlen(tree . '/' . path) | |
let name = tree . '/' . path | |
endif | |
catch /^fugitive:/ | |
"" That's okay | |
endtry | |
endif | |
return strlen(fnamemodify(name, ':~:.')) ? fnamemodify(name, ':~:.') : fnamemodify(name, ':~') | |
endfunction | |
function! MyGitCommit(buf) | |
try | |
let commit = fugitive#buffer(a:buf).containing_commit() | |
return commit == ':' ? 'HEAD' : commit == 'HEAD' ? '' : strpart(commit, 0, 7) | |
catch /^fugitive:/ | |
return '' | |
endtry | |
endfunction | |
function! MyQuickfixIndicator(bufnr) | |
redir => buffers | |
silent ls | |
redir END | |
let nr = a:bufnr | |
for buf in split(buffers, '\n') | |
if match(buf, '\v^\s*'.nr) > -1 | |
if match(buf, '\[Quickfix List\]') > -1 | |
return 'Ⓠ' | |
else | |
return 'Ⓛ' | |
endif | |
endif | |
endfor | |
return '' | |
endfunction | |
set laststatus=2 | |
set showtabline=2 | |
set statusline=%!MyStatusLine() | |
set tabline=%!MyTabLine() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment