5
5
" Version: 0.2.1
6
6
" Last Modified: Dec 18, 2016
7
7
" ============================================================================
8
+ let s: nomodeline = (v: version > 703 || (v: version == 703 && has (' patch442' ))) ? ' <nomodeline>' : ' '
8
9
let s: is_win = has (" win32" ) || has (' win64' )
9
10
10
11
" Extract git directory by path
@@ -31,8 +32,8 @@ function! s:FindGitdir(path)
31
32
return substitute (root, ' \r\?\n' , ' ' , ' ' ) . ' /.git'
32
33
else
33
34
let dir = finddir (' .git' , expand (a: path ).' ;' )
34
- if dir | return fnamemodify ( dir , ' :p:h ' ) | endif
35
- return ' '
35
+ if empty ( dir ) | return ' ' | endif
36
+ return fnamemodify ( dir , ' :p:h ' )
36
37
endif
37
38
endfunction
38
39
@@ -617,14 +618,18 @@ endfunction
617
618
618
619
" Run git add with files in smartRoot
619
620
function ! easygit#add (... ) abort
620
- if a: 0 == 0 | return | endif
621
621
let root = easygit#smartRoot ()
622
622
if empty (root) | return | endif
623
623
let cwd = getcwd ()
624
624
execute ' lcd ' . root
625
- let args = join (map (copy (a: 000 ), ' shellescape(v:val)' ), ' ' )
626
- let command = ' git add ' . join (a: 000 , ' ' )
625
+ if empty (a: 000 )
626
+ let l: args = expand (' %' )
627
+ else
628
+ let l: args = join (map (copy (a: 000 ), ' shellescape(v:val)' ), ' ' )
629
+ endif
630
+ let command = ' git add ' . l: args
627
631
call s: system (command )
632
+ call s: ResetGutter (bufnr (' %' ))
628
633
execute ' lcd ' . cwd
629
634
endfunction
630
635
@@ -634,13 +639,40 @@ function! easygit#status()
634
639
if empty (root) | return | endif
635
640
let cwd = getcwd ()
636
641
execute ' lcd ' . root
637
- call s: execute (' git status --long -b' , {
642
+ call s: execute (' git --no-pager status --long -b' , {
638
643
\ ' edit' : ' edit' ,
639
644
\ ' title' : ' __easygit_status__' ,
640
645
\} )
641
646
execute ' lcd ' . cwd
642
647
endfunction
643
648
649
+ function ! easygit#read (args )
650
+ let root = easygit#smartRoot ()
651
+ if empty (root) | return | endif
652
+ let old_cwd = getcwd ()
653
+ execute ' lcd ' . root
654
+ if empty (a: args )
655
+ let path = expand (' %' )
656
+ else
657
+ let path = a: args
658
+ endif
659
+ if empty (path ) | return | endif
660
+ let output = system (' git --no-pager show :' .path )
661
+ if v: shell_error && output !=# " "
662
+ echohl Error | echon output | echohl None
663
+ return -1
664
+ endif
665
+ execute ' edit ' . path
666
+ execute ' %d'
667
+ let eol = s: is_win ? ' \v\n' : ' \v\r?\n'
668
+ let list = split (output, eol )
669
+ if len (list )
670
+ call setline (1 , list [0 ])
671
+ silent ! call append (1 , list [1 :])
672
+ endif
673
+ execute ' lcd ' . old_cwd
674
+ endfunction
675
+
644
676
function ! easygit#merge (args )
645
677
if a: 0 == 0 | return | endif
646
678
let root = easygit#smartRoot ()
@@ -678,7 +710,7 @@ function! s:execute(cmd, option) abort
678
710
let edit = get (a: option , ' edit' , ' edit' )
679
711
let pipe = get (a: option , ' pipe' , 0 )
680
712
let bnr = bufnr (' %' )
681
- if edit !~# ' keepalt'
713
+ if edit !~# ' keepalt' && ! get ( a: option , ' nokeep ' , 0 )
682
714
let edit = ' keepalt ' . edit
683
715
endif
684
716
if pipe
@@ -789,4 +821,10 @@ function! s:escape(str)
789
821
endif
790
822
return a: str
791
823
endfunction
824
+
825
+ function ! s: ResetGutter (bufnr )
826
+ if exists (' *gitgutter#process_buffer' )
827
+ call gitgutter#process_buffer (a: bufnr , 1 )
828
+ endif
829
+ endfunction
792
830
" vim:set et sw = 2 ts = 2 tw = 78 :
0 commit comments