From 761561a6491002e79e7f2205304528791d4d0b74 Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Sun, 26 Feb 2017 22:08:04 +0800 Subject: [PATCH 1/3] Add vimfiler-git --- autoload/SpaceVim/layers/unite.vim | 1 + config/plugins/vimfiler.vim | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/autoload/SpaceVim/layers/unite.vim b/autoload/SpaceVim/layers/unite.vim index 5403f37d5..626620732 100644 --- a/autoload/SpaceVim/layers/unite.vim +++ b/autoload/SpaceVim/layers/unite.vim @@ -51,6 +51,7 @@ 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'], diff --git a/config/plugins/vimfiler.vim b/config/plugins/vimfiler.vim index 6163c40c7..5d9067022 100644 --- a/config/plugins/vimfiler.vim +++ b/config/plugins/vimfiler.vim @@ -29,11 +29,11 @@ call vimfiler#custom#profile('default', 'context', { \ 'winwidth' : g:spacevim_sidebar_width, \ 'winminwidth' : 30, \ 'toggle' : 1, - \ 'columns' : 'type', + \ 'columns' : 'git', \ 'auto_expand': 1, \ 'direction' : 'rightbelow', \ 'parent': 0, - \ 'explorer_columns' : 'type', + \ 'explorer_columns' : 'git', \ 'status' : 1, \ 'safe' : 0, \ 'split' : 1, From a01ca069c2e1b0b96f2be9c5348f6dcd3f2a45fb Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Mon, 27 Feb 2017 00:20:37 +0800 Subject: [PATCH 2/3] Add gitstatus --- autoload/SpaceVim/layers/unite.vim | 1 - autoload/vimfiler/columns/gitstatus.vim | 128 ++++++++++++++++++++++++ config/plugins/vimfiler.vim | 3 +- 3 files changed, 129 insertions(+), 3 deletions(-) create mode 100644 autoload/vimfiler/columns/gitstatus.vim diff --git a/autoload/SpaceVim/layers/unite.vim b/autoload/SpaceVim/layers/unite.vim index 626620732..5403f37d5 100644 --- a/autoload/SpaceVim/layers/unite.vim +++ b/autoload/SpaceVim/layers/unite.vim @@ -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'], diff --git a/autoload/vimfiler/columns/gitstatus.vim b/autoload/vimfiler/columns/gitstatus.vim new file mode 100644 index 000000000..acc2540b3 --- /dev/null +++ b/autoload/vimfiler/columns/gitstatus.vim @@ -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 diff --git a/config/plugins/vimfiler.vim b/config/plugins/vimfiler.vim index 5d9067022..14cf6ab7a 100644 --- a/config/plugins/vimfiler.vim +++ b/config/plugins/vimfiler.vim @@ -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, From ae00f6bda1adc192334ef775a863cb0ebd90c50c Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Mon, 27 Feb 2017 21:42:14 +0800 Subject: [PATCH 3/3] Fix lint --- autoload/vimfiler/columns/gitstatus.vim | 42 +++++++++++++++---------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/autoload/vimfiler/columns/gitstatus.vim b/autoload/vimfiler/columns/gitstatus.vim index acc2540b3..01adaab2c 100644 --- a/autoload/vimfiler/columns/gitstatus.vim +++ b/autoload/vimfiler/columns/gitstatus.vim @@ -1,9 +1,10 @@ let s:save_cpo = &cpo set cpo&vim +scriptencoding utf-8 let s:fish = &shell =~# 'fish' -function! vimfiler#columns#gitstatus#define() +function! vimfiler#columns#gitstatus#define() abort return s:column endfunction"}}} @@ -13,9 +14,14 @@ let s:column = { \ 'syntax' : 'vimfilerColumn__Git', \ } -function! s:column.length(files, context) "{{{ +" @vimlint(EVL103, 1, a:files) +" @vimlint(EVL103, 1, a:context) +function! s:column.length(files, context) abort return 3 -endfunction "}}} +endfunction +" @vimlint(EVL103, 0, a:files) +" @vimlint(EVL103, 0, a:context) + if !exists('g:VimFilerGitIndicatorMap') let g:VimFilerGitIndicatorMap = { \ 'Modified' : '✹', @@ -31,9 +37,10 @@ if !exists('g:VimFilerGitIndicatorMap') \ } endif -function! s:column.define_syntax(context) "{{{ +" @vimlint(EVL103, 1, a:context) +function! s:column.define_syntax(context) abort for name in keys(g:VimFilerGitIndicatorMap) - exe "syntax match vimfilerColumn__Git" . name + exe 'syntax match vimfilerColumn__Git' . name \ . " '\[" . g:VimFilerGitIndicatorMap[name] \ . "\]' contained containedin=vimfilerColumn__Git" endfor @@ -46,20 +53,21 @@ function! s:column.define_syntax(context) "{{{ highlight def link vimfilerColumn__GitDirty Tag highlight def link vimfilerColumn__GitClean DiffAdd highlight def link vimfilerColumn__GitUnknown Text -endfunction "}}} +endfunction +" @vimlint(EVL103, 0, a:context) -function s:directory_of_file(file) +function! s:directory_of_file(file) abort return fnamemodify(a:file, ':h') endfunction -function! s:system(cmd, ...) +function! s:system(cmd, ...) abort 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_/.-]\+$' +function! s:git_shellescape(arg) abort + 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') . '"' @@ -68,13 +76,13 @@ function! s:git_shellescape(arg) endif endfunction -function! s:cmd_in_directory_of_file(file, cmd) +function! s:cmd_in_directory_of_file(file, cmd) abort 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 +function! s:git_state_to_name(symb) abort if a:symb ==# '?' return 'Untracked' elseif a:symb ==# ' ' @@ -93,15 +101,16 @@ endif endfunction -function! s:git_state_to_symbol(s) +function! s:git_state_to_symbol(s) abort 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, ':.') +" @vimlint(EVL103, 1, a:context) +function! s:column.get(file, context) abort + let cmd = 'git -c color.status=false status -s ' . fnamemodify(a:file.action__path, ':.') let output = systemlist(cmd) if v:shell_error return ' ' @@ -120,7 +129,8 @@ function! s:column.get(file, context) "{{{ return ' ' endif endif -endfunction "}}} +endfunction +" @vimlint(EVL103, 0, a:context) let &cpo = s:save_cpo unlet s:save_cpo