Delegate :Git grep to :Ggrep

This commit is contained in:
Tim Pope 2019-08-11 21:27:59 -04:00
parent 03710a877a
commit 79b1f16a7a

View File

@ -3704,16 +3704,20 @@ function! s:GrepParseLine(prefix, name_only, dir, line) abort
return entry
endfunction
function! s:Grep(listnr, bang, arg) abort
function! s:GrepSubcommand(line1, line2, range, bang, mods, args) abort
let dir = s:Dir()
exe s:DirCheck(dir)
let listnr = a:listnr
let listnr = a:line1 == 0 ? a:line1 : a:line2
let cmd = s:UserCommandList(dir) + ['--no-pager', 'grep', '-n', '--no-color', '--full-name']
if fugitive#GitVersion(2, 19)
call add(cmd, '--column')
endif
let tree = s:Tree(dir)
let [args, after] = s:SplitExpandChain(a:arg, tree)
if type(a:args) == type([])
let [args, after] = [a:args, '']
else
let [args, after] = s:SplitExpandChain(a:args, tree)
endif
let prefix = s:PlatformSlash(s:HasOpt(args, '--cached') || empty(tree) ? 'fugitive://' . dir . '//0/' : tree . '/')
let name_only = s:HasOpt(args, '-l', '--files-with-matches', '--name-only', '-L', '--files-without-match')
let title = [listnr < 0 ? ':Ggrep' : ':Glgrep'] + args
@ -3859,9 +3863,9 @@ function! s:Log(type, bang, line1, count, args) abort
return s:QuickfixStream(listnr, title, cmd, !a:bang, s:function('s:LogParse'), state, path, dir) . after
endfunction
call s:command("-bang -nargs=? -range=-1 -addr=windows -complete=customlist,s:GrepComplete Ggrep :execute s:Grep(<count>,<bang>0,<q-args>)")
call s:command("-bang -nargs=? -complete=customlist,s:GrepComplete Gcgrep :execute s:Grep(-1,<bang>0,<q-args>)")
call s:command("-bang -nargs=? -complete=customlist,s:GrepComplete Glgrep :execute s:Grep(0,<bang>0,<q-args>)")
call s:command("-bang -nargs=? -range=-1 -addr=windows -complete=customlist,s:GrepComplete Ggrep", "grep")
call s:command("-bang -nargs=? -complete=customlist,s:GrepComplete Gcgrep :execute s:GrepSubcommand(-1, -1, 0, <bang>0, '<mods>', <q-args>)")
call s:command("-bang -nargs=? -complete=customlist,s:GrepComplete Glgrep :execute s:GrepSubcommand(0, 0, 0, <bang>0, '<mods>', <q-args>)")
call s:command("-bang -nargs=? -range=-1 -addr=other -complete=customlist,s:LogComplete Glog :exe s:Log('c',<bang>0,<line1>,<count>,<q-args>)")
call s:command("-bang -nargs=? -range=-1 -addr=other -complete=customlist,s:LogComplete Gclog :exe s:Log('c',<bang>0,<line1>,<count>,<q-args>)")
call s:command("-bang -nargs=? -range=-1 -addr=other -complete=customlist,s:LogComplete Gllog :exe s:Log('l',<bang>0,<line1>,<count>,<q-args>)")