forked from mechboxes/mech
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmech_completion.sh
117 lines (111 loc) · 3.24 KB
/
mech_completion.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/usr/bin/env bash
#
# bash completion file for mech
#
# This script provides completion of:
# - commands and their options
#
# To enable the completions either:
# - place this file in /etc/bash_completion.d
# or
# - copy this file to e.g. ~/.mech-completion.sh and add the line
# below to your .bashrc after bash completion features are loaded
# . ~/.mech-completion.sh
#
_mech() {
local cur prev opts base
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
# Options that will complete
opts="box destroy down global-status halt init ip list ls pause port provision ps reload resume scp snapshot stop ssh-config suspend up"
# Complete the arguments to some of the basic commands.
case "${prev}" in
box)
COMPREPLY=( $( compgen -W 'add delete list ls remove' -- "$cur" ) )
return 0
;;
destroy)
local commands="-f --force -h --help"
COMPREPLY=( $(compgen -W "${commands} $(get_instances)" -- ${cur}) )
return 0
;;
down)
local commands="-f --force -h --help"
COMPREPLY=( $(compgen -W "${commands} $(get_instances)" -- ${cur}) )
return 0
;;
global-status)
local commands="-h --help"
COMPREPLY=( $(compgen -W "${commands}" -- ${cur}) )
return 0
;;
init)
local commands="--box --box-version --force -h --help --name"
COMPREPLY=( $(compgen -W "${commands}" -- ${cur}) )
return 0
;;
ip)
local commands="-h --help"
COMPREPLY=( $(compgen -W "${commands} $(get_instances)" -- ${cur}) )
return 0
;;
list)
local commands="-d --detail -h --help"
COMPREPLY=( $(compgen -W "${commands} $(get_instances)" -- ${cur}) )
return 0
;;
pause)
local commands="-h --help"
COMPREPLY=( $(compgen -W "${commands} $(get_instances)" -- ${cur}) )
return 0
;;
port)
local commands="--guest -h --help"
COMPREPLY=( $(compgen -W "${commands} $(get_instances)" -- ${cur}) )
return 0
;;
provision)
local commands="-h --help -s --show"
COMPREPLY=( $(compgen -W "${commands} $(get_instances)" -- ${cur}) )
return 0
;;
ps)
local commands="-h --help"
COMPREPLY=( $(compgen -W "${commands} $(get_instances)" -- ${cur}) )
return 0
;;
reload)
local commands="-h --help"
COMPREPLY=( $(compgen -W "${commands} $(get_instances)" -- ${cur}) )
return 0
;;
scp)
local commands="-h --help"
COMPREPLY=( $(compgen -W "${commands}" -- ${cur}) )
return 0
;;
snapshot)
COMPREPLY=( $( compgen -W 'delete list ls remove save' -- "$cur" ) )
return 0
;;
suspend)
local commands="-h --help"
COMPREPLY=( $(compgen -W "${commands} $(get_instances)" -- ${cur}) )
return 0
;;
up)
local commands="--disable-provisioning --disable-shared-folders --gui -h --help --memsize --no-cache --no-nat --numvcpus"
COMPREPLY=( $(compgen -W "${commands} $(get_instances)" -- ${cur}) )
return 0
;;
*)
;;
esac
COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
}
get_instances () {
echo $(mech list | awk '(NR > 1) { printf("%s ", $1) }')
}
complete -F _mech mech
# vim: ft=bash sw=2 ts=2 et