Skip to content
This repository was archived by the owner on May 8, 2024. It is now read-only.

Commit e8ad68b

Browse files
authored
Merge pull request #287 from obcat/cmdline-completion
Some improvements to cmdline completion
2 parents 97116f3 + 932e8e5 commit e8ad68b

File tree

3 files changed

+85
-3
lines changed

3 files changed

+85
-3
lines changed

autoload/gina/command.vim

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ function! gina#command#complete(arglead, cmdline, cursorpos) abort
3636
\)
3737
elseif a:cmdline =~# printf('^.\{-}Gina\s\+%s$', a:arglead)
3838
return gina#complete#common#command(a:arglead, a:cmdline, a:cursorpos)
39-
else
40-
return []
4139
endif
4240
let cmdline = matchstr(a:cmdline, '^.\{-}Gina\s\+\zs.*')
4341
let scheme = matchstr(cmdline, '^\S\+')

autoload/gina/command/_raw.vim

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,14 @@ function! gina#command#_raw#call(range, args, mods) abort
88
endfunction
99

1010
function! gina#command#_raw#complete(arglead, cmdline, cursorpos) abort
11-
return gina#complete#filename#any(a:arglead, a:cmdline, a:cursorpos)
11+
let args = gina#core#args#new(matchstr(a:cmdline, '^.*\ze .*'))
12+
if empty(args.get(1))
13+
return gina#complete#common#raw_command(a:arglead, a:cmdline, a:cursorpos)
14+
endif
15+
if args.get(1) =~# '^\%(fetch\|pull\|push\|switch\)$'
16+
return s:{args.get(1)}_complete(a:arglead, a:cmdline, a:cursorpos)
17+
endif
18+
return []
1219
endfunction
1320

1421

@@ -22,6 +29,47 @@ function! s:build_args(git, args) abort
2229
return args.lock()
2330
endfunction
2431

32+
function! s:fetch_complete(arglead, cmdline, cursorpos) abort
33+
let args = gina#core#args#new(matchstr(a:cmdline, '^.*\ze .*'))
34+
if empty(args.get(2))
35+
return gina#complete#common#remote(a:arglead, a:cmdline, a:cursorpos)
36+
endif
37+
if empty(args.get(3))
38+
" TODO: Return refspecs in remote repository "args.get(2)".
39+
endif
40+
return []
41+
endfunction
42+
43+
function! s:pull_complete(arglead, cmdline, cursorpos) abort
44+
let args = gina#core#args#new(matchstr(a:cmdline, '^.*\ze .*'))
45+
if empty(args.get(2))
46+
return gina#complete#common#remote(a:arglead, a:cmdline, a:cursorpos)
47+
endif
48+
if empty(args.get(3))
49+
" TODO: Return refspecs in remote repository "args.get(2)".
50+
endif
51+
return []
52+
endfunction
53+
54+
function! s:push_complete(arglead, cmdline, cursorpos) abort
55+
let args = gina#core#args#new(matchstr(a:cmdline, '^.*\ze .*'))
56+
if empty(args.get(2))
57+
return gina#complete#common#remote(a:arglead, a:cmdline, a:cursorpos)
58+
endif
59+
if empty(args.get(3))
60+
return gina#complete#commit#local_branch(a:arglead, a:cmdline, a:cursorpos)
61+
endif
62+
return []
63+
endfunction
64+
65+
function! s:switch_complete(arglead, cmdline, cursorpos) abort
66+
let args = gina#core#args#new(matchstr(a:cmdline, '^.*\ze .*'))
67+
if empty(args.get(2))
68+
return gina#complete#commit#local_branch(a:arglead, a:cmdline, a:cursorpos)
69+
endif
70+
return []
71+
endfunction
72+
2573

2674
" Pipe -----------------------------------------------------------------------
2775
function! s:_pipe_on_exit(exitval) abort dict

autoload/gina/complete/common.vim

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,42 @@ function! gina#complete#common#command(arglead, cmdline, cursorpos) abort
4141
return gina#util#filter(a:arglead, command_names, '^_')
4242
endfunction
4343

44+
function! gina#complete#common#raw_command(arglead, cmdline, cursorpos) abort
45+
return gina#util#filter(a:arglead, [
46+
\ 'add',
47+
\ 'bisect',
48+
\ 'branch',
49+
\ 'checkout',
50+
\ 'clone',
51+
\ 'commit',
52+
\ 'diff',
53+
\ 'fetch',
54+
\ 'grep',
55+
\ 'init',
56+
\ 'log',
57+
\ 'merge',
58+
\ 'mv',
59+
\ 'pull',
60+
\ 'push',
61+
\ 'rebase',
62+
\ 'reset',
63+
\ 'restore',
64+
\ 'rm',
65+
\ 'show',
66+
\ 'status',
67+
\ 'switch',
68+
\ 'tag',
69+
\])
70+
endfunction
71+
72+
function! gina#complete#common#remote(arglead, cmdline, cursorpos) abort
73+
let git = gina#core#get_or_fail()
74+
let result = gina#process#call(git, ['remote'])
75+
if result.status
76+
return []
77+
endif
78+
return gina#util#filter(a:arglead, result.stdout)
79+
endfunction
4480

4581
" Private --------------------------------------------------------------------
4682
function! s:get_cache() abort

0 commit comments

Comments
 (0)