Updated Bash complete script
Some minor bug still exist but not breaking. Everything is marked with "TODO" inline the script. License: MIT Signed-off-by: Elias Gabrielsson <elias@benefactory.se>
Elias Gabrielsson committed
Nov 13, 2016 at 16:31 UTC
e9594c9b2374a1ee48675533c1b295a847f58529
1 file changed
+607
-59
misc/completion/ipfs-completion.bash
+607
-59
@@ -1,6 +1,10 @@
1
_ipfs_comp()
2
{
3
COMPREPLY=( $(compgen -W "$1" -- ${word}) )
4
+ if [[ ${#COMPREPLY[@]} == 1 && ${COMPREPLY[0]} == "--"*"=" ]] ; then
5
+ # If there's only one option, with =, then discard space
6
+ compopt -o nospace
7
+ fi
8
}
9
10
_ipfs_help_only()
@@ -10,13 +14,25 @@ _ipfs_help_only()
14
15
_ipfs_add()
16
{
13
- _ipfs_comp "--recursive --quiet --progress --trickle --only-hash
14
- --wrap-with-directory --hidden --help"
17
+ if [[ "${prev}" == "--chunker" ]] ; then
18
+ _ipfs_comp "placeholder1 placeholder2 placeholder3" # TODO: a) Give real options, b) Solve autocomplete bug for "="
19
+ elif [ "${prev}" == "--pin" ] ; then
20
+ _ipfs_comp "true false"
21
+ elif [[ ${word} == -* ]] ; then
22
+ _ipfs_comp "--recursive --quiet --silent --progress --trickle --only-hash --wrap-with-directory --hidden --chunker= --pin= --raw-leaves --help "
23
+ else
24
+ _ipfs_filesystem_complete
25
+ fi
26
}
27
28
_ipfs_bitswap()
29
{
19
- ipfs_comp "stat wantlist --help"
30
+ ipfs_comp "ledger stat unwant wantlist --help"
31
+}
32
+
33
+_ipfs_bitswap_ledger()
34
+{
35
+ _ipfs_help_only
36
}
37
38
_ipfs_bitswap_stat()
@@ -24,29 +40,54 @@ _ipfs_bitswap_stat()
40
_ipfs_help_only
41
}
42
43
+_ipfs_bitswap_unwant()
44
+{
45
+ _ipfs_help_only
46
+}
47
+
48
_ipfs_bitswap_wantlist()
49
{
50
ipfs_comp "--peer= --help"
51
}
52
53
+_ipfs_bitswap_unwant()
54
+{
55
+ _ipfs_help_only
56
+}
57
+
58
_ipfs_block()
59
{
34
- _ipfs_comp "get put stat --help"
60
+ _ipfs_comp "get put rm stat --help"
61
}
62
63
_ipfs_block_get()
64
{
39
- _ipfs_help_only
65
+ _ipfs_hash_complete
66
}
67
68
_ipfs_block_put()
69
{
44
- _ipfs_help_only
70
+ if [ "${prev}" == "--format" ] ; then
71
+ _ipfs_comp "v0 placeholder2 placeholder3" # TODO: a) Give real options, b) Solve autocomplete bug for "="
72
+ elif [[ ${word} == -* ]] ; then
73
+ _ipfs_comp "--format= --help"
74
+ else
75
+ _ipfs_filesystem_complete
76
+ fi
77
+}
78
+
79
+_ipfs_block_rm()
80
+{
81
+ if [[ ${word} == -* ]] ; then
82
+ _ipfs_comp "--force --quiet --help"
83
+ else
84
+ _ipfs_hash_complete
85
+ fi
86
}
87
88
_ipfs_block_stat()
89
{
49
- _ipfs_help_only
90
+ _ipfs_hash_complete
91
}
92
93
_ipfs_bootstrap()
@@ -56,7 +97,7 @@ _ipfs_bootstrap()
97
98
_ipfs_bootstrap_add()
99
{
59
- _ipfs_comp "--default --help"
100
+ _ipfs_comp "default --help"
101
}
102
103
_ipfs_bootstrap_list()
@@ -66,23 +107,34 @@ _ipfs_bootstrap_list()
107
108
_ipfs_bootstrap_rm()
109
{
69
- _ipfs_comp "--all --help"
110
+ _ipfs_comp "all --help"
111
}
112
113
_ipfs_cat()
114
{
74
- _ipfs_help_only
115
+ if [[ ${prev} == */* ]] ; then
116
+ COMPREPLY=() # Only one argument allowed
117
+ elif [[ ${word} == */* ]] ; then
118
+ _ipfs_hash_complete
119
+ else
120
+ _ipfs_pinned_complete
121
+ fi
122
}
123
124
_ipfs_commands()
125
{
79
- _ipfs_help_only
126
+ _ipfs_comp "--flags --help"
127
}
128
129
_ipfs_config()
130
{
84
- # TODO: auto-complete existing config keys
85
- _ipfs_comp "edit replace show --bool --json --help"
131
+ if [[ ${word} == -* ]] ; then
132
+ _ipfs_comp "--bool --json"
133
+ elif [[ ${prev} == *.* ]] ; then
134
+ COMPREPLY=() # Only one subheader of the config can be shown or edited.
135
+ else
136
+ _ipfs_comp "show edit replace"
137
+ fi
138
}
139
140
_ipfs_config_edit()
@@ -92,8 +144,11 @@ _ipfs_config_edit()
144
145
_ipfs_config_replace()
146
{
95
- # TODO: auto-complete with a filename
96
- _ipfs_help_only
147
+ if [[ ${word} == -* ]] ; then
148
+ _ipfs_comp "--help"
149
+ else
150
+ _ipfs_filesystem_complete
151
+ fi
152
}
153
154
_ipfs_config_show()
@@ -103,19 +158,48 @@ _ipfs_config_show()
158
159
_ipfs_daemon()
160
{
106
- _ipfs_comp "--init --routing= --mount --writable --mount-ipfs= \
107
- --mount-ipns= --unrestricted-api --disable-transport-encryption \
108
- --help"
161
+ if [[ ${prev} == "--routing" ]] ; then
162
+ _ipfs_comp "dht supernode" # TODO: Solve autocomplete bug for "="
163
+ elif [[ ${prev} == "--mount-ipfs" ]] || [[ ${prev} == "--mount-ipns" ]] || [[ ${prev} == "=" ]]; then
164
+ _ipfs_filesystem_complete
165
+ elif [[ ${word} == -* ]] ; then
166
+ _ipfs_comp "--init --routing= --mount --writable --mount-ipfs= \
167
+ --mount-ipns= --unrestricted-api --disable-transport-encryption \
168
+ -- enable-gc --manage-fdlimit --offline --migrate --help"
169
+ fi
170
+}
171
+
172
+_ipfs_dag()
173
+{
174
+ _ipfs_comp "get put --help"
175
+}
176
+
177
+_ipfs_dag_get()
178
+{
179
+ _ipfs_help_only
180
+}
181
+
182
+_ipfs_dag_put()
183
+{
184
+ if [[ ${prev} == "--format" ]] ; then
185
+ _ipfs_comp "cbor placeholder1" # TODO: a) Which format more then cbor is valid? b) Solve autocomplete bug for "="
186
+ elif [[ ${prev} == "--input-enc" ]] ; then
187
+ _ipfs_comp "json placeholder1" # TODO: a) Which format more then json is valid? b) Solve autocomplete bug for "="
188
+ elif [[ ${word} == -* ]] ; then
189
+ _ipfs_comp "--format= --input-enc= --help"
190
+ else
191
+ _ipfs_filesystem_complete
192
+ fi
193
}
194
195
_ipfs_dht()
196
{
113
- _ipfs_comp "findpeer findprovs get put query --help"
197
+ _ipfs_comp "findpeer findprovs get provide put query --help"
198
}
199
200
_ipfs_dht_findpeer()
201
{
118
- _ipfs_help_only
202
+ _ipfs_comp "--verbose --help"
203
}
204
205
_ipfs_dht_findprovs()
@@ -128,6 +212,11 @@ _ipfs_dht_get()
212
_ipfs_comp "--verbose --help"
213
}
214
215
+_ipfs_dht_provide()
216
+{
217
+ _ipfs_comp "--recursive --verbose --help"
218
+}
219
+
220
_ipfs_dht_put()
221
{
222
_ipfs_comp "--verbose --help"
@@ -140,23 +229,171 @@ _ipfs_dht_query()
229
230
_ipfs_diag()
231
{
143
- _ipfs_comp "net --help"
232
+ _ipfs_comp "sys cmds net --help"
233
+}
234
+
235
+_ipfs_diag_cmds()
236
+{
237
+ if [[ ${prev} == "clear" ]] ; then
238
+ return 0
239
+ elif [[ ${prev} =~ ^-?[0-9]+$ ]] ; then
240
+ _ipfs_comp "ns us µs ms s m h" # TODO: Trigger with out space, eg. "ipfs diag set-time 10ns" not "... set-time 10 ns"
241
+ elif [[ ${prev} == "set-time" ]] ; then
242
+ _ipfs_help_only
243
+ elif [[ ${word} == -* ]] ; then
244
+ _ipfs_comp "--verbose --help"
245
+ else
246
+ _ipfs_comp "clear set-time"
247
+ fi
248
+}
249
+
250
+_ipfs_diag_sys()
251
+{
252
+ _ipfs_help_only
253
}
254
255
_ipfs_diag_net()
256
{
148
- # TODO: auto-complete -vis=*
149
- _ipfs_comp "--timeout= --vis= --help"
257
+ if [[ ${prev} == "--vis" ]] ; then
258
+ _ipfs_comp "d3 dot text" # TODO: Solve autocomplete bug for "="
259
+ elif [[ ${word} == -* ]] ; then
260
+ _ipfs_comp "--timeout= --vis= --help"
261
+ fi
262
}
263
264
_ipfs_dns()
265
{
154
- _ipfs_comp "--recursive --help"
266
+ if [[ ${word} == -* ]] ; then
267
+ _ipfs_comp "--recursive --help"
268
+ fi
269
+}
270
+
271
+_ipfs_files()
272
+{
273
+ _ipfs_comp "mv rm flush read write cp ls mkdir stat"
274
+}
275
+
276
+_ipfs_files_mv()
277
+{
278
+ if [[ ${word} == -* ]] ; then
279
+ _ipfs_comp "--recursive --flush"
280
+ elif [[ ${word} == /* ]] ; then
281
+ _ipfs_files_complete
282
+ else
283
+ COMPREPLY=( / )
284
+ [[ $COMPREPLY = */ ]] && compopt -o nospace
285
+ fi
286
+}
287
+
288
+_ipfs_files_rm()
289
+{
290
+ if [[ ${word} == -* ]] ; then
291
+ _ipfs_comp "--recursive --flush"
292
+ elif [[ ${word} == /* ]] ; then
293
+ _ipfs_files_complete
294
+ else
295
+ COMPREPLY=( / )
296
+ [[ $COMPREPLY = */ ]] && compopt -o nospace
297
+ fi
298
+}
299
+_ipfs_files_flush()
300
+{
301
+ if [[ ${word} == /* ]] ; then
302
+ _ipfs_files_complete
303
+ else
304
+ COMPREPLY=( / )
305
+ [[ $COMPREPLY = */ ]] && compopt -o nospace
306
+ fi
307
+}
308
+
309
+_ipfs_files_read()
310
+{
311
+ if [[ ${prev} == "--count" ]] || [[ ${prev} == "--offset" ]] ; then
312
+ COMPREPLY=() # Numbers, just keep it empty
313
+ elif [[ ${word} == -* ]] ; then
314
+ _ipfs_comp "--offset --count --help"
315
+ elif [[ ${word} == /* ]] ; then
316
+ _ipfs_files_complete
317
+ else
318
+ COMPREPLY=( / )
319
+ [[ $COMPREPLY = */ ]] && compopt -o nospace
320
+ fi
321
+}
322
+
323
+_ipfs_files_write()
324
+{
325
+ if [[ ${prev} == "--count" ]] || [[ ${prev} == "--offset" ]] ; then # Dirty check
326
+ COMPREPLY=() # Numbers, just keep it empty
327
+ elif [[ ${word} == -* ]] ; then
328
+ _ipfs_comp "--offset --count --create --truncate --help"
329
+ elif [[ ${prev} == /* ]] ; then
330
+ _ipfs_filesystem_complete
331
+ elif [[ ${word} == /* ]] ; then
332
+ _ipfs_files_complete
333
+ else
334
+ COMPREPLY=( / )
335
+ [[ $COMPREPLY = */ ]] && compopt -o nospace
336
+ fi
337
+}
338
+
339
+_ipfs_files_cp()
340
+{
341
+ if [[ ${word} == /* ]] ; then
342
+ _ipfs_files_complete
343
+ else
344
+ COMPREPLY=( / )
345
+ [[ $COMPREPLY = */ ]] && compopt -o nospace
346
+ fi
347
+}
348
+
349
+_ipfs_files_ls()
350
+{
351
+ if [[ ${word} == -* ]] ; then
352
+ _ipfs_comp "-l --help"
353
+ elif [[ ${prev} == /* ]] ; then
354
+ COMPREPLY=() # Path exist
355
+ elif [[ ${word} == /* ]] ; then
356
+ _ipfs_files_complete
357
+ else
358
+ COMPREPLY=( / )
359
+ [[ $COMPREPLY = */ ]] && compopt -o nospace
360
+ fi
361
+}
362
+
363
+_ipfs_files_mkdir()
364
+{
365
+ if [[ ${word} == -* ]] ; then
366
+ _ipfs_comp "--parents --help"
367
+
368
+ elif [[ ${prev} == /* ]] ; then
369
+ COMPREPLY=() # Path exist
370
+ elif [[ ${word} == /* ]] ; then
371
+ _ipfs_files_complete
372
+ else
373
+ COMPREPLY=( / )
374
+ [[ $COMPREPLY = */ ]] && compopt -o nospace
375
+ fi
376
+}
377
+
378
+_ipfs_files_stat()
379
+{
380
+ if [[ ${prev} == /* ]] ; then
381
+ COMPREPLY=() # Path exist
382
+ elif [[ ${word} == /* ]] ; then
383
+ _ipfs_files_complete
384
+ else
385
+ COMPREPLY=( / )
386
+ [[ $COMPREPLY = */ ]] && compopt -o nospace
387
+ fi
388
}
389
390
_ipfs_file()
391
{
159
- _ipfs_comp "ls --help"
392
+ if [[ ${prev} == "ls" ]] ; then
393
+ _ipfs_hash_complete
394
+ else
395
+ _ipfs_comp "ls --help"
396
+ fi
397
}
398
399
_ipfs_file_ls()
@@ -166,28 +403,44 @@ _ipfs_file_ls()
403
404
_ipfs_get()
405
{
169
- _ipfs_comp "--output= --archive --compress --compression-level= --help"
406
+ if [ "${prev}" == "--output" ] ; then
407
+ compopt -o default # Re-enable default file read
408
+ COMPREPLY=()
409
+ elif [ "${prev}" == "--compression-level" ] ; then
410
+ _ipfs_comp "-1 1 2 3 4 5 6 7 8 9" # TODO: Solve autocomplete bug for "="
411
+ elif [[ ${word} == -* ]] ; then
412
+ _ipfs_comp "--output= --archive --compress --compression-level= --help"
413
+ else
414
+ _ipfs_hash_complete
415
+ fi
416
}
417
418
_ipfs_id()
419
{
174
- _ipfs_comp "--format= --help"
420
+ if [[ ${word} == -* ]] ; then
421
+ _ipfs_comp "--format= --help"
422
+ fi
423
}
424
425
_ipfs_init()
426
{
179
- _ipfs_comp "--bits= --force --help"
427
+ _ipfs_comp "--bits --force --empty-repo --help"
428
}
429
430
_ipfs_log()
431
{
184
- _ipfs_comp "tail level --help"
432
+ _ipfs_comp "level ls tail --help"
433
}
434
435
_ipfs_log_level()
436
{
437
# TODO: auto-complete subsystem and level
190
- _ipfs_comp "--help"
438
+ _ipfs_help_only
439
+}
440
+
441
+_ipfs_log_ls()
442
+{
443
+ _ipfs_help_only
444
}
445
446
_ipfs_log_tail()
@@ -197,12 +450,20 @@ _ipfs_log_tail()
450
451
_ipfs_ls()
452
{
200
- _ipfs_comp "--headers --help"
453
+ if [[ ${word} == -* ]] ; then
454
+ _ipfs_comp "--headers --resolve-type=false --help"
455
+ else
456
+ _ipfs_hash_complete
457
+ fi
458
}
459
460
_ipfs_mount()
461
{
205
- _ipfs_comp "--ipfs-path= --ipns-path= --help"
462
+ if [[ ${prev} == "--ipfs-path" ]] || [[ ${prev} == "--ipns-path" ]] || [[ ${prev} == "=" ]] ; then
463
+ _ipfs_filesystem_complete
464
+ elif [[ ${word} == -* ]] ; then
465
+ _ipfs_comp "--ipfs-path= --ipns-path= --help"
466
+ fi
467
}
468
469
_ipfs_name()
@@ -212,53 +473,120 @@ _ipfs_name()
473
474
_ipfs_name_publish()
475
{
215
- _ipfs_help_only
476
+ if [[ ${prev} == "--lifetime" ]] || [[ ${prev} == "--ttl" ]] ; then
477
+ COMPREPLY=() # Accept only numbers
478
+ elif [[ ${prev} =~ ^-?[0-9]+$ ]] ; then
479
+ _ipfs_comp "ns us µs ms s m h" # TODO: Trigger without space, eg. "ipfs diag set-time 10ns" not "... set-time 10 ns"
480
+ elif [[ ${word} == -* ]] ; then
481
+ _ipfs_comp "--resolve --lifetime --ttl --help"
482
+ elif [[ ${word} == */ ]]; then
483
+ _ipfs_hash_complete
484
+ else
485
+ _ipfs_pinned_complete
486
+ fi
487
}
488
489
_ipfs_name_resolve()
490
{
220
- _ipfs_comp "--recursive --help"
491
+ if [[ ${word} == -* ]] ; then
492
+ _ipfs_comp "--recursive --nocache --help"
493
+ fi
494
}
495
496
_ipfs_object()
497
{
225
- _ipfs_comp "data get links new patch put stat --help"
498
+ _ipfs_comp "data diff get links new patch put stat --help"
499
}
500
501
_ipfs_object_data()
502
{
230
- _ipfs_help_only
503
+ _ipfs_hash_complete
504
+}
505
+
506
+_ipfs_object_diff()
507
+{
508
+ if [[ ${word} == -* ]] ; then
509
+ _ipfs_comp "--verbose --help"
510
+ else
511
+ _ipfs_hash_complete
512
+ fi
513
}
514
515
+
516
_ipfs_object_get()
517
{
235
- # TODO: auto-complete encoding
236
- _ipfs_comp "--encoding= --help"
518
+ if [ "${prev}" == "--encoding" ] ; then
519
+ _ipfs_comp "protobuf json xml"
520
+ elif [[ ${word} == -* ]] ; then
521
+ _ipfs_comp "--encoding --help"
522
+ else
523
+ _ipfs_hash_complete
524
+ fi
525
}
526
527
_ipfs_object_links()
528
{
241
- _ipfs_help_only
529
+ if [[ ${word} == -* ]] ; then
530
+ _ipfs_comp "--headers --help"
531
+ else
532
+ _ipfs_hash_complete
533
+ fi
534
}
535
536
_ipfs_object_new()
537
{
246
- _ipfs_help_only
538
+ if [[ ${word} == -* ]] ; then
539
+ _ipfs_comp "--help"
540
+ else
541
+ _ipfs_comp "unixfs-dir"
542
+ fi
543
}
544
545
_ipfs_object_patch()
546
{
251
- _ipfs_help_only
547
+ if [[ -n "${COMP_WORDS[3]}" ]] ; then # Root merkledag object exist
548
+ case "${COMP_WORDS[4]}" in
549
+ append-data)
550
+ _ipfs_help_only
551
+ ;;
552
+ add-link)
553
+ if [[ ${word} == -* ]] && [[ ${prev} == "add-link" ]] ; then # Dirty check
554
+ _ipfs_comp "--create"
555
+ #else
556
+ # TODO: Hash path autocomplete. This is tricky, can be hash or a name.
557
+ fi
558
+ ;;
559
+ rm-link)
560
+ _ipfs_hash_complete
561
+ ;;
562
+ set-data)
563
+ _ipfs_filesystem_complete
564
+ ;;
565
+ *)
566
+ _ipfs_comp "append-data add-link rm-link set-data"
567
+ ;;
568
+ esac
569
+ else
570
+ _ipfs_hash_complete
571
+ fi
572
}
573
574
_ipfs_object_put()
575
{
256
- _ipfs_comp "--inputenc= --help"
576
+ if [ "${prev}" == "--inputenc" ] ; then
577
+ _ipfs_comp "protobuf json"
578
+ elif [ "${prev}" == "--datafieldenc" ] ; then
579
+ _ipfs_comp "text base64"
580
+ elif [[ ${word} == -* ]] ; then
581
+ _ipfs_comp "--inputenc --datafieldenc --help"
582
+ else
583
+ _ipfs_hash_complete
584
+ fi
585
}
586
587
_ipfs_object_stat()
588
{
261
- _ipfs_help_only
589
+ _ipfs_hash_complete
590
}
591
592
_ipfs_pin()
@@ -268,18 +596,31 @@ _ipfs_pin()
596
597
_ipfs_pin_add()
598
{
271
- _ipfs_comp "--recursive --help"
599
+ if [[ ${word} == -* ]] ; then
600
+ _ipfs_comp "--recursive= --help"
601
+ elif [[ ${word} == */ ]] && [[ ${word} != "/ipfs/" ]] ; then
602
+ _ipfs_hash_complete
603
+ fi
604
}
605
606
_ipfs_pin_ls()
607
{
276
- # TODO: auto-complete -type=*
277
- _ipfs_comp "--count --quiet --type= --help"
608
+ if [[ ${prev} == "--type" ]] || [[ ${prev} == "-t" ]] ; then
609
+ _ipfs_comp "direct indirect recursive all" # TODO: Solve autocomplete bug for
610
+ elif [[ ${word} == -* ]] ; then
611
+ _ipfs_comp "--count --quiet --type= --help"
612
+ elif [[ ${word} == */ ]] && [[ ${word} != "/ipfs/" ]] ; then
613
+ _ipfs_hash_complete
614
+ fi
615
}
616
617
_ipfs_pin_rm()
618
{
282
- _ipfs_comp "--recursive --help"
619
+ if [[ ${word} == -* ]] ; then
620
+ _ipfs_comp "--recursive --help"
621
+ elif [[ ${word} == */ ]] && [[ ${word} != "/ipfs/" ]] ; then
622
+ COMPREPLY=() # TODO: _ipfs_hash_complete() + List local pinned hashes as default?
623
+ fi
624
}
625
626
_ipfs_ping()
@@ -287,9 +628,40 @@ _ipfs_ping()
628
_ipfs_comp "--count= --help"
629
}
630
631
+_ipfs_pubsub()
632
+{
633
+ _ipfs_comp "ls peers pub sub --help"
634
+}
635
+
636
+_ipfs_pubsub_ls()
637
+{
638
+ _ipfs_help_only
639
+}
640
+
641
+_ipfs_pubsub_peers()
642
+{
643
+ _ipfs_help_only
644
+}
645
+
646
+_ipfs_pubsub_pub()
647
+{
648
+ _ipfs_help_only
649
+}
650
+
651
+_ipfs_pubsub_sub()
652
+{
653
+ _ipfs_comp "--discover --help"
654
+}
655
+
656
_ipfs_refs()
657
{
292
- _ipfs_comp "local --format= --edges --unique --recursive --help"
658
+ if [ "${prev}" == "--format" ] ; then
659
+ _ipfs_comp "src dst linkname"
660
+ elif [[ ${word} == -* ]] ; then
661
+ _ipfs_comp "local --format= --edges --unique --recursive --help"
662
+ #else
663
+ # TODO: Use "ipfs ref" and combine it with autocomplete, see _ipfs_hash_complete
664
+ fi
665
}
666
667
_ipfs_refs_local()
@@ -299,7 +671,17 @@ _ipfs_refs_local()
671
672
_ipfs_repo()
673
{
302
- _ipfs_comp "gc --help"
674
+ _ipfs_comp "fsck gc stat verify version --help"
675
+}
676
+
677
+_ipfs_repo_version()
678
+{
679
+ _ipfs_comp "--quiet --help"
680
+}
681
+
682
+_ipfs_repo_verify()
683
+{
684
+ _ipfs_help_only
685
}
686
687
_ipfs_repo_gc()
@@ -307,9 +689,29 @@ _ipfs_repo_gc()
689
_ipfs_comp "--quiet --help"
690
}
691
692
+_ipfs_repo_stat()
693
+{
694
+ _ipfs_comp "--human --help"
695
+}
696
+
697
+_ipfs_repo_fsck()
698
+{
699
+ _ipfs_help_only
700
+}
701
+
702
_ipfs_resolve()
703
{
312
- _ipfs_comp "--recursive --help"
704
+ if [[ ${word} == /ipfs/* ]] ; then
705
+ _ipfs_hash_complete
706
+ elif [[ ${word} == /ipns/* ]] ; then
707
+ COMPREPLY=() # Can't autocomplete ipns
708
+ elif [[ ${word} == -* ]] ; then
709
+ _ipfs_comp "--recursive --help"
710
+ else
711
+ opts="/ipns/ /ipfs/"
712
+ COMPREPLY=( $(compgen -W "${opts}" -- ${word}) )
713
+ [[ $COMPREPLY = */ ]] && compopt -o nospace
714
+ fi
715
}
716
717
_ipfs_stats()
@@ -324,12 +726,13 @@ _ipfs_stats_bitswap()
726
727
_ipfs_stats_bw()
728
{
729
+ # TODO: Which protocol is valid?
730
_ipfs_comp "--peer= --proto= --poll --interval= --help"
731
}
732
733
_ipfs_stats_repo()
734
{
332
- _ipfs_comp "--human="
735
+ _ipfs_comp "--human= --help"
736
}
737
738
_ipfs_swarm()
@@ -349,17 +752,25 @@ _ipfs_swarm_addrs_local()
752
753
_ipfs_swarm_connect()
754
{
352
- _ipfs_help_only
755
+ _ipfs_multiaddr_complete
756
}
757
758
_ipfs_swarm_disconnect()
759
{
357
- _ipfs_help_only
760
+ local OLDIFS="$IFS" ; local IFS=$'\n' # Change divider for iterator one line below
761
+ opts=$(for x in `ipfs swarm peers`; do echo ${x} ; done)
762
+ IFS="$OLDIFS" # Reset divider to space, ' '
763
+ COMPREPLY=( $(compgen -W "${opts}" -- ${word}) )
764
+ [[ $COMPREPLY = */ ]] && compopt -o nospace -o filenames
765
}
766
767
_ipfs_swarm_filters()
768
{
362
- _ipfs_comp "add rm --help"
769
+ if [[ ${prev} == "add" ]] || [[ ${prev} == "rm" ]]; then
770
+ _ipfs_multiaddr_complete
771
+ else
772
+ _ipfs_comp "add rm --help"
773
+ fi
774
}
775
776
_ipfs_swarm_filters_add()
@@ -377,6 +788,29 @@ _ipfs_swarm_peers()
788
_ipfs_help_only
789
}
790
791
+_ipfs_tar()
792
+{
793
+ _ipfs_comp "add cat --help"
794
+}
795
+
796
+_ipfs_tar_add()
797
+{
798
+ if [[ ${word} == -* ]] ; then
799
+ _ipfs_comp "--help"
800
+ else
801
+ _ipfs_filesystem_complete
802
+ fi
803
+}
804
+
805
+_ipfs_tar_cat()
806
+{
807
+ if [[ ${word} == -* ]] ; then
808
+ _ipfs_comp "--help"
809
+ else
810
+ _ipfs_filesystem_complete
811
+ fi
812
+}
813
+
814
_ipfs_tour()
815
{
816
_ipfs_comp "list next restart --help"
@@ -399,24 +833,138 @@ _ipfs_tour_restart()
833
834
_ipfs_update()
835
{
402
- _ipfs_help_only
836
+ if [[ ${word} == -* ]] ; then
837
+ _ipfs_comp "--version" # TODO: How does "--verbose" option work?
838
+ else
839
+ _ipfs_comp "versions version install stash revert fetch"
840
+ fi
841
+}
842
+
843
+_ipfs_update_install()
844
+{
845
+ if [[ ${prev} == v*.*.* ]] ; then
846
+ COMPREPLY=()
847
+ elif [[ ${word} == -* ]] ; then
848
+ _ipfs_comp "--version"
849
+ else
850
+ local OLDIFS="$IFS" ; local IFS=$'\n' # Change divider for iterator one line below
851
+ opts=$(for x in `ipfs update versions`; do echo ${x} ; done)
852
+ IFS="$OLDIFS" # Reset divider to space, ' '
853
+ COMPREPLY=( $(compgen -W "${opts}" -- ${word}) )
854
+ fi
855
+}
856
+
857
+_ipfs_update_stash()
858
+{
859
+ if [[ ${word} == -* ]] ; then
860
+ _ipfs_comp "--tag --help"
861
+ fi
862
+}
863
+_ipfs_update_fetch()
864
+{
865
+ if [[ ${prev} == "--output" ]] ; then
866
+ _ipfs_filesystem_complete
867
+ elif [[ ${word} == -* ]] ; then
868
+ _ipfs_comp "--output --help"
869
+ fi
870
}
871
872
_ipfs_version()
873
{
407
- _ipfs_comp "--number --help"
874
+ _ipfs_comp "--number --commit --repo"
875
+}
876
+
877
+_ipfs_hash_complete()
878
+{
879
+ local lastDir=${word%/*}/
880
+ echo "LastDir: ${lastDir}" >> ~/Downloads/debug-ipfs.txt
881
+ local OLDIFS="$IFS" ; local IFS=$'\n' # Change divider for iterator one line below
882
+ opts=$(for x in `ipfs file ls ${lastDir}`; do echo ${lastDir}${x}/ ; done) # TODO: Implement "ipfs file ls -F" to get rid of frontslash after files. This take long time to run first time on a new shell.
883
+ echo "Options: ${opts}" >> ~/Downloads/debug-ipfs.txt
884
+ IFS="$OLDIFS" # Reset divider to space, ' '
885
+ echo "Current: ${word}" >> ~/Downloads/debug-ipfs.txt
886
+ COMPREPLY=( $(compgen -W "${opts}" -- ${word}) )
887
+ echo "Suggestion: ${COMPREPLY}" >> ~/Downloads/debug-ipfs.txt
888
+ [[ $COMPREPLY = */ ]] && compopt -o nospace -o filenames # Removing whitespace after output & handle output as filenames. (Only printing the latest folder of files.)
889
+ return 0
890
+}
891
+
892
+_ipfs_files_complete()
893
+{
894
+ local lastDir=${word%/*}/
895
+ local OLDIFS="$IFS" ; local IFS=$'\n' # Change divider for iterator one line below
896
+ opts=$(for x in `ipfs files ls ${lastDir}`; do echo ${lastDir}${x}/ ; done) # TODO: Implement "ipfs files ls -F" to get rid of frontslash after files. This does currently throw "Error: /cats/foo/ is not a directory"
897
+ IFS="$OLDIFS" # Reset divider to space, ' '
898
+ COMPREPLY=( $(compgen -W "${opts}" -- ${word}) )
899
+ [[ $COMPREPLY = */ ]] && compopt -o nospace -o filenames
900
+ return 0
901
+}
902
+
903
+_ipfs_multiaddr_complete()
904
+{
905
+ local lastDir=${word%/*}/
906
+ # Special case
907
+ if [[ ${word} == */"ipcidr"* ]] ; then # TODO: Broken, fix it.
908
+ opts="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" # TODO: IPv6?
909
+ COMPREPLY=( $(compgen -W "${opts}" -- ${word}) )
910
+ # "Loop"
911
+ elif [[ ${word} == /*/ ]] || [[ ${word} == /*/* ]] ; then
912
+ if [[ ${word} == /*/*/*/*/*/ ]] ; then
913
+ COMPREPLY=()
914
+ elif [[ ${word} == /*/*/*/*/ ]] ; then
915
+ word=${word##*/}
916
+ opts="ipfs/ "
917
+ COMPREPLY=( $(compgen -W "${opts}" -- ${word}) )
918
+ elif [[ ${word} == /*/*/*/ ]] ; then
919
+ word=${word##*/}
920
+ opts="4001/ "
921
+ COMPREPLY=( $(compgen -W "${opts}" -- ${word}) )
922
+ elif [[ ${word} == /*/*/ ]] ; then
923
+ word=${word##*/}
924
+ opts="udp/ tcp/ ipcidr/"
925
+ COMPREPLY=( $(compgen -W "${opts}" -- ${word}) )
926
+ elif [[ ${word} == /*/ ]] ; then
927
+ COMPREPLY=() # TODO: This need to return something to NOT break the function. Maybe a "/" in the end as well due to -o filename option.
928
+ fi
929
+ COMPREPLY=${lastDir}${COMPREPLY}
930
+ else # start case
931
+ opts="/ip4/ /ip6/"
932
+ COMPREPLY=( $(compgen -W "${opts}" -- ${word}) )
933
+ fi
934
+ [[ $COMPREPLY = */ ]] && compopt -o nospace -o filenames
935
+ return 0
936
+}
937
+
938
+_ipfs_pinned_complete()
939
+{
940
+ local OLDIFS="$IFS" ; local IFS=$'\n'
941
+ local pinned=$(ipfs pin ls)
942
+ COMPREPLY=( $(compgen -W "${pinned}" -- ${word}) )
943
+ IFS="$OLDIFS"
944
+ if [[ ${#COMPREPLY[*]} -eq 1 ]]; then # Only one completion, remove pretty output
945
+ COMPREPLY=( ${COMPREPLY[0]/ *//} ) #Remove ' ' and everything after
946
+ [[ $COMPREPLY = */ ]] && compopt -o nospace # Removing whitespace after output
947
+ fi
948
+}
949
+_ipfs_filesystem_complete()
950
+{
951
+ compopt -o default # Re-enable default file read
952
+ COMPREPLY=()
953
}
954
955
_ipfs()
956
{
957
COMPREPLY=()
958
+ compopt +o default # Disable default to not deny completion, see: http://stackoverflow.com/a/19062943/1216348
959
+
960
local word="${COMP_WORDS[COMP_CWORD]}"
961
+ local prev="${COMP_WORDS[COMP_CWORD-1]}"
962
963
case "${COMP_CWORD}" in
964
1)
417
- local opts="add bitswap block bootstrap cat commands config daemon dht \
418
- diag dns file get id init log ls mount name object pin ping \
419
- refs repo stats swarm tour update version"
965
+ local opts="add bitswap block bootstrap cat commands config daemon dag dht \
966
+ diag dns file files get id init log ls mount name object pin ping pubsub \
967
+ refs repo resolve stats swarm tar tour update version"
968
COMPREPLY=( $(compgen -W "${opts}" -- ${word}) );;
969
2)
970
local command="${COMP_WORDS[1]}"