-
Notifications
You must be signed in to change notification settings - Fork 9
/
qeneth-complete.sh
61 lines (51 loc) · 1.31 KB
/
qeneth-complete.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
_nodes()
{
local nodes
[ -f topology.dot ] || return
gvpr -V 2>/dev/null || return
gvpr 'N [$.qn_console] { print($.name); }' topology.dot
}
_links() {
[ -f topology.dot ] || return
gvpr -V 2>/dev/null || return
gvpr '
N [$.name == "'"$1"'"] {
edge_t e;
for (e = fstedge($); e; e = nxtedge(e, $)) {
if (e.head == $)
printf("%s ", e.headport);
else
printf("%s ", e.tailport);
}
printf("\n");
}
' topology.dot
}
_qeneth()
{
local cur prev command module i
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
prev="${COMP_WORDS[COMP_CWORD-1]}"
if [[ $COMP_CWORD -eq 1 ]] ; then
COMPREPLY=($(compgen -W "generate status web \
start stop restart console monitor link help" -- $cur))
else
command=${COMP_WORDS[1]}
case $command in
link)
if [ "$COMP_CWORD" -eq 2 ]; then
COMPREPLY=($(compgen -W "$(_nodes)" -- $cur))
elif [ "$COMP_CWORD" -eq 3 ]; then
COMPREPLY=($(compgen -W "$(_links "$prev")" -- "$cur"))
elif [ "$COMP_CWORD" -eq 4 ]; then
COMPREPLY=($(compgen -W "on off" -- "$cur"))
fi
;;
start|stop|restart|console|monitor)
COMPREPLY=($(compgen -W "$(_nodes)" -- $cur))
;;
esac
fi
}
complete -F _qeneth qeneth