-
-
Save bla-rs/c439daa0aaa5dea899056bc0b7d34ead to your computer and use it in GitHub Desktop.
A vim status line item to display git branch name and status of the currently edited file. To be put in the ~/.vimrc.
This file contains hidden or 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
" returns a string <branch/XX> where XX corresponds to the git status | |
" (for example "<master/ M>") | |
function! CurrentGitStatus() | |
let gitoutput = systemlist('cd '.expand('%:p:h:S').' && git status --porcelain -b 2>/dev/null') | |
if len(gitoutput) > 0 | |
let b:gitstatus = strpart(get(gitoutput,0,''),3) .'/'. strpart(get(gitoutput,1,' '),1,2) | |
else | |
let b:gitstatus = '' | |
endif | |
endfunc | |
autocmd BufEnter,BufWritePost * call CurrentGitStatus() | |
" example of use in the status line: | |
set stl=%f\ %(<%{b:gitstatus}>%) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I was messing around trying to awk the output of :Git status from fugitive, and I found your code. really helped me! thanks.
I don't tested so much but seems like this works for lightline. idk but it's working now.