1
0
mirror of https://github.com/pcvolkmer/vim-fugistate.git synced 2025-04-19 15:26:50 +00:00

Show overall git dir status

This commit is contained in:
Paul-Christian Volkmer 2022-01-10 15:15:58 +01:00
parent ed8a9ecda5
commit b47b8091da
3 changed files with 60 additions and 22 deletions

View File

@ -10,6 +10,12 @@ This simple plugin provides a function which returns the name of current file wi
It will show something like `main.c [ M]` for modified file `main.c`.
```vim
:echo FugiStateGitDir()
```
This will show changes, new and unversioned files, e.g. `1 change, 2 new, 3 unversioned`.
For example, to show the filename with git status using [lightline.vim](https://github.com/itchyny/lightline.vim),
configure as follows.

View File

@ -4,12 +4,11 @@
let s:filename_status = ''
function! fugistate#update()
let s:changed = 0
let s:new = 0
let s:unversioned = 0
if empty(@%)
let s:filename_status = ''
return
endif
function! fugistate#update()
if empty(g:fugistate_expand_filename)
let filename = expand(@%)
@ -17,30 +16,59 @@ function! fugistate#update()
let filename = expand(g:fugistate_expand_filename)
endif
let s:changed = 0
let s:new = 0
let s:unversioned = 0
let s:filename_status = filename
try
let gitstatus = FugitiveExecute('status', '-s')
if gitstatus.exit_status == 0
for filestate in gitstatus.stdout
if match(filestate, '^?') == 0
let s:unversioned = s:unversioned + 1
elseif match(filestate, '^A') == 0
let s:new = s:new + 1
elseif ! empty(filestate)
let s:changed = s:changed + 1
endif
if ! FugitiveIsGitDir()
let s:filename_status = filename
return
if ! empty(@%) && @% == filestate[3:]
let s:filename_status = filename . " [" . filestate[0:1] . "]"
endif
endfor
endif
let gitstatus = FugitiveExecute('status', '-s', @%)
if gitstatus.exit_status != 0 || empty(gitstatus.stdout[0])
let s:filename_status = filename
return
endif
let s:filename_status = filename . " [" . gitstatus.stdout[0][0:1] . "]"
catch
let s:filename_status = filename
endtry
endfunction
function! fugistate#filename_status()
function! fugistate#file()
return s:filename_status
endfunction
function! fugistate#gitdir()
let s:out = []
if s:changed == 1
call add(s:out, "1 change")
endif
if s:changed > 1
call add(s:out, s:changed . " changes")
endif
if s:new > 0
call add(s:out, s:new . " new")
endif
if s:unversioned > 0
call add(s:out, s:unversioned . " unversioned")
endif
return join(s:out, ', ')
endfunction

View File

@ -18,5 +18,9 @@ augroup FugiState
augroup END
function! FugiState()
return fugistate#filename_status()
return fugistate#file()
endfunction
function! FugiStateGitDir()
return fugistate#gitdir()
endfunction