mirror of
https://github.com/tpope/vim-fugitive.git
synced 2025-11-09 12:03:47 -05:00
Provide completion relative to working directory
This commit is contained in:
@@ -1505,10 +1505,21 @@ function! s:GlobComplete(lead, pattern) abort
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! fugitive#CompletePath(base, ...) abort
|
function! fugitive#CompletePath(base, ...) abort
|
||||||
let dir = a:0 == 1 ? a:1 : a:0 == 3 ? a:3 : s:Dir()
|
let dir = a:0 == 1 ? a:1 : a:0 >= 3 ? a:3 : s:Dir()
|
||||||
let tree = s:Tree(dir) . '/'
|
let stripped = matchstr(a:base, '^\%(:/:\=\|:(top)\|:(top,literal)\|:(literal,top)\)')
|
||||||
let strip = '^\%(:/:\=\|:(top)\|:(top,literal)\|:(literal,top)\|:(literal)\)'
|
let base = strpart(a:base, len(stripped))
|
||||||
let base = substitute(a:base, strip, '', '')
|
if len(stripped) || a:0 < 4
|
||||||
|
let root = s:Tree(dir)
|
||||||
|
else
|
||||||
|
let root = a:4
|
||||||
|
endif
|
||||||
|
if root !=# '/' && len(root)
|
||||||
|
let root .= '/'
|
||||||
|
endif
|
||||||
|
if empty(stripped)
|
||||||
|
let stripped = matchstr(a:base, '^\%(:(literal)\|:\)')
|
||||||
|
let base = strpart(a:base, len(stripped))
|
||||||
|
endif
|
||||||
if base =~# '^\.git/'
|
if base =~# '^\.git/'
|
||||||
let pattern = s:gsub(base[5:-1], '/', '*&').'*'
|
let pattern = s:gsub(base[5:-1], '/', '*&').'*'
|
||||||
let matches = s:GlobComplete(dir . '/', pattern)
|
let matches = s:GlobComplete(dir . '/', pattern)
|
||||||
@@ -1520,14 +1531,14 @@ function! fugitive#CompletePath(base, ...) abort
|
|||||||
call map(matches, "'.git/' . v:val")
|
call map(matches, "'.git/' . v:val")
|
||||||
elseif base =~# '^\~/'
|
elseif base =~# '^\~/'
|
||||||
let matches = map(s:GlobComplete(expand('~/'), base[2:-1] . '*'), '"~/" . v:val')
|
let matches = map(s:GlobComplete(expand('~/'), base[2:-1] . '*'), '"~/" . v:val')
|
||||||
elseif a:base =~# '^/\|^\a\+:\|^\.\.\=/\|^:(literal)'
|
elseif a:base =~# '^/\|^\a\+:\|^\.\.\=/'
|
||||||
let matches = s:GlobComplete('', base . '*')
|
let matches = s:GlobComplete('', base . '*')
|
||||||
elseif len(tree) > 1
|
elseif len(root)
|
||||||
let matches = s:GlobComplete(tree, s:gsub(base, '/', '*&').'*')
|
let matches = s:GlobComplete(root, s:gsub(base, '/', '*&').'*')
|
||||||
else
|
else
|
||||||
let matches = []
|
let matches = []
|
||||||
endif
|
endif
|
||||||
call map(matches, 's:fnameescape(s:Slash(matchstr(a:base, strip) . v:val))')
|
call map(matches, 's:fnameescape(s:Slash(stripped . v:val))')
|
||||||
return matches
|
return matches
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
@@ -1545,12 +1556,12 @@ function! s:CompleteHeads(dir) abort
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! fugitive#CompleteObject(base, ...) abort
|
function! fugitive#CompleteObject(base, ...) abort
|
||||||
let dir = a:0 == 1 ? a:1 : a:0 == 3 ? a:3 : s:Dir()
|
let dir = a:0 == 1 ? a:1 : a:0 >= 3 ? a:3 : s:Dir()
|
||||||
|
let tree = s:Tree(dir)
|
||||||
let cwd = getcwd()
|
let cwd = getcwd()
|
||||||
let tree = s:Tree(dir) . '/'
|
|
||||||
let subdir = ''
|
let subdir = ''
|
||||||
if len(tree) > 1 && s:cpath(tree, cwd[0 : len(tree) - 1])
|
if len(tree) && s:cpath(tree . '/', cwd[0 : len(tree)])
|
||||||
let subdir = strpart(cwd, len(tree)) . '/'
|
let subdir = strpart(cwd, len(tree) + 1) . '/'
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if a:base =~# '^\.\=/\|^:(' || a:base !~# ':'
|
if a:base =~# '^\.\=/\|^:(' || a:base !~# ':'
|
||||||
@@ -1566,9 +1577,7 @@ function! fugitive#CompleteObject(base, ...) abort
|
|||||||
endif
|
endif
|
||||||
let results += s:FilterEscape(heads, a:base)
|
let results += s:FilterEscape(heads, a:base)
|
||||||
endif
|
endif
|
||||||
if !empty(tree)
|
let results += a:0 == 1 || a:0 >= 3 ? fugitive#CompletePath(a:base, 0, '', dir, a:0 >= 4 ? a:4 : tree) : fugitive#CompletePath(a:base)
|
||||||
let results += a:0 == 1 ? fugitive#CompletePath(a:base, dir) : fugitive#CompletePath(a:base)
|
|
||||||
endif
|
|
||||||
return results
|
return results
|
||||||
|
|
||||||
elseif a:base =~# '^:'
|
elseif a:base =~# '^:'
|
||||||
@@ -1583,8 +1592,8 @@ function! fugitive#CompleteObject(base, ...) abort
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
else
|
else
|
||||||
let tree = matchstr(a:base, '.*[:/]')
|
let parent = matchstr(a:base, '.*[:/]')
|
||||||
let entries = s:LinesError(['ls-tree', substitute(tree, ':\zs\./', '\=subdir', '')], dir)[0]
|
let entries = s:LinesError(['ls-tree', substitute(parent, ':\zs\./', '\=subdir', '')], dir)[0]
|
||||||
call map(entries,'s:sub(v:val,"^04.*\\zs$","/")')
|
call map(entries,'s:sub(v:val,"^04.*\\zs$","/")')
|
||||||
call map(entries,'tree.s:sub(v:val,".*\t","")')
|
call map(entries,'tree.s:sub(v:val,".*\t","")')
|
||||||
|
|
||||||
@@ -1601,24 +1610,25 @@ function! s:CompleteSub(subcommand, A, L, P, ...) abort
|
|||||||
elseif !a:0
|
elseif !a:0
|
||||||
return fugitive#CompleteObject(a:A, s:Dir())
|
return fugitive#CompleteObject(a:A, s:Dir())
|
||||||
elseif type(a:1) == type(function('tr'))
|
elseif type(a:1) == type(function('tr'))
|
||||||
return call(a:1, [a:A, a:L, a:P])
|
return call(a:1, [a:A, a:L, a:P] + (a:0 > 1 ? a:2 : []))
|
||||||
else
|
else
|
||||||
return s:FilterEscape(a:1, a:A)
|
return s:FilterEscape(a:1, a:A)
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:CompleteRevision(A, L, P, ...) abort
|
function! s:CompleteRevision(A, L, P, ...) abort
|
||||||
return s:FilterEscape(s:CompleteHeads(s:Dir()), a:A)
|
return s:FilterEscape(s:CompleteHeads(a:0 ? a:1 : s:Dir()), a:A)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:CompleteRemote(A, L, P) abort
|
function! s:CompleteRemote(A, L, P, ...) abort
|
||||||
|
let dir = a:0 ? a:1 : s:Dir()
|
||||||
let remote = matchstr(a:L, '\u\w*[! ] *\zs\S\+\ze ')
|
let remote = matchstr(a:L, '\u\w*[! ] *\zs\S\+\ze ')
|
||||||
if !empty(remote)
|
if !empty(remote)
|
||||||
let matches = s:LinesError('ls-remote', remote)[0]
|
let matches = s:LinesError([dir, 'ls-remote', remote])[0]
|
||||||
call filter(matches, 'v:val =~# "\t" && v:val !~# "{"')
|
call filter(matches, 'v:val =~# "\t" && v:val !~# "{"')
|
||||||
call map(matches, 's:sub(v:val, "^.*\t%(refs/%(heads/|tags/)=)=", "")')
|
call map(matches, 's:sub(v:val, "^.*\t%(refs/%(heads/|tags/)=)=", "")')
|
||||||
else
|
else
|
||||||
let matches = s:LinesError('remote')[0]
|
let matches = s:LinesError([dir, 'remote'])[0]
|
||||||
endif
|
endif
|
||||||
return s:FilterEscape(matches, a:A)
|
return s:FilterEscape(matches, a:A)
|
||||||
endfunction
|
endfunction
|
||||||
@@ -2611,7 +2621,8 @@ function! s:Aliases(dir) abort
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! fugitive#Complete(lead, ...) abort
|
function! fugitive#Complete(lead, ...) abort
|
||||||
let dir = a:0 == 1 ? a:1 : a:0 == 3 ? a:3 : s:Dir()
|
let dir = a:0 == 1 ? a:1 : a:0 >= 3 ? a:3 : s:Dir()
|
||||||
|
let root = a:0 >= 4 ? a:4 : s:Tree(s:Dir())
|
||||||
let pre = a:0 > 1 ? strpart(a:1, 0, a:2) : ''
|
let pre = a:0 > 1 ? strpart(a:1, 0, a:2) : ''
|
||||||
let subcmd = matchstr(pre, '\u\w*[! ] *\zs[[:alnum:]-]\+\ze ')
|
let subcmd = matchstr(pre, '\u\w*[! ] *\zs[[:alnum:]-]\+\ze ')
|
||||||
if empty(subcmd)
|
if empty(subcmd)
|
||||||
@@ -2619,17 +2630,22 @@ function! fugitive#Complete(lead, ...) abort
|
|||||||
elseif a:0 ==# 2 && subcmd =~# '^\%(commit\|revert\|push\|fetch\|pull\|merge\|rebase\)$'
|
elseif a:0 ==# 2 && subcmd =~# '^\%(commit\|revert\|push\|fetch\|pull\|merge\|rebase\)$'
|
||||||
let cmdline = substitute(a:1, '\u\w*\([! ] *\)' . subcmd, 'G' . subcmd, '')
|
let cmdline = substitute(a:1, '\u\w*\([! ] *\)' . subcmd, 'G' . subcmd, '')
|
||||||
let caps_subcmd = substitute(subcmd, '\%(^\|-\)\l', '\u&', 'g')
|
let caps_subcmd = substitute(subcmd, '\%(^\|-\)\l', '\u&', 'g')
|
||||||
return fugitive#{caps_subcmd}Complete(a:lead, cmdline, a:2 + len(cmdline) - len(a:1))
|
return fugitive#{caps_subcmd}Complete(a:lead, cmdline, a:2 + len(cmdline) - len(a:1), dir, root)
|
||||||
elseif pre =~# ' -- '
|
elseif pre =~# ' -- '
|
||||||
return fugitive#CompletePath(a:lead, dir)
|
return fugitive#CompletePath(a:lead, a:1, a:2, dir, root)
|
||||||
elseif a:lead =~# '^-'
|
elseif a:lead =~# '^-'
|
||||||
let results = split(s:ChompDefault('', dir, subcmd, '--git-completion-helper'), ' ')
|
let results = split(s:ChompDefault('', dir, subcmd, '--git-completion-helper'), ' ')
|
||||||
else
|
else
|
||||||
return fugitive#CompleteObject(a:lead, dir)
|
return fugitive#CompleteObject(a:lead, a:1, a:2, dir, root)
|
||||||
endif
|
endif
|
||||||
return filter(results, 'strpart(v:val, 0, strlen(a:lead)) ==# a:lead')
|
return filter(results, 'strpart(v:val, 0, strlen(a:lead)) ==# a:lead')
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! fugitive#CompleteForWorkingDir(A, L, P, ...) abort
|
||||||
|
let path = a:0 ? a:1 : getcwd()
|
||||||
|
return fugitive#Complete(a:A, a:L, a:P, FugitiveExtractGitDir(path), path)
|
||||||
|
endfunction
|
||||||
|
|
||||||
" Section: :Gcd, :Glcd
|
" Section: :Gcd, :Glcd
|
||||||
|
|
||||||
function! fugitive#CdComplete(A, L, P) abort
|
function! fugitive#CdComplete(A, L, P) abort
|
||||||
@@ -3789,9 +3805,10 @@ function! s:RevertSubcommand(line1, line2, range, bang, mods, options) abort
|
|||||||
return {'insert_args': ['--edit']}
|
return {'insert_args': ['--edit']}
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! fugitive#CommitComplete(A, L, P) abort
|
function! fugitive#CommitComplete(A, L, P, ...) abort
|
||||||
|
let dir = a:0 ? a:1 : s:Dir()
|
||||||
if a:A =~# '^--fixup=\|^--squash='
|
if a:A =~# '^--fixup=\|^--squash='
|
||||||
let commits = s:LinesError(['log', '--pretty=format:%s', '@{upstream}..'])[0]
|
let commits = s:LinesError([dir, 'log', '--pretty=format:%s', '@{upstream}..'])[0]
|
||||||
let pre = matchstr(a:A, '^--\w*=''\=') . ':/^'
|
let pre = matchstr(a:A, '^--\w*=''\=') . ':/^'
|
||||||
if pre =~# "'"
|
if pre =~# "'"
|
||||||
call map(commits, 'pre . string(tr(v:val, "|\"^$*[]", "......."))[1:-1]')
|
call map(commits, 'pre . string(tr(v:val, "|\"^$*[]", "......."))[1:-1]')
|
||||||
@@ -3801,27 +3818,27 @@ function! fugitive#CommitComplete(A, L, P) abort
|
|||||||
return s:FilterEscape(map(commits, 'pre . tr(v:val, "\\ !^$*?[]()''\"`&;<>|#", "....................")'), a:A)
|
return s:FilterEscape(map(commits, 'pre . tr(v:val, "\\ !^$*?[]()''\"`&;<>|#", "....................")'), a:A)
|
||||||
endif
|
endif
|
||||||
else
|
else
|
||||||
return s:CompleteSub('commit', a:A, a:L, a:P, function('fugitive#CompletePath'))
|
return s:CompleteSub('commit', a:A, a:L, a:P, function('fugitive#CompletePath'), a:000)
|
||||||
endif
|
endif
|
||||||
return []
|
return []
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! fugitive#RevertComplete(A, L, P) abort
|
function! fugitive#RevertComplete(A, L, P, ...) abort
|
||||||
return s:CompleteSub('revert', a:A, a:L, a:P, function('s:CompleteRevision'))
|
return s:CompleteSub('revert', a:A, a:L, a:P, function('s:CompleteRevision'), a:000)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" Section: :Git merge, :Git rebase, :Git pull
|
" Section: :Git merge, :Git rebase, :Git pull
|
||||||
|
|
||||||
function! fugitive#MergeComplete(A, L, P) abort
|
function! fugitive#MergeComplete(A, L, P, ...) abort
|
||||||
return s:CompleteSub('merge', a:A, a:L, a:P, function('s:CompleteRevision'))
|
return s:CompleteSub('merge', a:A, a:L, a:P, function('s:CompleteRevision'), a:000)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! fugitive#RebaseComplete(A, L, P) abort
|
function! fugitive#RebaseComplete(A, L, P, ...) abort
|
||||||
return s:CompleteSub('rebase', a:A, a:L, a:P, function('s:CompleteRevision'))
|
return s:CompleteSub('rebase', a:A, a:L, a:P, function('s:CompleteRevision'), a:000)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! fugitive#PullComplete(A, L, P) abort
|
function! fugitive#PullComplete(A, L, P, ...) abort
|
||||||
return s:CompleteSub('pull', a:A, a:L, a:P, function('s:CompleteRemote'))
|
return s:CompleteSub('pull', a:A, a:L, a:P, function('s:CompleteRemote'), a:000)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:MergeSubcommand(line1, line2, range, bang, mods, options) abort
|
function! s:MergeSubcommand(line1, line2, range, bang, mods, options) abort
|
||||||
@@ -4720,12 +4737,12 @@ endfunction
|
|||||||
|
|
||||||
" Section: :Git push, :Git fetch
|
" Section: :Git push, :Git fetch
|
||||||
|
|
||||||
function! fugitive#PushComplete(A, L, P) abort
|
function! fugitive#PushComplete(A, L, P, ...) abort
|
||||||
return s:CompleteSub('push', a:A, a:L, a:P, function('s:CompleteRemote'))
|
return s:CompleteSub('push', a:A, a:L, a:P, function('s:CompleteRemote'), a:000)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! fugitive#FetchComplete(A, L, P) abort
|
function! fugitive#FetchComplete(A, L, P, ...) abort
|
||||||
return s:CompleteSub('fetch', a:A, a:L, a:P, function('s:CompleteRemote'))
|
return s:CompleteSub('fetch', a:A, a:L, a:P, function('s:CompleteRemote'), a:000)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:AskPassArgs(dir) abort
|
function! s:AskPassArgs(dir) abort
|
||||||
|
|||||||
Reference in New Issue
Block a user