1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-01-23 13:10:04 +08:00

Add gitstatus

This commit is contained in:
wsdjeg 2017-02-27 00:20:37 +08:00
parent 761561a649
commit a01ca069c2
3 changed files with 129 additions and 3 deletions

View File

@ -51,7 +51,6 @@ function! SpaceVim#layers#unite#plugins() abort
\ ['Shougo/unite-session'],
\ ['osyo-manga/unite-quickfix'],
\ ['Shougo/vimfiler.vim',{'merged' : 0, 'loadconf' : 1 , 'loadconf_before' : 1}],
\ ['d42/vimfiler_git.vim', {'merged' : 0, 'loadconf' : 1 }],
\ ['ujihisa/unite-colorscheme'],
\ ['mattn/unite-gist'],
\ ['tacroe/unite-mark'],

View File

@ -0,0 +1,128 @@
let s:save_cpo = &cpo
set cpo&vim
let s:fish = &shell =~# 'fish'
function! vimfiler#columns#gitstatus#define()
return s:column
endfunction"}}}
let s:column = {
\ 'name' : 'gitstatus',
\ 'description' : 'plugin for vimfiler that provides git status support',
\ 'syntax' : 'vimfilerColumn__Git',
\ }
function! s:column.length(files, context) "{{{
return 3
endfunction "}}}
if !exists('g:VimFilerGitIndicatorMap')
let g:VimFilerGitIndicatorMap = {
\ 'Modified' : '✹',
\ 'Staged' : '✚',
\ 'Untracked' : '✭',
\ 'Renamed' : '➜',
\ 'Unmerged' : '═',
\ 'Deleted' : '✖',
\ 'Dirty' : '✗',
\ 'Clean' : '✔︎',
\ 'Ignored' : '☒',
\ 'Unknown' : '?'
\ }
endif
function! s:column.define_syntax(context) "{{{
for name in keys(g:VimFilerGitIndicatorMap)
exe "syntax match vimfilerColumn__Git" . name
\ . " '\[" . g:VimFilerGitIndicatorMap[name]
\ . "\]' contained containedin=vimfilerColumn__Git"
endfor
highlight def link vimfilerColumn__GitModified Special
highlight def link vimfilerColumn__GitStaged Function
highlight def link vimfilerColumn__GitUnstaged Text
highlight def link vimfilerColumn__GitRenamed Title
highlight def link vimfilerColumn__GitUnmerged Label
highlight def link vimfilerColumn__GitDeleted Text
highlight def link vimfilerColumn__GitDirty Tag
highlight def link vimfilerColumn__GitClean DiffAdd
highlight def link vimfilerColumn__GitUnknown Text
endfunction "}}}
function s:directory_of_file(file)
return fnamemodify(a:file, ':h')
endfunction
function! s:system(cmd, ...)
silent let output = (a:0 == 0) ? system(a:cmd) : system(a:cmd, a:1)
return output
endfunction
function! s:git_shellescape(arg)
if a:arg =~ '^[A-Za-z0-9_/.-]\+$'
return a:arg
elseif &shell =~# 'cmd' || gitgutter#utility#using_xolox_shell()
return '"' . substitute(substitute(a:arg, '"', '""', 'g'), '%', '"%"', 'g') . '"'
else
return shellescape(a:arg)
endif
endfunction
function! s:cmd_in_directory_of_file(file, cmd)
return 'cd '.s:git_shellescape(s:directory_of_file(a:file)) . (s:fish ? '; and ' : ' && ') . a:cmd
endfunction
function! s:git_state_to_name(symb) " TODO: X, Y
if a:symb ==# '?'
return 'Untracked'
elseif a:symb ==# ' '
return 'Modified'
elseif a:symb =~# '[MAC]'
return 'Staged'
elseif a:symb ==# 'R'
return 'Renamed'
elseif a:symb ==# 'U' || a:symb ==# 'A' || a:symb ==# 'D'
return 'Unmerged'
elseif a:symb ==# '!'
return 'Ignored'
else
return 'Unknown'
endif
endfunction
function! s:git_state_to_symbol(s)
let name = s:git_state_to_name(a:s)
return g:VimFilerGitIndicatorMap[name]
endfunction
let g:wsd = []
function! s:column.get(file, context) "{{{
let cmd = "git -c color.status=false status -s " . fnamemodify(a:file.action__path, ':.')
let output = systemlist(cmd)
if v:shell_error
return ' '
endif
if a:file.vimfiler__is_directory
if !empty(output)
return '[' . g:VimFilerGitIndicatorMap['Dirty'] . ']'
else
return ' '
endif
else
if !empty(output)
let symb = split(output[0])[0]
return '[' . g:VimFilerGitIndicatorMap[s:git_state_to_name(symb)] . ']'
else
return ' '
endif
endif
endfunction "}}}
let &cpo = s:save_cpo
unlet s:save_cpo
" vim: foldmethod=marker

View File

@ -29,11 +29,10 @@ call vimfiler#custom#profile('default', 'context', {
\ 'winwidth' : g:spacevim_sidebar_width,
\ 'winminwidth' : 30,
\ 'toggle' : 1,
\ 'columns' : 'git',
\ 'auto_expand': 1,
\ 'direction' : 'rightbelow',
\ 'parent': 0,
\ 'explorer_columns' : 'git',
\ 'explorer_columns' : 'gitstatus',
\ 'status' : 1,
\ 'safe' : 0,
\ 'split' : 1,