-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompletion-rules.sh
More file actions
68 lines (62 loc) · 1.87 KB
/
completion-rules.sh
File metadata and controls
68 lines (62 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#
# Bash completion extension file for the git-partial-clone script
#
# Copyright (c) 2021 Lucero Alvarado
# https://github.com/lu0/git-partial-clone
#
have git-partial-clone &&
_git-partial-clone()
{
local cur prev
local words cword
# Complete by using _split_longopt()
_init_completion -s || return
# Try to stop option suggestion if -(-f)ile was provided
local i use_config_file
for ((i = cword - 1; i > 0; i--)); do
{ [[ ${words[i]} == --file* ]] || [[ ${words[i]} == -f ]] ;} \
&& use_config_file=true && break
done
case "${prev}" in
--file | -!(-*)f)
# Suggest files with .conf extension
_expand "$cur" && _filedir '?()conf'
return
;;
--host | -!(-*)h)
# Suggest tested hosts
COMPREPLY=( $(compgen -W '
github gitlab
' -- "$cur" ) )
return 0
;;
--token | -!(-*)t)
# Autocomplete for any file/directory
_expand "$cur" && _filedir
return
;;
--owner | -o | --repo | -r | --subdir | -s | \
--branch | -b | --depth | -d | \
--tag | -v)
# Suggest nothing :P
return
;;
--tag | -v)
return
;;
--help*)
return
;;
esac
# Suggest options contained in the 'usage'
# section of the git-partial-clone script
# If the option is long, suggest it with a leading '='
# unless it is the --help option
[[ ! $use_config_file ]] \
&& COMPREPLY=($(compgen -W '
$(_parse_help "$1" \
| while read opt; do echo ${opt}\=; done \
| sed "s/--help=/--help/g")
' -- "$cur"))
}
complete -o nosort -o nospace -F _git-partial-clone git-partial-clone