Skip to content

Commit 1e778fc

Browse files
author
Richard Alpe
committed
tipc: handle complete words without trailing space
Prior to this commit, $ tipc socke<TAB> $ tipc socket <TAB> Both produced "tipc socket " while While $ tipc socket<TAB> didn't produce anything. This was true for almost all commands and was a result of the recipe design. The mechanism that hinder repetition didn't handle complete words without a trailing space. In this patch we fix this, so that pressing tab after a completed valid subcommand inserts a space. Fixes #60
1 parent 83f78d2 commit 1e778fc

File tree

1 file changed

+39
-62
lines changed

1 file changed

+39
-62
lines changed

completions/tipc

Lines changed: 39 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,20 @@ _tipc()
8888
;;
8989
esac
9090

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

100+
if [[ $cword -eq $optind ]]; then
101+
COMPREPLY=( $( compgen -W 'enable disable set get list' -- $cur ) )
102+
return
103+
fi
104+
95105
case "${words[$optind]}" in
96106
enable)
97107
local media params
@@ -139,13 +149,11 @@ _tipc()
139149
done
140150

141151
COMPREPLY=( $( compgen -W '${params[@]}' -- $cur) )
142-
return
143152
;;
144153
disable)
145154
let optind++
146155

147156
_tipc_bearer $optind
148-
return
149157
;;
150158
get)
151159
let optind++
@@ -155,7 +163,6 @@ _tipc()
155163
elif [[ $cword -ge $optind+1 ]]; then
156164
_tipc_bearer $(($optind + 1))
157165
fi
158-
return
159166
;;
160167
set)
161168
let optind++
@@ -165,19 +172,17 @@ _tipc()
165172
elif [[ $cword -ge $optind+2 ]]; then
166173
_tipc_bearer $(($optind + 2))
167174
fi
168-
return
169-
;;
170-
list)
171-
return
172175
;;
173176
esac
174-
175-
COMPREPLY=( $( compgen -W 'enable disable set get list' -- $cur ) )
176-
return
177177
;;
178178
link)
179179
let optind++
180180

181+
if [[ $cword -eq $optind ]]; then
182+
COMPREPLY=( $( compgen -W 'get set list statistics' -- $cur ) )
183+
return
184+
fi
185+
181186
case "${words[$optind]}" in
182187
get)
183188
let optind++
@@ -187,7 +192,6 @@ _tipc()
187192
elif [[ $cword -ge $optind+1 ]]; then
188193
_tipc_link $(($optind + 1)) "peers"
189194
fi
190-
return
191195
;;
192196
set)
193197
let optind++
@@ -197,32 +201,31 @@ _tipc()
197201
elif [[ $cword -ge $optind+2 ]]; then
198202
_tipc_link $(($optind + 2)) "peers"
199203
fi
200-
return
201-
;;
202-
list)
203-
return
204204
;;
205205
statistics)
206206
let optind++
207207

208+
if [[ $cword -eq $optind ]]; then
209+
COMPREPLY=( $( compgen -W 'show reset' -- $cur) )
210+
return
211+
fi
212+
208213
case "${words[$optind]}" in
209214
show|reset)
210215
_tipc_link $(($optind + 1))
211-
return
212216
;;
213217
esac
214-
215-
COMPREPLY=( $( compgen -W 'show reset' -- $cur) )
216-
return
217218
;;
218219
esac
219-
220-
COMPREPLY=( $( compgen -W 'get set list statistics' -- $cur ) )
221-
return
222220
;;
223221
media)
224222
let optind++
225223

224+
if [[ $cword -eq $optind ]]; then
225+
COMPREPLY=( $( compgen -W 'get set list' -- $cur ) )
226+
return
227+
fi
228+
226229
case "${words[$optind]}" in
227230
get)
228231
let optind++
@@ -232,7 +235,6 @@ _tipc()
232235
elif [[ $cword -ge $optind+1 ]]; then
233236
_tipc_media $(($optind + 1))
234237
fi
235-
return
236238
;;
237239
set)
238240
let optind++
@@ -242,66 +244,41 @@ _tipc()
242244
elif [[ $cword -ge $optind+2 ]]; then
243245
_tipc_media $(($optind + 2))
244246
fi
245-
return
246-
;;
247-
list)
248-
return
249247
;;
250248
esac
251-
252-
COMPREPLY=( $( compgen -W 'get set list' -- $cur ) )
253-
return
254249
;;
255250
nametable)
256251
let optind++
257252

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

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

274-
case "${words[$optind]}" in
275-
address|netid)
276-
return
277-
;;
278-
esac
279-
COMPREPLY=( $( compgen -W 'address netid' -- $cur ) )
280-
return
281-
;;
282-
list)
283-
return
284-
;;
269+
if [[ $cword -eq $optind ]]; then
270+
COMPREPLY=( $( compgen -W 'address netid' -- $cur ) )
271+
fi
285272
esac
286-
287-
COMPREPLY=( $( compgen -W 'list get set' -- $cur ) )
288-
return
289273
;;
290274
socket)
291275
let optind++
292276

293-
case "${words[$optind]}" in
294-
list)
295-
return
296-
;;
297-
esac
298-
299-
COMPREPLY=( $( compgen -W 'list' -- $cur ) )
300-
return
277+
if [[ $cword -eq $optind ]]; then
278+
COMPREPLY=( $( compgen -W 'list' -- $cur ) )
279+
fi
301280
;;
302281
esac
303-
304-
COMPREPLY=( $( compgen -W 'bearer link media nametable node socket' -- $cur ) )
305282
}
306283
complete -F _tipc tipc
307284

0 commit comments

Comments
 (0)