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