Skip to content

Commit 58b7009

Browse files
authored
Merge pull request #61 from rical/master
tipc: fix some minor errors
2 parents 54ca5fe + 502b718 commit 58b7009

File tree

1 file changed

+42
-64
lines changed

1 file changed

+42
-64
lines changed

completions/tipc

Lines changed: 42 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ _tipc_bearer() {
4040
elif [[ $cword -eq $optind+3 ]]; then
4141
case "$media" in
4242
"udp")
43-
local names=$(tipc bearer list | awk -F: '/^udp:/ {print $2}')
43+
local names=$(tipc bearer list 2>/dev/null | awk -F: '/^udp:/ {print $2}')
4444
COMPREPLY=( $( compgen -W '$names' -- $cur) )
4545
;;
4646
"eth")
@@ -63,7 +63,8 @@ _tipc_link() {
6363
COMPREPLY=( $( compgen -W 'link' -- $cur) )
6464
elif [[ $cword -eq $optind+1 ]]; then
6565
# awk drops link state and last trailing :
66-
local links=$(tipc link list | awk '{print substr($1, 0, length($1)-1)}')
66+
local links=$(tipc link list 2>/dev/null | \
67+
awk '{print substr($1, 0, length($1))}')
6768
if [[ $filter == "peers" ]]; then
6869
links=$(command sed '/broadcast-link/d' <<<"$links")
6970
fi
@@ -87,10 +88,20 @@ _tipc()
8788
;;
8889
esac
8990

91+
if [[ $cword -eq 1 ]]; then
92+
COMPREPLY=( $( compgen -W 'bearer link media nametable node socket' -- $cur ) )
93+
return
94+
fi
95+
9096
case "${words[$optind]}" in
9197
bearer)
9298
let optind++
9399

100+
if [[ $cword -eq $optind ]]; then
101+
COMPREPLY=( $( compgen -W 'enable disable set get list' -- $cur ) )
102+
return
103+
fi
104+
94105
case "${words[$optind]}" in
95106
enable)
96107
local media params
@@ -138,13 +149,11 @@ _tipc()
138149
done
139150

140151
COMPREPLY=( $( compgen -W '${params[@]}' -- $cur) )
141-
return
142152
;;
143153
disable)
144154
let optind++
145155

146156
_tipc_bearer $optind
147-
return
148157
;;
149158
get)
150159
let optind++
@@ -154,7 +163,6 @@ _tipc()
154163
elif [[ $cword -ge $optind+1 ]]; then
155164
_tipc_bearer $(($optind + 1))
156165
fi
157-
return
158166
;;
159167
set)
160168
let optind++
@@ -164,19 +172,17 @@ _tipc()
164172
elif [[ $cword -ge $optind+2 ]]; then
165173
_tipc_bearer $(($optind + 2))
166174
fi
167-
return
168-
;;
169-
list)
170-
return
171175
;;
172176
esac
173-
174-
COMPREPLY=( $( compgen -W 'enable disable set get list' -- $cur ) )
175-
return
176177
;;
177178
link)
178179
let optind++
179180

181+
if [[ $cword -eq $optind ]]; then
182+
COMPREPLY=( $( compgen -W 'get set list statistics' -- $cur ) )
183+
return
184+
fi
185+
180186
case "${words[$optind]}" in
181187
get)
182188
let optind++
@@ -186,7 +192,6 @@ _tipc()
186192
elif [[ $cword -ge $optind+1 ]]; then
187193
_tipc_link $(($optind + 1)) "peers"
188194
fi
189-
return
190195
;;
191196
set)
192197
let optind++
@@ -196,32 +201,31 @@ _tipc()
196201
elif [[ $cword -ge $optind+2 ]]; then
197202
_tipc_link $(($optind + 2)) "peers"
198203
fi
199-
return
200-
;;
201-
list)
202-
return
203204
;;
204205
statistics)
205206
let optind++
206207

208+
if [[ $cword -eq $optind ]]; then
209+
COMPREPLY=( $( compgen -W 'show reset' -- $cur) )
210+
return
211+
fi
212+
207213
case "${words[$optind]}" in
208214
show|reset)
209215
_tipc_link $(($optind + 1))
210-
return
211216
;;
212217
esac
213-
214-
COMPREPLY=( $( compgen -W 'show reset' -- $cur) )
215-
return
216218
;;
217219
esac
218-
219-
COMPREPLY=( $( compgen -W 'get set list statistics' -- $cur ) )
220-
return
221220
;;
222221
media)
223222
let optind++
224223

224+
if [[ $cword -eq $optind ]]; then
225+
COMPREPLY=( $( compgen -W 'get set list' -- $cur ) )
226+
return
227+
fi
228+
225229
case "${words[$optind]}" in
226230
get)
227231
let optind++
@@ -231,7 +235,6 @@ _tipc()
231235
elif [[ $cword -ge $optind+1 ]]; then
232236
_tipc_media $(($optind + 1))
233237
fi
234-
return
235238
;;
236239
set)
237240
let optind++
@@ -241,66 +244,41 @@ _tipc()
241244
elif [[ $cword -ge $optind+2 ]]; then
242245
_tipc_media $(($optind + 2))
243246
fi
244-
return
245-
;;
246-
list)
247-
return
248247
;;
249248
esac
250-
251-
COMPREPLY=( $( compgen -W 'get set list' -- $cur ) )
252-
return
253249
;;
254250
nametable)
255251
let optind++
256252

257-
case "${words[$optind]}" in
258-
show)
259-
return
260-
;;
261-
esac
262-
263-
COMPREPLY=( $( compgen -W 'show' -- $cur ) )
264-
return
253+
if [[ $cword -eq $optind ]]; then
254+
COMPREPLY=( $( compgen -W 'show' -- $cur ) )
255+
fi
265256
;;
266257
node)
267258
let optind++
268259

260+
if [[ $cword -eq $optind ]]; then
261+
COMPREPLY=( $( compgen -W 'list get set' -- $cur ) )
262+
return
263+
fi
264+
269265
case "${words[$optind]}" in
270266
get|set)
271267
let optind++
272268

273-
case "${words[$optind]}" in
274-
address|netid)
275-
return
276-
;;
277-
esac
278-
COMPREPLY=( $( compgen -W 'address netid' -- $cur ) )
279-
return
280-
;;
281-
list)
282-
return
283-
;;
269+
if [[ $cword -eq $optind ]]; then
270+
COMPREPLY=( $( compgen -W 'address netid' -- $cur ) )
271+
fi
284272
esac
285-
286-
COMPREPLY=( $( compgen -W 'list get set' -- $cur ) )
287-
return
288273
;;
289274
socket)
290275
let optind++
291276

292-
case "${words[$optind]}" in
293-
list)
294-
return
295-
;;
296-
esac
297-
298-
COMPREPLY=( $( compgen -W 'list' -- $cur ) )
299-
return
277+
if [[ $cword -eq $optind ]]; then
278+
COMPREPLY=( $( compgen -W 'list' -- $cur ) )
279+
fi
300280
;;
301281
esac
302-
303-
COMPREPLY=( $( compgen -W 'bearer link media nametable node socket' -- $cur ) )
304282
}
305283
complete -F _tipc tipc
306284

0 commit comments

Comments
 (0)