mirror of
https://github.com/pcvolkmer/vim-fugistate.git
synced 2025-04-19 23:36:49 +00:00
Show overall git dir status
This commit is contained in:
parent
ed8a9ecda5
commit
b47b8091da
@ -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`.
|
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),
|
For example, to show the filename with git status using [lightline.vim](https://github.com/itchyny/lightline.vim),
|
||||||
configure as follows.
|
configure as follows.
|
||||||
|
|
||||||
|
@ -4,12 +4,11 @@
|
|||||||
|
|
||||||
let s:filename_status = ''
|
let s:filename_status = ''
|
||||||
|
|
||||||
function! fugistate#update()
|
let s:changed = 0
|
||||||
|
let s:new = 0
|
||||||
|
let s:unversioned = 0
|
||||||
|
|
||||||
if empty(@%)
|
function! fugistate#update()
|
||||||
let s:filename_status = ''
|
|
||||||
return
|
|
||||||
endif
|
|
||||||
|
|
||||||
if empty(g:fugistate_expand_filename)
|
if empty(g:fugistate_expand_filename)
|
||||||
let filename = expand(@%)
|
let filename = expand(@%)
|
||||||
@ -17,30 +16,59 @@ function! fugistate#update()
|
|||||||
let filename = expand(g:fugistate_expand_filename)
|
let filename = expand(g:fugistate_expand_filename)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
let s:changed = 0
|
||||||
|
let s:new = 0
|
||||||
|
let s:unversioned = 0
|
||||||
|
|
||||||
|
let s:filename_status = filename
|
||||||
|
|
||||||
try
|
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()
|
if ! empty(@%) && @% == filestate[3:]
|
||||||
let s:filename_status = filename
|
let s:filename_status = filename . " [" . filestate[0:1] . "]"
|
||||||
return
|
endif
|
||||||
|
endfor
|
||||||
endif
|
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
|
endtry
|
||||||
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! fugistate#filename_status()
|
function! fugistate#file()
|
||||||
|
|
||||||
return s:filename_status
|
return s:filename_status
|
||||||
|
|
||||||
endfunction
|
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
|
||||||
|
@ -18,5 +18,9 @@ augroup FugiState
|
|||||||
augroup END
|
augroup END
|
||||||
|
|
||||||
function! FugiState()
|
function! FugiState()
|
||||||
return fugistate#filename_status()
|
return fugistate#file()
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! FugiStateGitDir()
|
||||||
|
return fugistate#gitdir()
|
||||||
endfunction
|
endfunction
|
||||||
|
Loading…
x
Reference in New Issue
Block a user