File: documentation.md

package info (click to toggle)
crazy-complete 0.3.7-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,528 kB
  • sloc: python: 13,342; sh: 995; makefile: 68
file content (1874 lines) | stat: -rw-r--r-- 43,898 bytes parent folder | download
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
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
Crazy-Complete Documentation
============================

This documentation provides an overview of how to define shell completion for commands using crazy-complete.

- [Generating a Defintion File from Help](#generating-a-definition-file-from-help)
- [Defining a Command](#defining-a-command)
- [Defining an Option](#defining-an-option)
- [Defining a Positional Argument](#defining-a-positional-argument)
- [Using Aliases](#using-aliases)
- [Completion Commands](#completion-commands)
  - [Meta Commands](#meta-commands)
  - [Built-in Commands](#built-in-commands)
  - [User-Defined Commands](#user-defined-commands)
  - [Bonus Commands](#bonus-commands)
- [Options](#options)
- [When Conditionals](#when-conditionals)
- [Capturing Options](#capturing-options)
- [Tips and Tricks](#tips-and-tricks)

## Generating a Definition File from Help

It is possible to generate a definition file from a commands help output:

```
grep --help > help_file
crazy-complete --input-type=help yaml help_file

# or

grep --help | crazy-complete --input-type=help yaml /dev/stdin
```

## Defining a Command

To define a completion for a command, use the following structure:

```yaml
prog: "<PROGRAM NAME>"
aliases: ["<ALIAS>", ...]
help: "<PROGRAM DESCRIPTION>"
wraps: "<PROGRAM>"
options:
  <OPTION ...>
positionals:
  <POSITIONAL ...>
```

- *prog*: The name of the program for which you want to create completion
- *aliases* (optional): Specify alternative program names for which this completion should also apply
- *help* (optional): A short description of the program
- *wraps* (optional): Inherit completion behaviour of another command
- *options* (optional): A list of [options](#defining-an-option) the program accepts
- *positionals* (optional): A list of [positional arguments](#defining-a-positional-argument) the program uses

## Defining an Option

To define an option, use this format:

```yaml
[...]
options:
  - option_strings: ["<OPTION STRING>", ...]
    metavar: "<METAVAR>"
    help: "<OPTION DESCRIPTION>"
    optional_arg: <BOOL>
    complete: <COMPLETE ACTION>
    nosort: <BOOL>
    repeatable: <BOOL>
    final: <BOOL>
    hidden: <BOOL>
    groups: ["<GROUP>", ...]
    when: "<CONDITION>"
    capture: "<VARIABLE>"
    long_opt_arg_sep: "equals|space|both"
[...]
```

- *option\_strings*: A list of option strings (e.g., ["-h", "--help"])
- *metavar* (optional): The placeholder used for the argument (e.g., "FILE")
- *help* (optional): A description of the option
- *optional\_arg* (optional): Indicates if the option's argument is optional (default: false)
- *complete* (optional): Defines the method used to provide possible completions for this option. If not set, the option does not take an argument. Use `["none"]` if the option accepts an argument but no specific completion method applies. See [Completion Commands](#completion-commands)
- *nosort* (optional): Do not sort completion suggestions alphabetically. Keep them in the order generated by the completer. (true or false, default: false)
- *repeatable* (optional): Indicates whether an option can be suggested multiple times (true or false, default: false)
- *final* (optional): The final parameter indicates that no further options are shown after this one if it is passed on command line. Mostly used for --help and --version (default: false)
- *hidden* (optional): Specifies whether an option should be excluded from the auto-completion suggestions, though it remains usable when typed manually. (default: false)
- *groups* (optional): Add this option into the specified groups. Multiple flags from the same group cannot be completed at once. Useful for mutually exclusive flags
- *when* (optional): Only enable this option if [CONDITION](#when-conditionals) evaluates to true
- *capture* (optional): Specify the [variable](#capturing-options) where values of this option should be captured
- *long_opt_arg_sep* (optional): Specifies which separators are used for delimiting a long option from its argument

## Defining a Positional Argument

Positional arguments are defined as follows:

```yaml
[...]
positionals:
  - number: <NUMBER>
    metavar: "<METAVAR>"
    help: "<POSITIONAL DESCRIPTION>"
    repeatable: <BOOL>
    complete: <COMPLETE ACTION>
    nosort: <BOOL>
    when: "<CONDITION>"
[...]
```

- *number*: The order of the positional argument (e.g., 1 for the first argument)
- *metavar* (optional): A placeholder for the positional argument in the help text
- *help* (optional): A description of the positional argument
- *repeatable* (optional): Indicates if this positional argument can be repeated (true or false, default: false)
- *complete* (optional): The method used to generate possible completions for this positional argument. Default `["none"]`. See [Completion Commands](#completion-commands).
- *nosort* (optional): Do not sort completion suggestions alphabetically. Keep them in the order generated by the completer. (true or false, default: false)
- *when* (optional): Only enable this positional if [CONDITION](#when-conditionals) evaluates to true

### Using Aliases

Aliases / defines can be handy if completers are reused or to keep the defintion file clean.

**NOTE:** Every defined string is replaced throughout the YAML document, regardless of its context.

```yaml
prog: '%defines%'
complete_bool: ['choices', ['true', 'false']]
---
prog: "example"
options:
  - option_strings: ['--option-1']
    complete: 'complete_bool'

  - option_strings: ['--option-2']
    complete: 'complete_bool'
```

## Defining Subcommands

To define subcommands, append the subcommand name directly to the program name:

```yaml
prog: "<PROGRAM NAME> <SUBCOMMAND> ..."
aliases: ["<ALIAS>", ...]
help: "<SUBCOMMAND DESCRIPTION>"
[...]
```

- *prog*: The name of the program, followed by the subcommand(s)
- *aliases* (optional): A list of alternative names for the subcommand. Aliases must not include the program name
- *help* (optional): A description of the subcommand

## Completion Commands

### Meta commands

| Command                             | Description                                               |
| ----------------------------------- | --------------------------------------------------------- |
| [combine](#combine)                 | Combine multiple completers                               |
| [key\_value\_list](#key_value_list) | Complete a comma-separated list of key=value pairs        |
| [list](#list)                       | Complete a comma-separated list of any completer          |
| [none](#none)                       | No completion, but specifies that an argument is required |
| [prefix](#prefix)                   | Prefix completion by a string                             |

---

### Built-in commands

| Command                                    | Description                                    |
| ------------------------------------------ | ---------------------------------------------- |
| [choices](#choices)                        | Complete from a set of words                   |
| [command](#command)                        | Complete a command                             |
| [command\_arg](#command_arg)               | Complete arguments of a command                |
| [commandline\_string](#commandline_string) | Complete a command line as a string            |
| [date](#date)                              | Complete a date string                         |
| [date\_format](#date_format)               | Complete a date format string                  |
| [directory](#directory)                    | Complete a directory                           |
| [directory\_list](#directory_list)         | Complete a comma-separated list of directories |
| [environment](#environment)                | Complete a shell environment variable name     |
| [file](#file)                              | Complete a file                                |
| [file\_list](#file_list)                   | Complete a comma-separated list of files       |
| [filesystem\_type](#filesystem_type)       | Complete a filesystem type                     |
| [float](#float)                            | Complete a floating point number               |
| [gid](#gid)                                | Complete a group id                            |
| [group](#group)                            | Complete a group                               |
| [history](#history)                        | Complete based on a shell's history            |
| [hostname](#hostname)                      | Complete a hostname                            |
| [integer](#integer)                        | Complete an integer                            |
| [ip\_address](#ip_address)                 | Complete a bound ip address                    |
| [mime\_file](#mime_file)                   | Complete a file based on it's MIME-type        |
| [pid](#pid)                                | Complete a PID                                 |
| [process](#process)                        | Complete a process name                        |
| [range](#range)                            | Complete a range of integers                   |
| [service](#service)                        | Complete a SystemD service                     |
| [signal](#signal)                          | Complete signal names                          |
| [uid](#uid)                                | Complete a user id                             |
| [user](#user)                              | Complete a username                            |
| [value\_list](#value_list)                 | Complete a comma-separated list of values      |
| [variable](#variable)                      | Complete a shell variable name                 |

---

### User-defined commands

| Command                          | Description                                                                 |
| -------------------------------- | --------------------------------------------------------------------------- |
| [exec](#exec)                    | Complete by the output of a command or function                             |
| [exec\_fast](#exec_fast)         | Complete by the output of a command or function (fast and unsafe)           |
| [exec\_internal](#exec_internal) | Complete by a function that uses the shell's internal completion mechanisms |

---

### Bonus commands

| Command                          | Description                  |
| -------------------------------- | ---------------------------- |
| [alsa\_card](#alsa_card)         | Complete an ALSA card        |
| [alsa\_device](#alsa_device)     | Complete an ALSA device      |
| [charset](#charset)              | Complete a charset           |
| [locale](#locale)                | Complete a locale            |
| [login\_shell](#login_shell)     | Complete a login shell       |
| [mountpoint](#mountpoint)        | Complete a mountpoint        |
| [net\_interface](#net_interface) | Complete a network interface |
| [timezone](#timezone)            | Complete a timezone          |

---

### alsa\_card

> Complete an ALSA card

```yaml
prog: "example"
options:
  - option_strings: ["--alsa-card"]
    complete: ["alsa_card"]
```

```
~ > example --alsa-card=<TAB>
0  1
```

**SEE ALSO**

- [alsa\_device](#alsa_device): For completing an ALSA device

---

### alsa\_device

> Complete an ALSA device

```yaml
prog: "example"
options:
  - option_strings: ["--alsa-device"]
    complete: ["alsa_device"]
```

```
~ > example --alsa-device=<TAB>
hw:0  hw:1
```

**SEE ALSO**

- [alsa\_card](#alsa_card): For completing an ALSA card

---

### charset

> Complete a charset

```yaml
prog: "example"
options:
  - option_strings: ["--charset"]
    complete: ["charset"]
```

```
~ > example --charset=A<TAB>
ANSI_X3.110-1983  ANSI_X3.4-1968    ARMSCII-8         ASMO_449
```

---

### locale

> Complete a locale

```yaml
prog: "example"
options:
  - option_strings: ["--locale"]
    complete: ["locale"]
```

```
~ > example --locale=<TAB>
C  C.UTF-8  de_DE  de_DE@euro  de_DE.iso88591  de_DE.iso885915@euro
de_DE.UTF-8  deutsch  en_US  en_US.iso88591  en_US.UTF-8  german  POSIX
```

---

### login\_shell

> Complete a login shell

```yaml
prog: "example"
options:
  - option_strings: ["--login-shell"]
    complete: ["login_shell"]
```

```
~ > example --login-shell=<TAB>
/bin/bash   /bin/sh         /usr/bin/fish       /usr/bin/sh
[...]
```

---

### mountpoint

> Complete a mountpoint

```yaml
prog: "example"
options:
  - option_strings: ["--mountpoint"]
    complete: ["mountpoint"]
```

```
~ > example --mountpoint=<TAB>
/  /boot  /home  /proc  /run  /sys  /tmp
[...]
```

---

### net\_interface

> Complete a network interface

```yaml
prog: "example"
options:
  - option_strings: ["--net-interface"]
    complete: ["net_interface"]
```

```
~ > example --net-interface=<TAB>
eno1  enp1s0  lo  wlo1  wlp2s0
[...]
```

**SEE ALSO**

- [ip\_address](#ip_address): For completing an ip address

---

### timezone

> Complete a timezone

```yaml
prog: "example"
options:
  - option_strings: ["--timezone"]
    complete: ["timezone"]
```

```
~ > example --timezone=Europe/B<TAB>
Belfast     Belgrade    Berlin      Bratislava
Brussels    Bucharest   Budapest    Busingen
```

---

### choices

> Complete from a set of words

Items can be a list or a dictionary.
 
If a dictionary is supplied, the keys are used as items and the values are used
as description.


**NOTES**

- If the completion suggestions should appear in their original order, set `nosort` to `true`

```yaml
prog: "example"
options:
  - option_strings: ["--choices-1"]
    complete: ["choices", ["Item 1", "Item 2"]]

  - option_strings: ["--choices-2"]
    complete: ["choices", {"Item 1": "Description 1", "Item 2": "Description 2"}]

  - option_strings: ["--choices-keep-order"]
    complete: ["choices", ["zebra", "cat", "monkey"]]
    nosort: true
```

```
~ > example --choices-2=<TAB>
Item 1  (Description 1)  Item 2  (Description 2)
```

---

### command

> Complete a command

This completer provides completion suggestions for executable commands available in the system's `$PATH`.
 
`$PATH` can be modified using these options:
 
`{"path": "<directory>:..."}`: Overrides the default `$PATH` entirely.
 
`{"path_append": "<directory>:..."}`: Appends to the default `$PATH`.
 
`{"path_prepend": "<directory>:..."}`: Prepends to the default `$PATH`.


**NOTES**

- `path_append` and `path_prepend` can be used together, but both are mutually exclusive with `path`.

```yaml
prog: "example"
options:
  - option_strings: ["--command"]
    complete: ["command"]
  - option_strings: ["--command-sbin"]
    complete: ["command", {"path_append": "/sbin:/usr/sbin"}]
```

```
~ > example --command=bas<TAB>
base32    base64    basename  basenc    bash      bashbug
```

**SEE ALSO**

- [command\_arg](#command_arg): For completing arguments of a command

- [commandline\_string](#commandline_string): For completing a command line as a string

---

### command\_arg

> Complete arguments of a command

**NOTES**

- This completer can only be used in combination with a previously defined `command` completer.

- This completer requires `repeatable: true`.

```yaml
prog: "example"
positionals:
  - number: 1
    complete: ["command"]

  - number: 2
    complete: ["command_arg"]
    repeatable: true
```

```
~ > example sudo bas<TAB>
base32    base64    basename  basenc    bash      bashbug
```

**SEE ALSO**

- [command](#command): For completing a command

- [commandline\_string](#commandline_string): For completing a command line as a string

---

### commandline\_string

> Complete a command line as a string

```yaml
prog: "example"
options:
  - option_strings: ["--commandline"]
    complete: ["commandline_string"]
```

```
~ > example --commandline='sudo ba<TAB>
base32    base64    basename  basenc    bash      bashbug
```

---

### date

> Complete a date string

The argument is the date format as described in `strftime(3)`.


**NOTES**

- This completer is currently only implemented in **Zsh**.

```yaml
prog: "example"
options:
  - option_strings: ["--date"]
    complete: ["date", '%Y-%m-%d']
```

```
~ > example --date=<TAB>

         November                        
Mo  Tu  We  Th  Fr  Sa  Su     
     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
```

**SEE ALSO**

- [date\_format](#date_format): For completing a date format string

---

### date\_format

> Complete a date format string

**NOTES**

- This completer is currently only implemented in **Fish** and **Zsh**.

```yaml
prog: "example"
options:
  - option_strings: ["--date-format"]
    complete: ["date_format"]
```

```
~ > example --date-format '%<TAB>
a     -- abbreviated day name
A     -- full day name
B     -- full month name
c     -- preferred locale date and time
C     -- 2-digit century
d     -- day of month (01-31)
D     -- American format month/day/year (%m/%d/%y)
e     -- day of month ( 1-31)
[...]
```

**SEE ALSO**

- [date](#date): For completing a date

---

### directory

> Complete a directory

You can restrict completion to a specific directory by adding `{"directory": ...}`.


```yaml
prog: "example"
options:
  - option_strings: ["--directory"]
    complete: ["directory"]
  - option_strings: ["--directory-tmp"]
    complete: ["directory", {"directory": "/tmp"}]
```

```
~ > example --directory=<TAB>
dir1/  dir2/
```

**SEE ALSO**

- [directory\_list](#directory_list): For completing a comma-separated list of directories

---

### directory\_list

> Complete a comma-separated list of directories

This is an alias for `['list', ['directory']]`.

You can restrict completion to a specific directory by adding `{"directory": ...}`.
 
The separator can be changed by adding `{"separator": ...}`
 
By default, duplicate values are not offered for completion. This can be changed by adding `{"duplicates": true}`.


```yaml
prog: "example"
options:
  - option_strings: ["--directory-list"]
    complete: ["directory_list"]
```

```
~ > example --directory-list=directory1,directory2,<TAB>
directory3  directory4
```

**SEE ALSO**

- [list](#list): For completion a comma-separated list of any completer

- [directory](#directory): For completing a directory

- [file\_list](#file_list): For completing a comma-separated list of files

---

### environment

> Complete a shell environment variable name

```yaml
prog: "example"
options:
  - option_strings: ["--environment"]
    complete: ["environment"]
```

```
~ > example --environment=X<TAB>
XDG_RUNTIME_DIR  XDG_SEAT  XDG_SESSION_CLASS  XDG_SESSION_ID
XDG_SESSION_TYPE XDG_VTNR
```

---

### file

> Complete a file

You can restrict completion to a specific directory by adding `{"directory": ...}`.
 
You can restrict completion to specific extensions by adding `{"extensions": [...]}`.
 
You can make matching extensions *fuzzy* by adding `{"fuzzy": true}`.
Fuzzy means that the files do not have to end with the exact extension. For example `foo.txt.1`.

You can ignore files by adding a list of Bash globs using `{"ignore_globs": [...]}`

**NOTE:** Restricting completion to specific file extensions only makes sense if the program being completed actually expects files of those types.
On Unix-like systems, file extensions generally have no inherent meaning -- they are purely conventional and not required for determining file types.


```yaml
prog: "example"
options:
  - option_strings: ["--file"]
    complete: ["file"]

  - option_strings: ["--file-tmp"]
    complete: ["file", {"directory": "/tmp"}]

  - option_strings: ["--file-ext"]
    complete: ["file", {"extensions": ["c", "cpp"]}]

  - option_strings: ["--file-ignore"]
    complete: ["file", {"ignore_globs": ["*.[tT][xX][tT]", "*.c++"]}]
```

```
~ > example --file=<TAB>
dir1/  dir2/  file1  file2
~ > example --file-ext=<TAB>
dir1/  dir2/  file.c  file.cpp
```

**SEE ALSO**

- [file\_list](#file_list): For completing a comma-separated list of files

- [mime\_file](#mime_file): For completing a file based on it's MIME-type

---

### file\_list

> Complete a comma-separated list of files

This is an alias for `['list', ['file']]`.

You can restrict completion to a specific directory by adding `{"directory": ...}`.

You can restrict completion to specific extensions by adding `{"extensions": [...]}`.

You can make matching extensions *fuzzy* by adding `{"fuzzy": true}`.
Fuzzy means that the files do not have to end with the exact extension. For example `foo.txt.1`.

You can ignore files by adding a list of Bash globs using `{"ignore_globs": [...]}`

By default, duplicate values are not offered for completion. This can be changed by adding `{"duplicates": true}`.

The separator can be changed by adding `{"separator": ...}`


```yaml
prog: "example"
options:
  - option_strings: ["--file-list"]
    complete: ["file_list"]
```

```
~ > example --file-list=file1,file2,<TAB>
file3  file4
```

**SEE ALSO**

- [list](#list): For completing a comma-separted list using any completer

- [file](#file): For completing a file

- [directory\_list](#directory_list): For completing a comma-separated list of directories

---

### filesystem\_type

> Complete a filesystem type

```yaml
prog: "example"
options:
  - option_strings: ["--filesystem-type"]
    complete: ["filesystem_type"]
```

```
~ > example --filesystem-type=<TAB>
adfs     autofs   bdev      bfs     binder     binfmt_misc  bpf
cgroup   cgroup2  configfs  cramfs  debugfs    devpts       devtmpfs
[...]
```

---

### float

> Complete a floating point number

A min value can be specified by using `{"min": <VALUE>}`.

A max value can be specified by using `{"max": <VALUE>}`.

A list of suffixes can be specified by using `{"suffixes": {"<SUFFIX>": "<DESCRIPTION", ...}}`

A help text can be set by using `{"help": "<TEXT>"}`. If not supplied, the `help` attribute of the option is used.


```yaml
prog: "example"
options:
  - option_strings: ["--time"]
    complete: ["float", {"suffixes": {"s": "seconds", "m": "minutes", "h": "hours"}}]
```

```
~ > example --time=3.0<TAB>
s -- seconds  m -- minutes  h -- hours
```

**SEE ALSO**

- [integer](#integer): For completing an integer

---

### gid

> Complete a group id

```yaml
prog: "example"
options:
  - option_strings: ["--gid"]
    complete: ["gid"]
```

```
~ > example --gid=<TAB>
0      -- root
1000   -- braph
102    -- polkitd
108    -- vboxusers
11     -- ftp
12     -- mail
133    -- rtkit
19     -- log
[...]
```

**SEE ALSO**

- [group](#group): For completing a group name

---

### group

> Complete a group

```yaml
prog: "example"
options:
  - option_strings: ["--group"]
    complete: ["group"]
```

```
~ > example --group=<TAB>
adm                     audio                   avahi
bin                     braph                   colord
daemon                  dbus                    dhcpcd
disk                    floppy                  ftp
games                   git                     groups
[...]
```

**SEE ALSO**

- [gid](#gid): For completing a group id

---

### history

> Complete based on a shell's history

The argument is an extended regular expression passed to `grep -E`.


```yaml
prog: "example"
options:
  - option_strings: ["--history"]
    complete: ["history", '[a-zA-Z0-9]+@[a-zA-Z0-9]+']
```

```
~ > example --history=<TAB>
foo@bar mymail@myprovider
```

---

### hostname

> Complete a hostname

```yaml
prog: "example"
options:
  - option_strings: ["--hostname"]
    complete: ["hostname"]
```

```
~ > example --hostname=<TAB>
localhost
```

---

### integer

> Complete an integer

A min value can be specified by using `{"min": <VALUE>}`.

A max value can be specified by using `{"max": <VALUE>}`.

A list of suffixes can be specified by using `{"suffixes": {"<SUFFIX>": "<DESCRIPTION", ...}}`

A help text can be set by using `{"help": "<TEXT>"}`. If not supplied, the `help` attribute of the option is used.


```yaml
prog: "example"
options:
  - option_strings: ["--time"]
    complete: ["integer", {"suffixes": {"s": "seconds", "m": "minutes", "h": "hours"}}]
```

```
~ > example --integer=3<TAB>
s -- seconds  m -- minutes  h -- hours
```

**SEE ALSO**

- [float](#float): For completing a floating point number

- [range](#range): For completing a range of integers

---

### ip\_address

> Complete a bound ip address

By default, both IPv4 and IPv6 addresses are completed.

To complete only IPv4 addresses, pass "ipv4" as argument.

To complete only IPv6 addresses, pass "ipv6" as argument.


```yaml
prog: "example"
options:
  - option_strings: ["--ip-address"]
    complete: ["ip_address"]
  - option_strings: ["--ip-address-v4"]
    complete: ["ip_address", "ipv4"]
  - option_strings: ["--ip-address-v6"]
    complete: ["ip_address", "ipv6"]
```

```
~ > example --ip-address=<TAB>
::1    10.0.0.71   127.0.0.1   fe80::f567:7a1a:3c98:808d

~ > example --ip-address-v4=<TAB>
10.0.0.71   127.0.0.1

~ > example --ip-address-v6=<TAB>
::1   fe80::f567:7a1a:3c98:808d
```

**SEE ALSO**

- [net\_interface](#net_interface): For completing a network interface

---

### mime\_file

> Complete a file based on it's MIME-type

This completer takes an extended regex passed to `grep -E` to filter the results.


```yaml
prog: "example"
options:
  - option_strings: ["--image"]
    complete: ["mime_file", 'image/']
```

```
~ > example --image=<TAB>
dir1/  dir2/  img.png  img.jpg
```

---

### pid

> Complete a PID

```yaml
prog: "example"
options:
  - option_strings: ["--pid"]
    complete: ["pid"]
```

```
~ > example --pid=<TAB>
1       13      166     19      254     31      45
1006    133315  166441  19042   26      32      46
10150   1392    166442  195962  27      33      4609
```

**SEE ALSO**

- [process](#process): For completing a process name

---

### process

> Complete a process name

```yaml
prog: "example"
options:
  - option_strings: ["--process"]
    complete: ["process"]
```

```
~ > example --process=s<TAB>
scsi_eh_0         scsi_eh_1       scsi_eh_2      scsi_eh_3  scsi_eh_4
scsi_eh_5         sh              sudo           syndaemon  systemd
systemd-journald  systemd-logind  systemd-udevd
```

**SEE ALSO**

- [pid](#pid): For completing a PID

---

### range

> Complete a range of integers

```yaml
prog: "example"
options:
  - option_strings: ["--range-1"]
    complete: ["range", 1, 9]
  - option_strings: ["--range-2"]
    complete: ["range", 1, 9, 2]
```

```
~ > example --range-1=<TAB>
1  2  3  4  5  6  7  8  9
~ > example --range-2=<TAB>
1  3  5  7  9
```

---

### service

> Complete a SystemD service

```yaml
prog: "example"
options:
  - option_strings: ["--service"]
    complete: ["service"]
```

```
~ > example --service=<TAB>
TODO
[...]
```

---

### signal

> Complete signal names

```yaml
prog: "example"
options:
  - option_strings: ["--signal"]
    complete: ["signal"]
```

```
~ > example --signal=<TAB>
ABRT    -- Process abort signal
ALRM    -- Alarm clock
BUS     -- Access to an undefined portion of a memory object
CHLD    -- Child process terminated, stopped, or continued
CONT    -- Continue executing, if stopped
FPE     -- Erroneous arithmetic operation
HUP     -- Hangup
ILL     -- Illegal instruction
INT     -- Terminal interrupt signal
[...]
```

---

### uid

> Complete a user id

```yaml
prog: "example"
options:
  - option_strings: ["--uid"]
    complete: ["uid"]
```

```
~ > example --uid=<TAB>
0      -- root
1000   -- braph
102    -- polkitd
133    -- rtkit
14     -- ftp
1      -- bin
2      -- daemon
33     -- http
65534  -- nobody
[...]
```

**SEE ALSO**

- [user](#user): For completing a user name

---

### user

> Complete a username

```yaml
prog: "example"
options:
  - option_strings: ["--user"]
    complete: ["user"]
```

```
~ > example --user=<TAB>
avahi                   bin                     braph
colord                  daemon                  dbus
dhcpcd                  ftp                     git
[...]
```

**SEE ALSO**

- [uid](#uid): For completing a user id

---

### value\_list

> Complete a comma-separated list of values

Complete one or more items from a list of items. Similar to `mount -o`.
 
Arguments are supplied by adding `{"values": ...}`.
 
A separator can be supplied by adding `{"separator": ...}` (the default is `","`).
 
By default, duplicate values are not offered for completion. This can be changed by adding `{"duplicates": true}`.


```yaml
prog: "example"
options:
  - option_strings: ["--value-list-1"]
    complete: ["value_list", {"values": ["exec", "noexec"]}]
  - option_strings: ["--value-list-2"]
    complete: ["value_list", {"values": {"one": "Description 1", "two": "Description 2"}}]
```

```
~ > example --value-list-1=<TAB>
exec    noexec
~ > example --value-list-1=exec,<TAB>
noexec
~ > example --value-list-2=<TAB>
one  -- Description 1
two  -- Description 2
```

**SEE ALSO**

- [list](#list): For completing a comma-separated list of any completer

- [key\_value\_list](#key_value_list): For completing a comma-separated list of key=value pairs

---

### variable

> Complete a shell variable name

```yaml
prog: "example"
options:
  - option_strings: ["--variable"]
    complete: ["variable"]
```

```
~ > example --variable=HO<TAB>
HOME      HOSTNAME  HOSTTYPE
```

**SEE ALSO**

- [environment](#environment): For completing an environment variable

---

### combine

> Combine multiple completers

With `combine` multiple completers can be combined into one.

It takes a list of completers as its argument.


```yaml
prog: "example"
options:
  - option_strings: ["--combine"]
    complete: ["combine", [["user"], ["pid"]]]
```

```
~ > example --user-list=avahi,daemon,<TAB>
1439404  3488332  3571716           3607235                 4134206
alpm     avahi    bin               braph                   daemon
root     rtkit    systemd-coredump  systemd-journal-remote  systemd-network
[...]
```

---

### key\_value\_list

> Complete a comma-separated list of key=value pairs

The first argument is the separator used for delimiting the key-value pairs.

The second argument is the separator used for delimiting the value from the key.

The third argument is a list of key-description-completer definitions, like:

  `[ [<key>, <description>, <completer>], ... ]`

If a key does not take an argument, use `null` as completer.

If a key does take an argument but cannot be completed, use `['none']` as completer.


```yaml
prog: "example"
options:
  - option_strings: ["--key-value-list"]
    complete: ["key_value_list", ",", "=", [
      ['flag',   'An option flag', null],
      ['nodesc', null, null],
      ['nocomp', 'An option with arg but without completer', ['none']],
      ['user',   'Takes a username',  ['user']],
      ['check',  'Specify file name conversions', ['choices', {
        'relaxed': "convert to lowercase before lookup",
        'strict': "no conversion"
      }]]
    ]]
```

```
~ > example --key-value-list flag,user=<TAB>
bin                     braph
colord                  dbus
dhcpcd                  git
```

**SEE ALSO**

- [list](#list): For completing a comma-separated list of any completer

- [value\_list](#value_list): For completing a comma-separated list of values

---

### list

> Complete a comma-separated list of any completer

The separator can be changed by adding `{"separator": ...}`.

By default, duplicate values are not offered for completion. This can be changed by adding `{"duplicates": true}`.


```yaml
prog: "example"
options:
  - option_strings: ["--user-list"]
    complete: ["list", ["user"]]
  - option_strings: ["--option-list"]
    complete: ["list", ["choices", ["setuid", "async", "block"]], {"separator": ":"}]
```

```
~ > example --user-list=avahi,daemon,<TAB>
bin                     braph
colord                  dbus
dhcpcd                  git
```

**SEE ALSO**

- [value\_list](#value_list): For completing a comma-separated list of values

- [file\_list](#file_list): For completing a comma-separated list of files

- [directory\_list](#directory_list): For completing a comma-separated list of directories

- [key\_value\_list](#key_value_list): For completing a comma-separated list of key=value pairs

---

### none

> No completion, but specifies that an argument is required

Disables autocompletion for an option but still marks it as requiring an argument.

Without specifying `complete`, the option would not take an argument.


```yaml
prog: "example"
options:
  - option_strings: ["--none"]
    complete: ["none"]
```

```
~ > example --none=<TAB>
<NO OUTPUT>
```

---

### prefix

> Prefix completion by a string

The first argument is the prefix that should be used.

The second argument is a completer.


```yaml
prog: "example"
options:
  - option_strings: ["--prefix"]
    complete: ["prefix", "input:", ['file']]
```

```
~ > example --prefix=<TAB>
~ > example --prefix=input:

~ > example --prefix=input:<TAB>
~ > example --prefix=input:file1.txt
```

---

### exec

> Complete by the output of a command or function

The output must be in form of:

```
<item_1>\t<description_1>\n
<item_2>\t<description_2>\n
[...]
```

An item and its description are delimited by a tabulator.
 
These pairs are delimited by a newline.


**NOTES**

- Functions can be put inside a file and included with `--include-file`

```yaml
prog: "example"
options:
  - option_strings: ["--exec"]
    complete: ["exec", "printf '%s\\t%s\\n' 'Item 1' 'Description 1' 'Item 2' 'Description 2'"]
```

```
~ > example --exec=<TAB>
Item 1  (Description 1)  Item 2  (Description 2)
```

**SEE ALSO**

- [exec\_fast](#exec_fast): Faster implementation of exec

---

### exec\_fast

> Complete by the output of a command or function (fast and unsafe)

Faster version of exec for handling large amounts of data.
 
This implementation requires that the items of the parsed output do not include
special shell characters or whitespace.


**NOTES**

- Functions can be put inside a file and included with `--include-file`

```yaml
prog: "example"
options:
  - option_strings: ["--exec-fast"]
    complete: ["exec_fast", "printf '%s\\t%s\\n' 1 one 2 two"]
```

```
~ > example --exec-internal=<TAB>
1  -- one
2  -- one
```

---

### exec\_internal

> Complete by a function that uses the shell's internal completion mechanisms

Execute a function that internally modifies the completion state.

This is useful if a more advanced completion is needed.

For **Bash**, it might look like:

```sh
my_completion_func() {
    COMPREPLY=( $(compgen -W "read write append" -- "$cur") )
}
```

For **Zsh**, it might look like:

```sh
my_completion_func() {
    local items=(
        read:'Read data from a file'
        write:'Write data from a file'
        append:'Append data to a file'
    )

    _describe 'my items' items
}
```

For **Fish**, it might look like:

```sh
function my_completion_func
    printf '%s\t%s\n' \
        read 'Read data from a file'  \
        write 'Write data from a file' \
        append 'Append data to a file'
end
```


**NOTES**

- Functions can be put inside a file and included with `--include-file`

```yaml
prog: "example"
options:
  - option_strings: ["--exec-internal"]
    complete: ["exec_internal", "my_completion_func"]
```

```
~ > example --exec-internal=<TAB>
append  -- Append data to a file
read    -- Read data from a file
write   -- Write data from a file
```

### Options

**--version**

> Show program version

---

**--help**

> Show program help

---

**--manual=[TOPIC]**

> Show a manual for a help topic

---

**--input-type=TYPE** *(yaml, json, python, help, auto)*

> Specify input file type. If "auto", input type is determined by the file extension

For security reasons, reading python files must be explicitly enabled.

This option defaults to `auto`.

---

**--abbreviate-commands=BOOL** *(True, False)*

> Sets whether sub commands can be abbreviated

This option defaults to `False`.

---

**--abbreviate-options=BOOL** *(True, False)*

> Sets whether options can be abbreviated

Currently only supported in Bash.

This option defaults to `False`.

---

**--repeatable-options=BOOL** *(True, False)*

> Sets whether options are suggested multiple times during completion

This only overrides the `repeatable` parameter of options that don't have
it explicitly set to `True` or `False`.

If you wish to make all options repeatable regardless of how they are
defined in the definition file, use `--disable=repeatable`.

This option defaults to `False`.

---

**--inherit-options=BOOL** *(True, False)*

> Sets whether parent options are visible to subcommands

This option defaults to `False`.

---

**--option-stacking=BOOL** *(True, False)*

> Sets whether short option stacking is allowed

Enables or disables short option stacking, where multiple short options are
combined in a single argument (e.g. `-fo` instead of `-f -o`).

This option defaults to `True`.

---

**--long-option-argument-separator=SEPARATOR** *(space, equals, both)*

> Sets which separators are used for delimiting a long option from its argument

If `space`, only the form `--option argument` is allowed.
If `equals`, only the form `--option=argument` is allowed.
If `both`, both forms are allowed.

Currently only supported in Bash and Zsh.

This option defaults to `both`.

---

**--disable=FEATURES** *(hidden, final, groups, repeatable, when)*

> Disable features

- hidden: Disable hidden options
- final: Disable final options
- groups: Disable option groups
- repeatable: Make all options repeatable
- when: Disable conditional options and positionals

---

**--vim-modeline=BOOL** *(True, False)*

> Sets whether a vim modeline comment shall be appended to the generated code

The modeline comment looks like this:

  `# vim: ft=zsh ts=2 sts=2 sw=2 et`

This option defaults to `True`.

---

**--bash-completions-version=VERSION**

> Generate code for a specific bash-completions version

Use a value greater or equal to `2.12` to generate code for the "new"
version of bash-completions.

This option defaults to `2.0`.

---

**--zsh-compdef=BOOL** *(True, False)*

> Sets whether #compdef is used in zsh scripts

Set this option to `False` if the generated script should be sourcable.

This option defaults to `True`.

---

**--fish-fast=BOOL** *(True, False)*

> Use faster commandline parsing for fish at the cost of correctness

This option defaults to `False`.

---

**--fish-inline-conditions=BOOL** *(True, False)*

> Don't store conditions in a variable

This option defaults to `False`.

---

**--parser-variable=VARIABLE**

> Specify the variable name of the ArgumentParser object (for --input-type=python)

---

**--include-file=FILE**

> Include file in output

---

**--comment=COMMENT**

> Add a comment to output

---

**--keep-comments=BOOL** *(True, False)*

> Keep comments of helper functions used in the generated code

This option defaults to `False`.

---

**--function-prefix=PREFIX**

> Set the prefix for generated functions

The placeholder `$PROG` will be replaced by the program name.

This option defaults to `_$PROG`.

---

**--debug**

> Enable debug mode

Keep comments, generate shell code for debugging and print a full stack
trace in case of an error.

---

**-o|--output=FILE**

> Write output to destination file [default: stdout]

---

**-i|--install-system-wide**

> Write output to the system-wide completions dir of shell

---

**-u|--uninstall-system-wide**

> Uninstall the system-wide completion file for program

## When Conditionals

Options and Positional Arguments can include a `when` attribute that defines
a condition under which the option (or positional argument) should be
activated.

### has\_option

> Checks if one or more specified options have been provided on the command line.

> **NOTE**: The options used inside the condition have also to be defined as options!

**Examples:**

```yaml
# This activates --conditional if --foo, --bar or --baz are present on the command line

[...]
options:
  - option_strings: ["--conditional"]
    when: "has_option --foo --bar --baz"

  - option_strings: ["--foo", "--bar", "--baz"]
[...]
```

### option\_is

> Checks if one ore more specified options have been set to a specific value.

> **NOTE**: The options used inside the condition have also to be defined as options!

**Example:**

```yaml
# This activates --conditional if --foo, --bar or --baz are set to value1, value2 or value3

[...]
options:
  - option_strings: ["--conditional"]
    when: "option_is --foo --bar --baz -- value1 value2 value3"

  - option_strings: ["--foo", "--bar", "--baz"]
    complete: ["none"]
[...]
```

### Multiple conditions

> Multiple conditions can be combined using the logical operators `&&` (**AND**) and `||` (**OR**).

> Expressions can be grouped using parentheses `(` and `)` to control evaluation order.

> The negation operator `!` is also supported for logical **NOT** expressions.

**Example:**

```yaml
# This activates --conditional if --foo is given but --bar is not given.

[...]
options:
  - option_strings: ["--conditional"]
    when: "has_option --foo && ! has_option --bar"

  - option_strings: ["--foo"]

  - option_strings: ["--bar"]
[...]
```

## Capturing Options

Options can include a `capture` field to store their values for later use.

The value of `capture` is the **name of a variable** that will receive all values passed to that option.

- The captured variable is always an **array**, containing one element for each occurence of the option on the command line.
- This makes it easy to implement **context-sensitive completions** that depend on previously supplied option values

> **NOTE:** There is currently **no automatic check for name clashes** between your capture variables and the parser's internal variables.
> To minimize the risk of conflicts, it is recommended to prefix variable names with `CAPTURE_` or `CAPTURED_`.

> **NOTE:** Captured variables are currently only available in **Bash** and **Zsh**.

**Example:**

```yaml
prog: my_db_tool
options:
  - option_strings: ["--database", "-d"]
    complete: ["choices", ["mysql", "postgres", "sqlite"]]
    capture: "CAPTURED_DB"

  - option_strings: ["--table", "-t"]
    complete: ["exec", "_my_db_tool_complete_table"]
```

For **Bash** and **Zsh**:

```bash
_my_db_tool_complete_table() {
  case "${CAPTURED_DB[-1]}" in
    mysql)    printf '%s\n' users orders products;;
    postgres) printf '%s\n' customers invoices transactions;;
    sqlite)   printf '%s\n' local_cache config sessions;;
  esac
}
```

## Tips and Tricks

It is always recommended to define your command line **as precisely as possible**.
This helps crazy-complete generate reliable completions. Key practices include:
- **Final options**: Use `final: true` for options like `--help` and `--version` that should
  prevent further options from being completed
- **Hidden options**: Use `hidden: true` for options that should be completable but not shown
  in the suggestion list
- **Mutually exclusive options**: Use `groups: [...]` to define sets of options that cannot appear
    together
- **Repeatable options**: Use `repeatable: true` for options that may be used more than once

### Trying out zsh autocompletion scripts

By default, crazy-complete generates scripts that should be installed under `/usr/share/zsh/site-functions`
and loaded from there. If you want to try the generated scripts directly, use `--zsh-compdef=False`.

### Optimizing Script Output

Especially for **Fish** scripts, performance can decrease if many options are defined.
Features like final options and non-repeatable options require extra conditional code to execute, which can make completions slower.

To improve performance these features can be completely disabled using:

```
crazy-complete fish --disable=final,repeatable DEFINITION_FILE
```

This turns off final and repeatable option handling, reducing script size and improving completion speed