-
Notifications
You must be signed in to change notification settings - Fork 16
/
smc-tools.autocomplete
140 lines (133 loc) · 4.78 KB
/
smc-tools.autocomplete
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
_smc()
{
local cur prev opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
opts="device linkgroup info stats ueid -a -d -dd -v"
opts_smcd="device linkgroup info stats ueid seid -a -d -v"
opts_short="device linkgroup"
opts_show="show link-show"
opts_show_smcd="show"
opts_stats="show reset"
opts_ueid="show add del flush"
opts_seid="show enable disable"
opts_type="smcd smcr"
opts_final="all netdev ibdev"
opts_final_smcd="all"
case "${prev}" in
-v)
if [ $1 = "smcr" ]; then
COMPREPLY=( $(compgen -W "${opts_short}" -- ${cur}))
fi
return 0
;;
-vv)
if [ $1 = "smcr" ]; then
COMPREPLY=( $(compgen -W "${opts_short}" -- ${cur}))
fi
return 0
;;
device)
if [ $1 = "smcr" ]; then
COMPREPLY=( $(compgen -W "${opts_show}" -- ${cur}))
else
COMPREPLY=( $(compgen -W "${opts_show_smcd}" -- ${cur}))
fi
return 0
;;
linkgroup)
if [ $1 = "smcr" ]; then
COMPREPLY=( $(compgen -W "${opts_show}" -- ${cur}) )
else
COMPREPLY=( $(compgen -W "${opts_show_smcd}" -- ${cur}) )
fi
return 0
;;
info)
COMPREPLY=( $(compgen -W "${opts_show_smcd}" -- ${cur}) )
return 0
;;
show)
if [ $1 = "smcr" ]; then
COMPREPLY=( $(compgen -W "${opts_final}" -- ${cur}) )
else
COMPREPLY=( $(compgen -W "${opts_final_smcd}" -- ${cur}) )
fi
return 0
;;
link-show)
COMPREPLY=( $(compgen -W "${opts_final}" -- ${cur}) )
return 0
;;
smcd)
COMPREPLY=( $(compgen -W "${opts_smcd}" -- ${cur}) )
return 0
;;
smcr)
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
;;
stats)
COMPREPLY=( $(compgen -W "${opts_stats}" -- ${cur}) )
return 0
;;
ueid)
COMPREPLY=( $(compgen -W "${opts_ueid}" -- ${cur}) )
return 0
;;
seid)
COMPREPLY=( $(compgen -W "${opts_seid}" -- ${cur}) )
return 0
;;
*)
;;
esac
}
function _smc_pnet_complete_() {
case "${COMP_WORDS[COMP_CWORD-1]}" in
--interface*|-I*)
COMPREPLY=($(compgen -W "$(ls -1 /sys/class/net/)" -- "${COMP_WORDS[COMP_CWORD]}"))
return;;
--ibdevice*|-D*)
which smc_rnics >/dev/null
if [ $? -eq 0 ]; then
COMPREPLY=($(compgen -W "$(smc_rnics | tail -n +3 | awk '{print($3)}' | uniq)" -- "${COMP_WORDS[COMP_CWORD]}"))
else
COMPREPLY=($(compgen -W "$(ls -1 /sys/bus/pci/devices)" -- "${COMP_WORDS[COMP_CWORD]}"))
fi
return;;
--ibport*|-P*)
;;
esac
COMPREPLY=($(compgen -W "--help --version --add --delete --show --flush --interface --ibdevice --ibport" -- "${COMP_WORDS[COMP_CWORD]}"))
}
function _smc_rnics_complete_() {
case "${COMP_WORDS[COMP_CWORD-1]}" in
--enable|-e)
COMPREPLY=($(compgen -W "$(smc_rnics | grep -e "^ [[:space:]0-9a-f]\{2\} 0" | awk '{print($1)}')" -- "${COMP_WORDS[COMP_CWORD]}"))
return;;
--disable|-d)
COMPREPLY=($(compgen -W "$(smc_rnics | grep -e "^ [[:space:]0-9a-f]\{2\} 1" | awk '{print($1)}')" -- "${COMP_WORDS[COMP_CWORD]}"))
return;;
esac
COMPREPLY=($(compgen -W "--help --version --disable --enable --rawids" -- "${COMP_WORDS[COMP_CWORD]}"))
}
function _smc_chk_complete_() {
case "${COMP_WORDS[COMP_CWORD-1]}" in
--pnetid|-i)
COMPREPLY=($(compgen -W "$(ip link show | grep -e "^[0-9]\+:" | awk '{print($2)}' | sed s'/:$//') $(ip link show up | grep -e "^\s*altname" | awk '{print($2)}')" -- "${COMP_WORDS[COMP_CWORD]}"))
return;;
--connect|-C|--port|-p)
COMPREPLY=()
return;;
esac
COMPREPLY=($(compgen -W "$(ip link show up | grep -e "^[0-9]\+:" | awk '{print($2)}' | sed s'/:$//') $(ip link show up | grep -e "^\s*altname" | awk '{print($2)}') --connect --help --version --debug --pnetid --port --server --static-analysis --live-test --ipv6" -- "${COMP_WORDS[COMP_CWORD]}"))
}
complete -W "--help --tgz --version" smc_dbg
complete -W "--help --version --all --listening --debug --wide --smcd --smcr" smcss
complete -F _smc smcd
complete -F _smc smcr
complete -F _smc_pnet_complete_ smc_pnet
complete -F _smc_rnics_complete_ smc_rnics
complete -F _smc_chk_complete_ smc_chk