Add a basic command line completion for IPFS
Does auto-complete for the ipfs commands, subcommands and parameters. Reported to works for bash and zfs The completion could be smarter for some parameters (marked as #TODO)
Michael Muré committed
Mar 25, 2015 at 22:14 UTC
a1ac0b55c06100032a092b2aa421e62df8df2f49
1 file changed
+345
misc/completion/ipfs-completion.bash
new
+345
@@ -0,0 +1,345 @@
1
+_ipfs_comp()
2
+{
3
+ COMPREPLY=( $(compgen -W "$1" -- ${word}) )
4
+}
5
+
6
+_ipfs_help_only()
7
+{
8
+ _ipfs_comp "--help"
9
+}
10
+
11
+_ipfs_add()
12
+{
13
+ _ipfs_comp "-recursive -quiet -progress -wrap-with-directory \
14
+ -trickle --help"
15
+}
16
+
17
+_ipfs_block()
18
+{
19
+ _ipfs_comp "get put stat --help"
20
+}
21
+
22
+_ipfs_block_get()
23
+{
24
+ _ipfs_help_only
25
+}
26
+
27
+_ipfs_block_put()
28
+{
29
+ _ipfs_help_only
30
+}
31
+
32
+_ipfs_block_stat()
33
+{
34
+ _ipfs_help_only
35
+}
36
+
37
+_ipfs_bootstrap()
38
+{
39
+ _ipfs_comp "add list rm --help"
40
+}
41
+
42
+_ipfs_bootstrap_add()
43
+{
44
+ _ipfs_comp "-default --help"
45
+}
46
+
47
+_ipfs_bootstrap_list()
48
+{
49
+ _ipfs_help_only
50
+}
51
+
52
+_ipfs_bootstrap_rm()
53
+{
54
+ _ipfs_comp "-all --help"
55
+}
56
+
57
+_ipfs_cat()
58
+{
59
+ _ipfs_help_only
60
+}
61
+
62
+_ipfs_commands()
63
+{
64
+ _ipfs_help_only
65
+}
66
+
67
+_ipfs_config()
68
+{
69
+ # TODO: auto-complete existing config keys
70
+ _ipfs_comp "edit replace show -bool --help"
71
+}
72
+
73
+_ipfs_config_edit()
74
+{
75
+ _ipfs_help_only
76
+}
77
+
78
+_ipfs_config_replace()
79
+{
80
+ # TODO: auto-complete with a filename
81
+ _ipfs_help_only
82
+}
83
+
84
+_ipfs_config_show()
85
+{
86
+ _ipfs_help_only
87
+}
88
+
89
+_ipfs_daemon()
90
+{
91
+ _ipfs_comp "-init -routing= -mount -writable -mount-ipfs= \
92
+ -mount-ipns= --help"
93
+}
94
+
95
+_ipfs_dht()
96
+{
97
+ _ipfs_comp "findpeer findprovs query --help"
98
+}
99
+
100
+_ipfs_dht_findpeer()
101
+{
102
+ _ipfs_help_only
103
+}
104
+
105
+_ipfs_dht_findprovs()
106
+{
107
+ _ipfs_comp "-verbose --help"
108
+}
109
+
110
+_ipfs_dht_query()
111
+{
112
+ _ipfs_comp "-verbose --help"
113
+}
114
+
115
+_ipfs_diag()
116
+{
117
+ _ipfs_comp "net --help"
118
+}
119
+
120
+_ipfs_diag_net()
121
+{
122
+ # TODO: auto-complete -vis=*
123
+ _ipfs_comp "-timeout= -vis= --help"
124
+}
125
+
126
+_ipfs_get()
127
+{
128
+ _ipfs_comp "-output= -archive -compress -compression-level= --help"
129
+}
130
+
131
+_ipfs_id()
132
+{
133
+ _ipfs_comp "-format= --help"
134
+}
135
+
136
+_ipfs_init()
137
+{
138
+ _ipfs_comp "-bits= -passphrase= -force --help"
139
+}
140
+
141
+_ipfs_log()
142
+{
143
+ _ipfs_comp "tail level --help"
144
+}
145
+
146
+_ipfs_log_level()
147
+{
148
+ # TODO: auto-complete subsystem and level
149
+ _ipfs_comp "--help"
150
+}
151
+
152
+_ipfs_log_tail()
153
+{
154
+ _ipfs_comp "tail level --help"
155
+}
156
+
157
+_ipfs_ls()
158
+{
159
+ _ipfs_help_only
160
+}
161
+
162
+_ipfs_mount()
163
+{
164
+ _ipfs_comp "-f= -n= --help"
165
+}
166
+
167
+_ipfs_name()
168
+{
169
+ _ipfs_comp "publish resolve --help"
170
+}
171
+
172
+_ipfs_name_publish()
173
+{
174
+ _ipfs_help_only
175
+}
176
+
177
+_ipfs_name_resolve()
178
+{
179
+ _ipfs_help_only
180
+}
181
+
182
+_ipfs_object()
183
+{
184
+ _ipfs_comp "data get links put stat --help"
185
+}
186
+
187
+_ipfs_object_data()
188
+{
189
+ _ipfs_help_only
190
+}
191
+
192
+_ipfs_object_get()
193
+{
194
+ # TODO: auto-complete encoding
195
+ _ipfs_comp "--encoding="
196
+}
197
+
198
+_ipfs_object_links()
199
+{
200
+ _ipfs_help_only
201
+}
202
+
203
+_ipfs_object_put()
204
+{
205
+ _ipfs_help_only
206
+}
207
+
208
+_ipfs_object_stat()
209
+{
210
+ _ipfs_help_only
211
+}
212
+
213
+_ipfs_pin()
214
+{
215
+ _ipfs_comp "rm ls add --help"
216
+}
217
+
218
+_ipfs_pin_add()
219
+{
220
+ _ipfs_comp "-recursive --help"
221
+}
222
+
223
+_ipfs_pin_ls()
224
+{
225
+ # TODO: auto-complete -type=*
226
+ _ipfs_comp "-type= --help"
227
+}
228
+
229
+_ipfs_pin_rm()
230
+{
231
+ _ipfs_comp "-recursive --help"
232
+}
233
+
234
+_ipfs_ping()
235
+{
236
+ _ipfs_comp "-count= --help"
237
+}
238
+
239
+_ipfs_refs()
240
+{
241
+ _ipfs_comp "local -format= -edges -unique -recursive --help"
242
+}
243
+
244
+_ipfs_refs_local()
245
+{
246
+ _ipfs_help_only
247
+}
248
+
249
+_ipfs_repo()
250
+{
251
+ _ipfs_comp "gc --help"
252
+}
253
+
254
+_ipfs_repo_gc()
255
+{
256
+ _ipfs_comp "-quiet --help"
257
+}
258
+
259
+_ipfs_swarm()
260
+{
261
+ _ipfs_comp "addrs connect disconnect peers --help"
262
+}
263
+
264
+_ipfs_swarm_addrs()
265
+{
266
+ _ipfs_help_only
267
+}
268
+
269
+_ipfs_swarm_connect()
270
+{
271
+ _ipfs_help_only
272
+}
273
+
274
+_ipfs_swarm_disconnect()
275
+{
276
+ _ipfs_help_only
277
+}
278
+
279
+_ipfs_swarm_peers()
280
+{
281
+ _ipfs_help_only
282
+}
283
+
284
+_ipfs_tour()
285
+{
286
+ _ipfs_comp "list next restart --help"
287
+}
288
+
289
+_ipfs_tour_list()
290
+{
291
+ _ipfs_help_only
292
+}
293
+
294
+_ipfs_tour_next()
295
+{
296
+ _ipfs_help_only
297
+}
298
+
299
+_ipfs_tour_restart()
300
+{
301
+ _ipfs_help_only
302
+}
303
+
304
+_ipfs_update()
305
+{
306
+ _ipfs_comp "check log --help"
307
+}
308
+
309
+_ipfs_update_check()
310
+{
311
+ _ipfs_help_only
312
+}
313
+
314
+_ipfs_update_log()
315
+{
316
+ _ipfs_help_only
317
+}
318
+
319
+_ipfs_version()
320
+{
321
+ _ipfs_comp "-number --help"
322
+}
323
+
324
+_ipfs()
325
+{
326
+ COMPREPLY=()
327
+ local word="${COMP_WORDS[COMP_CWORD]}"
328
+
329
+ case "${COMP_CWORD}" in
330
+ 1)
331
+ local opts="add block bootstrap cat commands config daemon dht diag id \
332
+ init log ls mount name object pin ping refs repo swarm tour \
333
+ update version"
334
+ COMPREPLY=( $(compgen -W "${opts}" -- ${word}) );;
335
+ 2)
336
+ local command="${COMP_WORDS[1]}"
337
+ eval "_ipfs_$command" 2> /dev/null ;;
338
+ *)
339
+ local command="${COMP_WORDS[1]}"
340
+ local subcommand="${COMP_WORDS[2]}"
341
+ eval "_ipfs_${command}_${subcommand}" 2> /dev/null && return
342
+ eval "_ipfs_$command" 2> /dev/null ;;
343
+ esac
344
+}
345
+complete -F _ipfs ipfs