-
Notifications
You must be signed in to change notification settings - Fork 140
/
robox-completions.sh
62 lines (50 loc) · 1.77 KB
/
robox-completions.sh
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
# main function bound to robox command
_robox()
{
local cur actions cur_action isos boxes configs providers namespaces
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
actions="start links cache validate build cleanup distclean registry-login registry-logout ova vmware hyperv libvirt parallels virtualbox docker isos sums invalid missing public available iso box all"
isos=`./robox.sh list-isos`
boxes=`./robox.sh list-boxes`
configs=`./robox.sh list-configs`
providers=`./robox.sh list-providers`
namespaces=`./robox.sh list-namespaces`
# Complete the action names.
if ((COMP_CWORD == 1)); then
COMPREPLY=( $(compgen -W "${actions} ${namespaces} ${providers} ${configs}" -- ${cur}) )
return 0;
fi
# # If there is command or separator in arguments then stop completion.
# if ((COMP_CWORD > 3)); then
# for word in "${COMP_WORDS[@]}"; do
# if [[ ${word} == \'* || ${word} == \"* || ${word} == "--" ]] ; then
# return 0
# fi
# done
# fi
# Complete one or none action argument.
if ((COMP_CWORD = 2)); then
cur_action="${COMP_WORDS[1]}"
case "$cur_action" in
# Argument is collection name
iso)
if ((COMP_CWORD == 2)); then
COMPREPLY=( $(compgen -W "$isos" -- ${cur}) )
fi
return 0
;;
# Argument is a box name.
box)
COMPREPLY=( $(compgen -W "$boxes" -- ${cur}))
return 0
;;
# No argument
*)
return 0
;;
esac
fi
}
# bind the robox command to the _robox function for completion
complete -F _robox ./robox.sh