| 1 |
Crazy-Complete Documentation |
| 2 |
============================ |
| 3 |
|
| 4 |
This documentation provides an overview of how to define shell completion for commands using crazy-complete. |
| 5 |
|
| 6 |
- [Generating a Definition File from Help](#generating-a-definition-file-from-help) |
| 7 |
- [Defining a Command](#defining-a-command) |
| 8 |
- [Defining an Option](#defining-an-option) |
| 9 |
- [Defining a Positional Argument](#defining-a-positional-argument) |
| 10 |
- [Using Aliases](#using-aliases) |
| 11 |
- [Completion Commands](#completion-commands) |
| 12 |
- [Meta Commands](#meta-commands) |
| 13 |
- [Built-in Commands](#built-in-commands) |
| 14 |
- [User-Defined Commands](#user-defined-commands) |
| 15 |
- [Bonus Commands](#bonus-commands) |
| 16 |
- [Options](#options) |
| 17 |
- [When Conditionals](#when-conditionals) |
| 18 |
- [Capturing Options](#capturing-options) |
| 19 |
- [Tips and Tricks](#tips-and-tricks) |
| 20 |
|
| 21 |
## Generating a Definition File from Help |
| 22 |
|
| 23 |
It is possible to generate a definition file from a commands help output: |
| 24 |
|
| 25 |
``` |
| 26 |
grep --help > help_file |
| 27 |
crazy-complete --input-type=help yaml help_file |
| 28 |
|
| 29 |
# or |
| 30 |
|
| 31 |
grep --help | crazy-complete --input-type=help yaml /dev/stdin |
| 32 |
``` |
| 33 |
|
| 34 |
## Defining a Command |
| 35 |
|
| 36 |
To define a completion for a command, use the following structure: |
| 37 |
|
| 38 |
```yaml |
| 39 |
prog: "<PROGRAM NAME>" |
| 40 |
aliases: ["<ALIAS>", ...] |
| 41 |
help: "<PROGRAM DESCRIPTION>" |
| 42 |
wraps: "<PROGRAM>" |
| 43 |
options: |
| 44 |
<OPTION ...> |
| 45 |
positionals: |
| 46 |
<POSITIONAL ...> |
| 47 |
``` |
| 48 |
|
| 49 |
- *prog*: The name of the program for which you want to create completion |
| 50 |
- *aliases* (optional): Specify alternative program names for which this completion should also apply |
| 51 |
- *help* (optional): A short description of the program |
| 52 |
- *wraps* (optional): Inherit completion behaviour of another command |
| 53 |
- *options* (optional): A list of [options](#defining-an-option) the program accepts |
| 54 |
- *positionals* (optional): A list of [positional arguments](#defining-a-positional-argument) the program uses |
| 55 |
|
| 56 |
## Defining an Option |
| 57 |
|
| 58 |
To define an option, use this format: |
| 59 |
|
| 60 |
```yaml |
| 61 |
[...] |
| 62 |
options: |
| 63 |
- option_strings: ["<OPTION STRING>", ...] |
| 64 |
metavar: "<METAVAR>" |
| 65 |
help: "<OPTION DESCRIPTION>" |
| 66 |
optional_arg: <BOOL> |
| 67 |
complete: <COMPLETE ACTION> |
| 68 |
nosort: <BOOL> |
| 69 |
repeatable: <BOOL> |
| 70 |
final: <BOOL> |
| 71 |
hidden: <BOOL> |
| 72 |
groups: ["<GROUP>", ...] |
| 73 |
when: "<CONDITION>" |
| 74 |
capture: "<VARIABLE>" |
| 75 |
long_opt_arg_sep: "equals|space|both" |
| 76 |
[...] |
| 77 |
``` |
| 78 |
|
| 79 |
- *option\_strings*: A list of option strings (e.g., ["-h", "--help"]) |
| 80 |
- *metavar* (optional): The placeholder used for the argument (e.g., "FILE") |
| 81 |
- *help* (optional): A description of the option |
| 82 |
- *optional\_arg* (optional): Indicates if the option's argument is optional (default: false) |
| 83 |
- *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) |
| 84 |
- *nosort* (optional): Do not sort completion suggestions alphabetically. Keep them in the order generated by the completer. (true or false, default: false) |
| 85 |
- *repeatable* (optional): Indicates whether an option can be suggested multiple times (true or false, default: false) |
| 86 |
- *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) |
| 87 |
- *hidden* (optional): Specifies whether an option should be excluded from the auto-completion suggestions, though it remains usable when typed manually. (default: false) |
| 88 |
- *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 |
| 89 |
- *when* (optional): Only enable this option if [CONDITION](#when-conditionals) evaluates to true |
| 90 |
- *capture* (optional): Specify the [variable](#capturing-options) where values of this option should be captured |
| 91 |
- *long_opt_arg_sep* (optional): Specifies which separators are used for delimiting a long option from its argument |
| 92 |
|
| 93 |
## Defining a Positional Argument |
| 94 |
|
| 95 |
Positional arguments are defined as follows: |
| 96 |
|
| 97 |
```yaml |
| 98 |
[...] |
| 99 |
positionals: |
| 100 |
- number: <NUMBER> |
| 101 |
metavar: "<METAVAR>" |
| 102 |
help: "<POSITIONAL DESCRIPTION>" |
| 103 |
repeatable: <BOOL> |
| 104 |
complete: <COMPLETE ACTION> |
| 105 |
nosort: <BOOL> |
| 106 |
when: "<CONDITION>" |
| 107 |
[...] |
| 108 |
``` |
| 109 |
|
| 110 |
- *number*: The order of the positional argument (e.g., 1 for the first argument) |
| 111 |
- *metavar* (optional): A placeholder for the positional argument in the help text |
| 112 |
- *help* (optional): A description of the positional argument |
| 113 |
- *repeatable* (optional): Indicates if this positional argument can be repeated (true or false, default: false) |
| 114 |
- *complete* (optional): The method used to generate possible completions for this positional argument. Default `["none"]`. See [Completion Commands](#completion-commands). |
| 115 |
- *nosort* (optional): Do not sort completion suggestions alphabetically. Keep them in the order generated by the completer. (true or false, default: false) |
| 116 |
- *when* (optional): Only enable this positional if [CONDITION](#when-conditionals) evaluates to true |
| 117 |
|
| 118 |
### Using Aliases |
| 119 |
|
| 120 |
Aliases / defines can be handy if completers are reused or to keep the definition file clean. |
| 121 |
|
| 122 |
**NOTE:** Every defined string is replaced throughout the YAML document, regardless of its context. |
| 123 |
|
| 124 |
```yaml |
| 125 |
prog: '%defines%' |
| 126 |
complete_bool: ['choices', ['true', 'false']] |
| 127 |
--- |
| 128 |
prog: "example" |
| 129 |
options: |
| 130 |
- option_strings: ['--option-1'] |
| 131 |
complete: 'complete_bool' |
| 132 |
|
| 133 |
- option_strings: ['--option-2'] |
| 134 |
complete: 'complete_bool' |
| 135 |
``` |
| 136 |
|
| 137 |
## Defining Subcommands |
| 138 |
|
| 139 |
To define subcommands, append the subcommand name directly to the program name: |
| 140 |
|
| 141 |
```yaml |
| 142 |
prog: "<PROGRAM NAME> <SUBCOMMAND> ..." |
| 143 |
aliases: ["<ALIAS>", ...] |
| 144 |
help: "<SUBCOMMAND DESCRIPTION>" |
| 145 |
[...] |
| 146 |
``` |
| 147 |
|
| 148 |
- *prog*: The name of the program, followed by the subcommand(s) |
| 149 |
- *aliases* (optional): A list of alternative names for the subcommand. Aliases must not include the program name |
| 150 |
- *help* (optional): A description of the subcommand |
| 151 |
|
| 152 |
## Completion Commands |
| 153 |
|
| 154 |
### Meta commands |
| 155 |
|
| 156 |
| Command | Description | |
| 157 |
| ----------------------------------- | ------------------------------------------------------- | |
| 158 |
| [combine](#combine) | Combine multiple completers | |
| 159 |
| [key\_value\_list](#key_value_list) | Complete comma-separated lists of key=value pairs | |
| 160 |
| [key\_value\_pair](#key_value_pair) | Complete single key=value pairs | |
| 161 |
| [list](#list) | Complete comma-separated lists using a completer | |
| 162 |
| [none](#none) | No completion, but specify that an argument is required | |
| 163 |
| [prefix](#prefix) | Prefix completions with a string | |
| 164 |
|
| 165 |
--- |
| 166 |
|
| 167 |
### Built-in commands |
| 168 |
|
| 169 |
| Command | Description | |
| 170 |
| ------------------------------------------ | --------------------------------------------- | |
| 171 |
| [choices](#choices) | Complete from a predefined set of values | |
| 172 |
| [command](#command) | Complete command names | |
| 173 |
| [command\_arg](#command_arg) | Complete command arguments | |
| 174 |
| [commandline\_string](#commandline_string) | Complete command lines as strings | |
| 175 |
| [date](#date) | Complete date strings | |
| 176 |
| [date\_format](#date_format) | Complete date format strings | |
| 177 |
| [directory](#directory) | Complete directory names | |
| 178 |
| [directory\_list](#directory_list) | Complete comma-separated lists of directories | |
| 179 |
| [environment](#environment) | Complete environment variable names | |
| 180 |
| [file](#file) | Complete file names | |
| 181 |
| [file\_list](#file_list) | Complete comma-separated lists of files | |
| 182 |
| [filesystem\_type](#filesystem_type) | Complete filesystem types | |
| 183 |
| [float](#float) | Complete floating-point values | |
| 184 |
| [gid](#gid) | Complete group IDs | |
| 185 |
| [group](#group) | Complete group names | |
| 186 |
| [history](#history) | Complete based on a shell's history | |
| 187 |
| [hostname](#hostname) | Complete hostnames | |
| 188 |
| [integer](#integer) | Complete integer values | |
| 189 |
| [ip\_address](#ip_address) | Complete local IP addresses | |
| 190 |
| [mime\_file](#mime_file) | Complete files by MIME type | |
| 191 |
| [pid](#pid) | Complete process IDs | |
| 192 |
| [process](#process) | Complete process names | |
| 193 |
| [range](#range) | Complete sequences of integers | |
| 194 |
| [service](#service) | Complete systemd service names | |
| 195 |
| [signal](#signal) | Complete signal names | |
| 196 |
| [uid](#uid) | Complete user IDs | |
| 197 |
| [user](#user) | Complete user names | |
| 198 |
| [value\_list](#value_list) | Complete comma-separated lists of values | |
| 199 |
| [variable](#variable) | Complete shell variable names | |
| 200 |
|
| 201 |
--- |
| 202 |
|
| 203 |
### User-defined commands |
| 204 |
|
| 205 |
| Command | Description | |
| 206 |
| ---------------------------------------------- | -------------------------------------------------------------------------- | |
| 207 |
| [exec](#exec) | Complete values from the output of a command or function | |
| 208 |
| [exec\_fast](#exec_fast) | Complete values from the output of a command or function (fast and unsafe) | |
| 209 |
| [exec\_internal](#exec_internal) | Use the shell's internal completion mechanisms | |
| 210 |
| [key\_value\_list\_exec](#key_value_list_exec) | Complete dynamically generated comma-separted lists of key=value pairs | |
| 211 |
| [key\_value\_pair\_exec](#key_value_pair_exec) | Complete dynamically generated a key=value pairs | |
| 212 |
|
| 213 |
--- |
| 214 |
|
| 215 |
### Bonus commands |
| 216 |
|
| 217 |
| Command | Description | |
| 218 |
| -------------------------------- | --------------------------- | |
| 219 |
| [alsa\_card](#alsa_card) | Complete ALSA cards | |
| 220 |
| [alsa\_device](#alsa_device) | Complete ALSA devices | |
| 221 |
| [charset](#charset) | Complete character sets | |
| 222 |
| [locale](#locale) | Complete locales | |
| 223 |
| [login\_shell](#login_shell) | Complete login shells | |
| 224 |
| [mountpoint](#mountpoint) | Complete mount points | |
| 225 |
| [net\_interface](#net_interface) | Complete network interfaces | |
| 226 |
| [timezone](#timezone) | Complete timezones | |
| 227 |
|
| 228 |
--- |
| 229 |
|
| 230 |
### alsa\_card |
| 231 |
|
| 232 |
> Complete ALSA cards |
| 233 |
|
| 234 |
**SYNOPSIS** |
| 235 |
|
| 236 |
```yaml |
| 237 |
['alsa_card'] |
| 238 |
``` |
| 239 |
|
| 240 |
**EXAMPLE** |
| 241 |
|
| 242 |
```yaml |
| 243 |
prog: 'example' |
| 244 |
options: |
| 245 |
- option_strings: ['--alsa-card'] |
| 246 |
complete: ['alsa_card'] |
| 247 |
``` |
| 248 |
|
| 249 |
``` |
| 250 |
~ > example --alsa-card=<TAB> |
| 251 |
0 1 |
| 252 |
``` |
| 253 |
|
| 254 |
**SEE ALSO** |
| 255 |
|
| 256 |
- [alsa\_device](#alsa_device): For completing ALSA devices |
| 257 |
|
| 258 |
--- |
| 259 |
|
| 260 |
### alsa\_device |
| 261 |
|
| 262 |
> Complete ALSA devices |
| 263 |
|
| 264 |
**SYNOPSIS** |
| 265 |
|
| 266 |
```yaml |
| 267 |
['alsa_device'] |
| 268 |
``` |
| 269 |
|
| 270 |
**EXAMPLE** |
| 271 |
|
| 272 |
```yaml |
| 273 |
prog: 'example' |
| 274 |
options: |
| 275 |
- option_strings: ['--alsa-device'] |
| 276 |
complete: ['alsa_device'] |
| 277 |
``` |
| 278 |
|
| 279 |
``` |
| 280 |
~ > example --alsa-device=<TAB> |
| 281 |
hw:0 hw:1 |
| 282 |
``` |
| 283 |
|
| 284 |
**SEE ALSO** |
| 285 |
|
| 286 |
- [alsa\_card](#alsa_card): For completing ALSA cards |
| 287 |
|
| 288 |
--- |
| 289 |
|
| 290 |
### charset |
| 291 |
|
| 292 |
> Complete character sets |
| 293 |
|
| 294 |
**SYNOPSIS** |
| 295 |
|
| 296 |
```yaml |
| 297 |
['charset'] |
| 298 |
``` |
| 299 |
|
| 300 |
**EXAMPLE** |
| 301 |
|
| 302 |
```yaml |
| 303 |
prog: 'example' |
| 304 |
options: |
| 305 |
- option_strings: ['--charset'] |
| 306 |
complete: ['charset'] |
| 307 |
``` |
| 308 |
|
| 309 |
``` |
| 310 |
~ > example --charset=A<TAB> |
| 311 |
ANSI_X3.110-1983 ANSI_X3.4-1968 ARMSCII-8 ASMO_449 |
| 312 |
``` |
| 313 |
|
| 314 |
--- |
| 315 |
|
| 316 |
### locale |
| 317 |
|
| 318 |
> Complete locales |
| 319 |
|
| 320 |
**SYNOPSIS** |
| 321 |
|
| 322 |
```yaml |
| 323 |
['locale'] |
| 324 |
``` |
| 325 |
|
| 326 |
**EXAMPLE** |
| 327 |
|
| 328 |
```yaml |
| 329 |
prog: 'example' |
| 330 |
options: |
| 331 |
- option_strings: ['--locale'] |
| 332 |
complete: ['locale'] |
| 333 |
``` |
| 334 |
|
| 335 |
``` |
| 336 |
~ > example --locale=<TAB> |
| 337 |
C C.UTF-8 de_DE de_DE@euro de_DE.iso88591 de_DE.iso885915@euro |
| 338 |
de_DE.UTF-8 deutsch en_US en_US.iso88591 en_US.UTF-8 german POSIX |
| 339 |
``` |
| 340 |
|
| 341 |
--- |
| 342 |
|
| 343 |
### login\_shell |
| 344 |
|
| 345 |
> Complete login shells |
| 346 |
|
| 347 |
**SYNOPSIS** |
| 348 |
|
| 349 |
```yaml |
| 350 |
['login_shell'] |
| 351 |
``` |
| 352 |
|
| 353 |
**EXAMPLE** |
| 354 |
|
| 355 |
```yaml |
| 356 |
prog: 'example' |
| 357 |
options: |
| 358 |
- option_strings: ['--login-shell'] |
| 359 |
complete: ['login_shell'] |
| 360 |
``` |
| 361 |
|
| 362 |
``` |
| 363 |
~ > example --login-shell=<TAB> |
| 364 |
/bin/bash /bin/sh /usr/bin/fish /usr/bin/sh |
| 365 |
[...] |
| 366 |
``` |
| 367 |
|
| 368 |
--- |
| 369 |
|
| 370 |
### mountpoint |
| 371 |
|
| 372 |
> Complete mount points |
| 373 |
|
| 374 |
**SYNOPSIS** |
| 375 |
|
| 376 |
```yaml |
| 377 |
['mountpoint'] |
| 378 |
``` |
| 379 |
|
| 380 |
**EXAMPLE** |
| 381 |
|
| 382 |
```yaml |
| 383 |
prog: 'example' |
| 384 |
options: |
| 385 |
- option_strings: ['--mountpoint'] |
| 386 |
complete: ['mountpoint'] |
| 387 |
``` |
| 388 |
|
| 389 |
``` |
| 390 |
~ > example --mountpoint=<TAB> |
| 391 |
/ /boot /home /proc /run /sys /tmp |
| 392 |
[...] |
| 393 |
``` |
| 394 |
|
| 395 |
--- |
| 396 |
|
| 397 |
### net\_interface |
| 398 |
|
| 399 |
> Complete network interfaces |
| 400 |
|
| 401 |
**SYNOPSIS** |
| 402 |
|
| 403 |
```yaml |
| 404 |
['net_interface'] |
| 405 |
``` |
| 406 |
|
| 407 |
**EXAMPLE** |
| 408 |
|
| 409 |
```yaml |
| 410 |
prog: 'example' |
| 411 |
options: |
| 412 |
- option_strings: ['--net-interface'] |
| 413 |
complete: ['net_interface'] |
| 414 |
``` |
| 415 |
|
| 416 |
``` |
| 417 |
~ > example --net-interface=<TAB> |
| 418 |
eno1 enp1s0 lo wlo1 wlp2s0 |
| 419 |
[...] |
| 420 |
``` |
| 421 |
|
| 422 |
**SEE ALSO** |
| 423 |
|
| 424 |
- [ip\_address](#ip_address): For completing IP addresses |
| 425 |
|
| 426 |
--- |
| 427 |
|
| 428 |
### timezone |
| 429 |
|
| 430 |
> Complete timezones |
| 431 |
|
| 432 |
**SYNOPSIS** |
| 433 |
|
| 434 |
```yaml |
| 435 |
['timezone'] |
| 436 |
``` |
| 437 |
|
| 438 |
**EXAMPLE** |
| 439 |
|
| 440 |
```yaml |
| 441 |
prog: 'example' |
| 442 |
options: |
| 443 |
- option_strings: ['--timezone'] |
| 444 |
complete: ['timezone'] |
| 445 |
``` |
| 446 |
|
| 447 |
``` |
| 448 |
~ > example --timezone=Europe/B<TAB> |
| 449 |
Belfast Belgrade Berlin Bratislava |
| 450 |
Brussels Bucharest Budapest Busingen |
| 451 |
``` |
| 452 |
|
| 453 |
--- |
| 454 |
|
| 455 |
### choices |
| 456 |
|
| 457 |
> Complete from a predefined set of values |
| 458 |
|
| 459 |
**SYNOPSIS** |
| 460 |
|
| 461 |
```yaml |
| 462 |
['choices', <ITEMS>] |
| 463 |
``` |
| 464 |
|
| 465 |
**PARAMETERS** |
| 466 |
|
| 467 |
`ITEMS`: |
| 468 |
A list or dictionary containing the values to offer for completion. |
| 469 |
|
| 470 |
If a list is supplied, all items are offered without descriptions. |
| 471 |
|
| 472 |
If a dictionary is supplied, the keys are used as completion values and the |
| 473 |
values are used as descriptions. |
| 474 |
|
| 475 |
|
| 476 |
**NOTES** |
| 477 |
|
| 478 |
- If the completion suggestions should appear in their original order, set `nosort` to `true` |
| 479 |
|
| 480 |
**EXAMPLE** |
| 481 |
|
| 482 |
```yaml |
| 483 |
prog: 'example' |
| 484 |
options: |
| 485 |
- option_strings: ['--choices-1'] |
| 486 |
complete: ['choices', ['Item 1', 'Item 2']] |
| 487 |
|
| 488 |
- option_strings: ['--choices-2'] |
| 489 |
complete: ['choices', {'Item 1': 'Description 1', 'Item 2': 'Description 2'}] |
| 490 |
|
| 491 |
- option_strings: ['--choices-keep-order'] |
| 492 |
complete: ['choices', ['zebra', 'cat', 'monkey']] |
| 493 |
nosort: true |
| 494 |
``` |
| 495 |
|
| 496 |
``` |
| 497 |
~ > example --choices-2=<TAB> |
| 498 |
Item 1 (Description 1) Item 2 (Description 2) |
| 499 |
|
| 500 |
~ > example --choices-keep-order=<TAB> |
| 501 |
zebra cat monkey |
| 502 |
``` |
| 503 |
|
| 504 |
--- |
| 505 |
|
| 506 |
### command |
| 507 |
|
| 508 |
> Complete command names |
| 509 |
|
| 510 |
**SYNOPSIS** |
| 511 |
|
| 512 |
```yaml |
| 513 |
['command'] |
| 514 |
|
| 515 |
['command', <OPTIONS>] |
| 516 |
``` |
| 517 |
|
| 518 |
**PARAMETERS** |
| 519 |
|
| 520 |
This completer provides completion suggestions for executable commands available in the system's `$PATH`. |
| 521 |
|
| 522 |
`OPTIONS`: |
| 523 |
A dictionary containing additional options for configuring the completion. |
| 524 |
|
| 525 |
- `path`: |
| 526 |
Override the default `$PATH` used for searching executables. |
| 527 |
|
| 528 |
- `path_append`: |
| 529 |
Append directories to the default `$PATH`. |
| 530 |
|
| 531 |
- `path_prepend`: |
| 532 |
Prepend directories to the default `$PATH`. |
| 533 |
|
| 534 |
|
| 535 |
**NOTES** |
| 536 |
|
| 537 |
- `path_append` and `path_prepend` can be used together, but both are mutually exclusive with `path`. |
| 538 |
|
| 539 |
**EXAMPLE** |
| 540 |
|
| 541 |
```yaml |
| 542 |
prog: 'example' |
| 543 |
options: |
| 544 |
- option_strings: ['--command'] |
| 545 |
complete: ['command'] |
| 546 |
|
| 547 |
- option_strings: ['--command-sbin'] |
| 548 |
complete: ['command', {'path_append': '/sbin:/usr/sbin'}] |
| 549 |
``` |
| 550 |
|
| 551 |
``` |
| 552 |
~ > example --command=bas<TAB> |
| 553 |
base32 base64 basename basenc bash bashbug |
| 554 |
``` |
| 555 |
|
| 556 |
**SEE ALSO** |
| 557 |
|
| 558 |
- [command\_arg](#command_arg): For completing arguments of a command |
| 559 |
|
| 560 |
- [commandline\_string](#commandline_string): For completing command lines as strings |
| 561 |
|
| 562 |
--- |
| 563 |
|
| 564 |
### command\_arg |
| 565 |
|
| 566 |
> Complete command arguments |
| 567 |
|
| 568 |
**SYNOPSIS** |
| 569 |
|
| 570 |
```yaml |
| 571 |
['command_arg'] |
| 572 |
``` |
| 573 |
|
| 574 |
**NOTES** |
| 575 |
|
| 576 |
- This completer can only be used in combination with a previously defined `command` completer. |
| 577 |
|
| 578 |
- This completer requires `repeatable: true`. |
| 579 |
|
| 580 |
**EXAMPLE** |
| 581 |
|
| 582 |
```yaml |
| 583 |
prog: 'example' |
| 584 |
positionals: |
| 585 |
- number: 1 |
| 586 |
complete: ['command'] |
| 587 |
|
| 588 |
- number: 2 |
| 589 |
complete: ['command_arg'] |
| 590 |
repeatable: true |
| 591 |
``` |
| 592 |
|
| 593 |
``` |
| 594 |
~ > example sudo bas<TAB> |
| 595 |
base32 base64 basename basenc bash bashbug |
| 596 |
``` |
| 597 |
|
| 598 |
**SEE ALSO** |
| 599 |
|
| 600 |
- [command](#command): For completing command names |
| 601 |
|
| 602 |
- [commandline\_string](#commandline_string): For completing command lines as strings |
| 603 |
|
| 604 |
--- |
| 605 |
|
| 606 |
### commandline\_string |
| 607 |
|
| 608 |
> Complete command lines as strings |
| 609 |
|
| 610 |
**SYNOPSIS** |
| 611 |
|
| 612 |
```yaml |
| 613 |
['commandline_string'] |
| 614 |
``` |
| 615 |
|
| 616 |
**EXAMPLE** |
| 617 |
|
| 618 |
```yaml |
| 619 |
prog: 'example' |
| 620 |
options: |
| 621 |
- option_strings: ['--commandline'] |
| 622 |
complete: ['commandline_string'] |
| 623 |
``` |
| 624 |
|
| 625 |
``` |
| 626 |
~ > example --commandline='sudo ba<TAB> |
| 627 |
base32 base64 basename basenc bash bashbug |
| 628 |
``` |
| 629 |
|
| 630 |
**SEE ALSO** |
| 631 |
|
| 632 |
- [command](#command): For completing command names |
| 633 |
|
| 634 |
- [command\_arg](#command_arg): For completing command arguments |
| 635 |
|
| 636 |
--- |
| 637 |
|
| 638 |
### date |
| 639 |
|
| 640 |
> Complete date strings |
| 641 |
|
| 642 |
**SYNOPSIS** |
| 643 |
|
| 644 |
```yaml |
| 645 |
['date', <FORMAT>] |
| 646 |
``` |
| 647 |
|
| 648 |
**PARAMETERS** |
| 649 |
|
| 650 |
`FORMAT`: |
| 651 |
The date format as described in `strftime(3)`. |
| 652 |
|
| 653 |
|
| 654 |
**NOTES** |
| 655 |
|
| 656 |
- This completer is currently only implemented in **Zsh**. |
| 657 |
|
| 658 |
**EXAMPLE** |
| 659 |
|
| 660 |
```yaml |
| 661 |
prog: 'example' |
| 662 |
options: |
| 663 |
- option_strings: ['--date'] |
| 664 |
complete: ['date', '%Y-%m-%d'] |
| 665 |
``` |
| 666 |
|
| 667 |
``` |
| 668 |
~ > example --date=<TAB> |
| 669 |
|
| 670 |
November |
| 671 |
Mo Tu We Th Fr Sa Su |
| 672 |
1 2 3 4 5 6 |
| 673 |
7 8 9 10 11 12 13 |
| 674 |
14 15 16 17 18 19 20 |
| 675 |
21 22 23 24 25 26 27 |
| 676 |
28 29 30 |
| 677 |
``` |
| 678 |
|
| 679 |
**SEE ALSO** |
| 680 |
|
| 681 |
- [date\_format](#date_format): For completing date format strings |
| 682 |
|
| 683 |
--- |
| 684 |
|
| 685 |
### date\_format |
| 686 |
|
| 687 |
> Complete date format strings |
| 688 |
|
| 689 |
**SYNOPSIS** |
| 690 |
|
| 691 |
```yaml |
| 692 |
['date_format'] |
| 693 |
``` |
| 694 |
|
| 695 |
**NOTES** |
| 696 |
|
| 697 |
- This completer is currently only implemented in **Fish** and **Zsh**. |
| 698 |
|
| 699 |
**EXAMPLE** |
| 700 |
|
| 701 |
```yaml |
| 702 |
prog: 'example' |
| 703 |
options: |
| 704 |
- option_strings: ['--date-format'] |
| 705 |
complete: ['date_format'] |
| 706 |
``` |
| 707 |
|
| 708 |
``` |
| 709 |
~ > example --date-format '%<TAB> |
| 710 |
a -- abbreviated day name |
| 711 |
A -- full day name |
| 712 |
B -- full month name |
| 713 |
c -- preferred locale date and time |
| 714 |
C -- 2-digit century |
| 715 |
d -- day of month (01-31) |
| 716 |
D -- American format month/day/year (%m/%d/%y) |
| 717 |
e -- day of month ( 1-31) |
| 718 |
[...] |
| 719 |
``` |
| 720 |
|
| 721 |
**SEE ALSO** |
| 722 |
|
| 723 |
- [date](#date): For completing dates |
| 724 |
|
| 725 |
--- |
| 726 |
|
| 727 |
### directory |
| 728 |
|
| 729 |
> Complete directory names |
| 730 |
|
| 731 |
**SYNOPSIS** |
| 732 |
|
| 733 |
```yaml |
| 734 |
['directory'] |
| 735 |
|
| 736 |
['directory', <OPTIONS>] |
| 737 |
``` |
| 738 |
|
| 739 |
**PARAMETERS** |
| 740 |
|
| 741 |
`OPTIONS`: |
| 742 |
A dictionary containing additional options for configuring the completion. |
| 743 |
|
| 744 |
- `directory`: Restrict completion to directories inside the specified directory. |
| 745 |
|
| 746 |
|
| 747 |
**EXAMPLE** |
| 748 |
|
| 749 |
```yaml |
| 750 |
prog: 'example' |
| 751 |
options: |
| 752 |
- option_strings: ['--directory'] |
| 753 |
complete: ['directory'] |
| 754 |
|
| 755 |
- option_strings: ['--directory-tmp'] |
| 756 |
complete: ['directory', {'directory': '/tmp'}] |
| 757 |
``` |
| 758 |
|
| 759 |
``` |
| 760 |
~ > example --directory=<TAB> |
| 761 |
dir1/ dir2/ |
| 762 |
``` |
| 763 |
|
| 764 |
**SEE ALSO** |
| 765 |
|
| 766 |
- [directory\_list](#directory_list): For completing comma-separated lists of directories |
| 767 |
|
| 768 |
--- |
| 769 |
|
| 770 |
### directory\_list |
| 771 |
|
| 772 |
> Complete comma-separated lists of directories |
| 773 |
|
| 774 |
**SYNOPSIS** |
| 775 |
|
| 776 |
```yaml |
| 777 |
['directory_list'] |
| 778 |
|
| 779 |
['directory_list', <OPTIONS>] |
| 780 |
``` |
| 781 |
|
| 782 |
**PARAMETERS** |
| 783 |
|
| 784 |
This is an alias for `['list', ['directory']]`. |
| 785 |
|
| 786 |
`OPTIONS`: |
| 787 |
A dictionary containing additional options for configuring the completion. |
| 788 |
|
| 789 |
- `directory`: |
| 790 |
Restrict completion to directories inside the specified directory. |
| 791 |
|
| 792 |
- `duplicates`: |
| 793 |
Allow duplicate values to be offered for completion. Defaults to `false`. |
| 794 |
|
| 795 |
- `separator`: |
| 796 |
The separator used between list elements. Defaults to `,`. |
| 797 |
|
| 798 |
|
| 799 |
**EXAMPLE** |
| 800 |
|
| 801 |
```yaml |
| 802 |
prog: 'example' |
| 803 |
options: |
| 804 |
- option_strings: ['--directory-list'] |
| 805 |
complete: ['directory_list'] |
| 806 |
``` |
| 807 |
|
| 808 |
``` |
| 809 |
~ > example --directory-list=directory1,directory2,<TAB> |
| 810 |
directory3 directory4 |
| 811 |
``` |
| 812 |
|
| 813 |
**SEE ALSO** |
| 814 |
|
| 815 |
- [list](#list): For completion comma-separated lists using a completer |
| 816 |
|
| 817 |
- [directory](#directory): For completing directory names |
| 818 |
|
| 819 |
- [file\_list](#file_list): For completing comma-separated lists of files |
| 820 |
|
| 821 |
--- |
| 822 |
|
| 823 |
### environment |
| 824 |
|
| 825 |
> Complete environment variable names |
| 826 |
|
| 827 |
**SYNOPSIS** |
| 828 |
|
| 829 |
```yaml |
| 830 |
['environment'] |
| 831 |
``` |
| 832 |
|
| 833 |
**EXAMPLE** |
| 834 |
|
| 835 |
```yaml |
| 836 |
prog: 'example' |
| 837 |
options: |
| 838 |
- option_strings: ['--environment'] |
| 839 |
complete: ['environment'] |
| 840 |
``` |
| 841 |
|
| 842 |
``` |
| 843 |
~ > example --environment=X<TAB> |
| 844 |
XDG_RUNTIME_DIR XDG_SEAT XDG_SESSION_CLASS XDG_SESSION_ID |
| 845 |
XDG_SESSION_TYPE XDG_VTNR |
| 846 |
``` |
| 847 |
|
| 848 |
**SEE ALSO** |
| 849 |
|
| 850 |
- [variable](#variable): For completing shell variable names |
| 851 |
|
| 852 |
--- |
| 853 |
|
| 854 |
### file |
| 855 |
|
| 856 |
> Complete file names |
| 857 |
|
| 858 |
**SYNOPSIS** |
| 859 |
|
| 860 |
```yaml |
| 861 |
['file'] |
| 862 |
|
| 863 |
['file', <OPTIONS>] |
| 864 |
``` |
| 865 |
|
| 866 |
**PARAMETERS** |
| 867 |
|
| 868 |
`OPTIONS`: |
| 869 |
A dictionary containing additional options for configuring the completion. |
| 870 |
|
| 871 |
- `directory`: Restrict completion to files inside the specified directory. |
| 872 |
|
| 873 |
- `extensions`: A list of file extensions to offer for completion. |
| 874 |
|
| 875 |
- `fuzzy`: |
| 876 |
Enable fuzzy extension matching. |
| 877 |
By default, files must end with one of the specified extensions. |
| 878 |
With fuzzy matching enabled, files with additional suffixes are also matched, for example `foo.txt.1`. |
| 879 |
|
| 880 |
- `ignore_globs`: |
| 881 |
A list of Bash globs for files that should not be offered for completion. |
| 882 |
|
| 883 |
**NOTE:** Restricting completion to specific file extensions only makes sense |
| 884 |
if the program being completed actually expects files of those types. On |
| 885 |
Unix-like systems, file extensions generally have no inherent meaning and are |
| 886 |
only conventions. |
| 887 |
|
| 888 |
|
| 889 |
**EXAMPLE** |
| 890 |
|
| 891 |
```yaml |
| 892 |
prog: 'example' |
| 893 |
options: |
| 894 |
- option_strings: ['--file'] |
| 895 |
complete: ['file'] |
| 896 |
|
| 897 |
- option_strings: ['--file-tmp'] |
| 898 |
complete: ['file', {'directory': '/tmp'}] |
| 899 |
|
| 900 |
- option_strings: ['--file-ext'] |
| 901 |
complete: ['file', {'extensions': ['c', 'cpp']}] |
| 902 |
|
| 903 |
- option_strings: ['--file-ignore'] |
| 904 |
complete: ['file', {'ignore_globs': ['*.[tT][xX][tT]', '*.c++']}] |
| 905 |
``` |
| 906 |
|
| 907 |
``` |
| 908 |
~ > example --file=<TAB> |
| 909 |
dir1/ dir2/ file1 file2 |
| 910 |
|
| 911 |
~ > example --file-ext=<TAB> |
| 912 |
dir1/ dir2/ file.c file.cpp |
| 913 |
``` |
| 914 |
|
| 915 |
**SEE ALSO** |
| 916 |
|
| 917 |
- [file\_list](#file_list): For completing comma-separated lists of files |
| 918 |
|
| 919 |
- [mime\_file](#mime_file): For completing files by MIME type |
| 920 |
|
| 921 |
--- |
| 922 |
|
| 923 |
### file\_list |
| 924 |
|
| 925 |
> Complete comma-separated lists of files |
| 926 |
|
| 927 |
**SYNOPSIS** |
| 928 |
|
| 929 |
```yaml |
| 930 |
['file_list'] |
| 931 |
|
| 932 |
['file_list', <OPTIONS>] |
| 933 |
``` |
| 934 |
|
| 935 |
**PARAMETERS** |
| 936 |
|
| 937 |
This is an alias for `['list', ['file']]`. |
| 938 |
|
| 939 |
`OPTIONS`: |
| 940 |
A dictionary containing additional options for configuring the completion. |
| 941 |
|
| 942 |
- `directory`: |
| 943 |
Restrict completion to files inside the specified directory. |
| 944 |
|
| 945 |
- `extensions`: |
| 946 |
A list of file extensions to offer for completion. |
| 947 |
|
| 948 |
- `fuzzy`: |
| 949 |
Enable fuzzy extension matching. By default, files must end with one of |
| 950 |
the specified extensions. With fuzzy matching enabled, files with |
| 951 |
additional suffixes are also matched, for example `foo.txt.1`. |
| 952 |
|
| 953 |
- `ignore_globs`: |
| 954 |
A list of Bash globs for files that should not be offered for completion. |
| 955 |
|
| 956 |
- `duplicates`: |
| 957 |
Allow duplicate values to be offered for completion. Defaults to `false`. |
| 958 |
|
| 959 |
- `separator`: |
| 960 |
The separator used between list elements. Defaults to `,`. |
| 961 |
|
| 962 |
|
| 963 |
**EXAMPLE** |
| 964 |
|
| 965 |
```yaml |
| 966 |
prog: 'example' |
| 967 |
options: |
| 968 |
- option_strings: ['--file-list'] |
| 969 |
complete: ['file_list'] |
| 970 |
``` |
| 971 |
|
| 972 |
``` |
| 973 |
~ > example --file-list=file1,file2,<TAB> |
| 974 |
file3 file4 |
| 975 |
``` |
| 976 |
|
| 977 |
**SEE ALSO** |
| 978 |
|
| 979 |
- [list](#list): For completing comma-separted lists using a completer |
| 980 |
|
| 981 |
- [file](#file): For completing file names |
| 982 |
|
| 983 |
- [directory\_list](#directory_list): For completing comma-separated lists of directories |
| 984 |
|
| 985 |
--- |
| 986 |
|
| 987 |
### filesystem\_type |
| 988 |
|
| 989 |
> Complete filesystem types |
| 990 |
|
| 991 |
**SYNOPSIS** |
| 992 |
|
| 993 |
```yaml |
| 994 |
['filesystem_type'] |
| 995 |
``` |
| 996 |
|
| 997 |
**EXAMPLE** |
| 998 |
|
| 999 |
```yaml |
| 1000 |
prog: 'example' |
| 1001 |
options: |
| 1002 |
- option_strings: ['--filesystem-type'] |
| 1003 |
complete: ['filesystem_type'] |
| 1004 |
``` |
| 1005 |
|
| 1006 |
``` |
| 1007 |
~ > example --filesystem-type=<TAB> |
| 1008 |
adfs autofs bdev bfs binder binfmt_misc bpf |
| 1009 |
cgroup cgroup2 configfs cramfs debugfs devpts devtmpfs |
| 1010 |
[...] |
| 1011 |
``` |
| 1012 |
|
| 1013 |
--- |
| 1014 |
|
| 1015 |
### float |
| 1016 |
|
| 1017 |
> Complete floating-point values |
| 1018 |
|
| 1019 |
**SYNOPSIS** |
| 1020 |
|
| 1021 |
```yaml |
| 1022 |
['float'] |
| 1023 |
|
| 1024 |
['float', <OPTIONS>] |
| 1025 |
``` |
| 1026 |
|
| 1027 |
**PARAMETERS** |
| 1028 |
|
| 1029 |
`OPTIONS`: |
| 1030 |
A dictionary containing additional options for configuring the completion. |
| 1031 |
|
| 1032 |
- `min`: The minimum allowed value. |
| 1033 |
|
| 1034 |
- `max`: The maximum allowed value. |
| 1035 |
|
| 1036 |
- `suffixes`: A dictionary of suffixes and their descriptions. The suffix is appended to the completed value. |
| 1037 |
|
| 1038 |
- `help`: The help text shown during completion. If not specified, the `help` attribute of the option is used. |
| 1039 |
|
| 1040 |
|
| 1041 |
**EXAMPLE** |
| 1042 |
|
| 1043 |
```yaml |
| 1044 |
prog: 'example' |
| 1045 |
options: |
| 1046 |
- option_strings: ['--time'] |
| 1047 |
complete: ['float', {'suffixes': {'s': 'seconds', 'm': 'minutes', 'h': 'hours'}}] |
| 1048 |
``` |
| 1049 |
|
| 1050 |
``` |
| 1051 |
~ > example --time=3.0<TAB> |
| 1052 |
s -- seconds m -- minutes h -- hours |
| 1053 |
``` |
| 1054 |
|
| 1055 |
**SEE ALSO** |
| 1056 |
|
| 1057 |
- [integer](#integer): For completing integer values |
| 1058 |
|
| 1059 |
--- |
| 1060 |
|
| 1061 |
### gid |
| 1062 |
|
| 1063 |
> Complete group IDs |
| 1064 |
|
| 1065 |
**SYNOPSIS** |
| 1066 |
|
| 1067 |
```yaml |
| 1068 |
['gid'] |
| 1069 |
``` |
| 1070 |
|
| 1071 |
**EXAMPLE** |
| 1072 |
|
| 1073 |
```yaml |
| 1074 |
prog: 'example' |
| 1075 |
options: |
| 1076 |
- option_strings: ['--gid'] |
| 1077 |
complete: ['gid'] |
| 1078 |
``` |
| 1079 |
|
| 1080 |
``` |
| 1081 |
~ > example --gid=<TAB> |
| 1082 |
0 -- root |
| 1083 |
1000 -- braph |
| 1084 |
102 -- polkitd |
| 1085 |
108 -- vboxusers |
| 1086 |
11 -- ftp |
| 1087 |
12 -- mail |
| 1088 |
133 -- rtkit |
| 1089 |
19 -- log |
| 1090 |
[...] |
| 1091 |
``` |
| 1092 |
|
| 1093 |
**SEE ALSO** |
| 1094 |
|
| 1095 |
- [group](#group): For completing group names |
| 1096 |
|
| 1097 |
--- |
| 1098 |
|
| 1099 |
### group |
| 1100 |
|
| 1101 |
> Complete group names |
| 1102 |
|
| 1103 |
**SYNOPSIS** |
| 1104 |
|
| 1105 |
```yaml |
| 1106 |
['group'] |
| 1107 |
``` |
| 1108 |
|
| 1109 |
**EXAMPLE** |
| 1110 |
|
| 1111 |
```yaml |
| 1112 |
prog: 'example' |
| 1113 |
options: |
| 1114 |
- option_strings: ['--group'] |
| 1115 |
complete: ['group'] |
| 1116 |
``` |
| 1117 |
|
| 1118 |
``` |
| 1119 |
~ > example --group=<TAB> |
| 1120 |
adm audio avahi |
| 1121 |
bin braph colord |
| 1122 |
daemon dbus dhcpcd |
| 1123 |
disk floppy ftp |
| 1124 |
games git groups |
| 1125 |
[...] |
| 1126 |
``` |
| 1127 |
|
| 1128 |
**SEE ALSO** |
| 1129 |
|
| 1130 |
- [gid](#gid): For completing group IDs |
| 1131 |
|
| 1132 |
--- |
| 1133 |
|
| 1134 |
### history |
| 1135 |
|
| 1136 |
> Complete based on a shell's history |
| 1137 |
|
| 1138 |
**SYNOPSIS** |
| 1139 |
|
| 1140 |
```yaml |
| 1141 |
['history', <REGEX>] |
| 1142 |
``` |
| 1143 |
|
| 1144 |
**PARAMETERS** |
| 1145 |
|
| 1146 |
`REGEX`: |
| 1147 |
An extended regular expression used to filter history entries. |
| 1148 |
The regular expression is passed to `grep -E`. |
| 1149 |
|
| 1150 |
|
| 1151 |
**EXAMPLE** |
| 1152 |
|
| 1153 |
```yaml |
| 1154 |
prog: 'example' |
| 1155 |
options: |
| 1156 |
- option_strings: ['--history'] |
| 1157 |
complete: ['history', '[a-zA-Z0-9]+@[a-zA-Z0-9]+'] |
| 1158 |
``` |
| 1159 |
|
| 1160 |
``` |
| 1161 |
~ > example --history=<TAB> |
| 1162 |
foo@bar mymail@myprovider |
| 1163 |
``` |
| 1164 |
|
| 1165 |
--- |
| 1166 |
|
| 1167 |
### hostname |
| 1168 |
|
| 1169 |
> Complete hostnames |
| 1170 |
|
| 1171 |
**SYNOPSIS** |
| 1172 |
|
| 1173 |
```yaml |
| 1174 |
['hostname'] |
| 1175 |
``` |
| 1176 |
|
| 1177 |
**EXAMPLE** |
| 1178 |
|
| 1179 |
```yaml |
| 1180 |
prog: 'example' |
| 1181 |
options: |
| 1182 |
- option_strings: ['--hostname'] |
| 1183 |
complete: ['hostname'] |
| 1184 |
``` |
| 1185 |
|
| 1186 |
``` |
| 1187 |
~ > example --hostname=<TAB> |
| 1188 |
localhost |
| 1189 |
``` |
| 1190 |
|
| 1191 |
**SEE ALSO** |
| 1192 |
|
| 1193 |
- [ip\_address](#ip_address): For completing local IP addresses |
| 1194 |
|
| 1195 |
--- |
| 1196 |
|
| 1197 |
### integer |
| 1198 |
|
| 1199 |
> Complete integer values |
| 1200 |
|
| 1201 |
**SYNOPSIS** |
| 1202 |
|
| 1203 |
```yaml |
| 1204 |
['integer'] |
| 1205 |
|
| 1206 |
['integer', <OPTIONS>] |
| 1207 |
``` |
| 1208 |
|
| 1209 |
**PARAMETERS** |
| 1210 |
|
| 1211 |
`OPTIONS`: |
| 1212 |
A dictionary containing additional options for configuring the completion. |
| 1213 |
|
| 1214 |
- `min`: The minimum allowed value. |
| 1215 |
|
| 1216 |
- `max`: The maximum allowed value. |
| 1217 |
|
| 1218 |
- `suffixes`: A dictionary of suffixes and their descriptions. The suffix is appended to the completed value. |
| 1219 |
|
| 1220 |
- `help`: The help text shown during completion. If not specified, the `help` attribute of the option is used. |
| 1221 |
|
| 1222 |
|
| 1223 |
**EXAMPLE** |
| 1224 |
|
| 1225 |
```yaml |
| 1226 |
prog: 'example' |
| 1227 |
options: |
| 1228 |
- option_strings: ['--time'] |
| 1229 |
complete: ['integer', {'suffixes': {'s': 'seconds', 'm': 'minutes', 'h': 'hours'}}] |
| 1230 |
``` |
| 1231 |
|
| 1232 |
``` |
| 1233 |
~ > example --integer=3<TAB> |
| 1234 |
s -- seconds m -- minutes h -- hours |
| 1235 |
``` |
| 1236 |
|
| 1237 |
**SEE ALSO** |
| 1238 |
|
| 1239 |
- [float](#float): For completing floating-point values |
| 1240 |
|
| 1241 |
- [range](#range): For completing sequences of integers |
| 1242 |
|
| 1243 |
--- |
| 1244 |
|
| 1245 |
### ip\_address |
| 1246 |
|
| 1247 |
> Complete local IP addresses |
| 1248 |
|
| 1249 |
**SYNOPSIS** |
| 1250 |
|
| 1251 |
```yaml |
| 1252 |
['ip_address', <TYPE>] |
| 1253 |
``` |
| 1254 |
|
| 1255 |
**PARAMETERS** |
| 1256 |
|
| 1257 |
`TYPE`: |
| 1258 |
The type of ip addresses to complete: |
| 1259 |
|
| 1260 |
- `ipv4`: IPv4 addresses |
| 1261 |
- `ipv6`: IPv6 addresses |
| 1262 |
- `all`: Both IPv4 and IPv6 addresses |
| 1263 |
|
| 1264 |
Append `+` to include the unspecified address of the selected family: |
| 1265 |
|
| 1266 |
- `ipv4+`: Includes `0.0.0.0` |
| 1267 |
- `ipv6+`: Includes `::` |
| 1268 |
- `all+`: Includes both 0.0.0.0 and `::` |
| 1269 |
|
| 1270 |
|
| 1271 |
**EXAMPLE** |
| 1272 |
|
| 1273 |
```yaml |
| 1274 |
prog: 'example' |
| 1275 |
options: |
| 1276 |
- option_strings: ['--ip-address'] |
| 1277 |
complete: ['ip_address'] |
| 1278 |
|
| 1279 |
- option_strings: ['--ip-address-v4'] |
| 1280 |
complete: ['ip_address', 'ipv4'] |
| 1281 |
|
| 1282 |
- option_strings: ['--ip-address-v6'] |
| 1283 |
complete: ['ip_address', 'ipv6'] |
| 1284 |
``` |
| 1285 |
|
| 1286 |
``` |
| 1287 |
~ > example --ip-address=<TAB> |
| 1288 |
::1 10.0.0.71 127.0.0.1 fe80::f567:7a1a:3c98:808d |
| 1289 |
|
| 1290 |
~ > example --ip-address-v4=<TAB> |
| 1291 |
10.0.0.71 127.0.0.1 |
| 1292 |
|
| 1293 |
~ > example --ip-address-v6=<TAB> |
| 1294 |
::1 fe80::f567:7a1a:3c98:808d |
| 1295 |
``` |
| 1296 |
|
| 1297 |
**SEE ALSO** |
| 1298 |
|
| 1299 |
- [net\_interface](#net_interface): For completing network interfaces |
| 1300 |
|
| 1301 |
- [hostname](#hostname): For completing hostnames |
| 1302 |
|
| 1303 |
--- |
| 1304 |
|
| 1305 |
### mime\_file |
| 1306 |
|
| 1307 |
> Complete files by MIME type |
| 1308 |
|
| 1309 |
**SYNOPSIS** |
| 1310 |
|
| 1311 |
```yaml |
| 1312 |
['mime_file', <MIME_REGEX>] |
| 1313 |
``` |
| 1314 |
|
| 1315 |
**PARAMETERS** |
| 1316 |
|
| 1317 |
`MIME_REGEX`: |
| 1318 |
An extended regular expression used to match MIME types. |
| 1319 |
The expression is passed to `grep -E` to filter the results. |
| 1320 |
|
| 1321 |
|
| 1322 |
**EXAMPLE** |
| 1323 |
|
| 1324 |
```yaml |
| 1325 |
prog: 'example' |
| 1326 |
options: |
| 1327 |
- option_strings: ['--image'] |
| 1328 |
complete: ['mime_file', 'image/'] |
| 1329 |
``` |
| 1330 |
|
| 1331 |
``` |
| 1332 |
~ > example --image=<TAB> |
| 1333 |
dir1/ dir2/ img.png img.jpg |
| 1334 |
``` |
| 1335 |
|
| 1336 |
--- |
| 1337 |
|
| 1338 |
### pid |
| 1339 |
|
| 1340 |
> Complete process IDs |
| 1341 |
|
| 1342 |
**SYNOPSIS** |
| 1343 |
|
| 1344 |
```yaml |
| 1345 |
['pid'] |
| 1346 |
``` |
| 1347 |
|
| 1348 |
**EXAMPLE** |
| 1349 |
|
| 1350 |
```yaml |
| 1351 |
prog: 'example' |
| 1352 |
options: |
| 1353 |
- option_strings: ['--pid'] |
| 1354 |
complete: ['pid'] |
| 1355 |
``` |
| 1356 |
|
| 1357 |
``` |
| 1358 |
~ > example --pid=<TAB> |
| 1359 |
1 13 166 19 254 31 45 |
| 1360 |
1006 133315 166441 19042 26 32 46 |
| 1361 |
10150 1392 166442 195962 27 33 4609 |
| 1362 |
``` |
| 1363 |
|
| 1364 |
**SEE ALSO** |
| 1365 |
|
| 1366 |
- [process](#process): For completing process names |
| 1367 |
|
| 1368 |
--- |
| 1369 |
|
| 1370 |
### process |
| 1371 |
|
| 1372 |
> Complete process names |
| 1373 |
|
| 1374 |
**SYNOPSIS** |
| 1375 |
|
| 1376 |
```yaml |
| 1377 |
['process'] |
| 1378 |
``` |
| 1379 |
|
| 1380 |
**EXAMPLE** |
| 1381 |
|
| 1382 |
```yaml |
| 1383 |
prog: 'example' |
| 1384 |
options: |
| 1385 |
- option_strings: ['--process'] |
| 1386 |
complete: ['process'] |
| 1387 |
``` |
| 1388 |
|
| 1389 |
``` |
| 1390 |
~ > example --process=s<TAB> |
| 1391 |
scsi_eh_0 scsi_eh_1 scsi_eh_2 scsi_eh_3 scsi_eh_4 |
| 1392 |
scsi_eh_5 sh sudo syndaemon systemd |
| 1393 |
systemd-journald systemd-logind systemd-udevd |
| 1394 |
``` |
| 1395 |
|
| 1396 |
**SEE ALSO** |
| 1397 |
|
| 1398 |
- [pid](#pid): For completing process IDs |
| 1399 |
|
| 1400 |
--- |
| 1401 |
|
| 1402 |
### range |
| 1403 |
|
| 1404 |
> Complete sequences of integers |
| 1405 |
|
| 1406 |
**SYNOPSIS** |
| 1407 |
|
| 1408 |
```yaml |
| 1409 |
['range', <START>, <STOP>] |
| 1410 |
|
| 1411 |
['range', <START>, <STOP>, <STEP>] |
| 1412 |
``` |
| 1413 |
|
| 1414 |
**PARAMETERS** |
| 1415 |
|
| 1416 |
`START`: |
| 1417 |
The first value of the range. |
| 1418 |
|
| 1419 |
`STOP`: |
| 1420 |
The last value of the range. |
| 1421 |
|
| 1422 |
`STEP`: |
| 1423 |
The increment between values. Defaults to `1`. |
| 1424 |
|
| 1425 |
|
| 1426 |
**EXAMPLE** |
| 1427 |
|
| 1428 |
```yaml |
| 1429 |
prog: 'example' |
| 1430 |
options: |
| 1431 |
- option_strings: ['--range-1'] |
| 1432 |
complete: ['range', 1, 9] |
| 1433 |
|
| 1434 |
- option_strings: ['--range-2'] |
| 1435 |
complete: ['range', 1, 9, 2] |
| 1436 |
``` |
| 1437 |
|
| 1438 |
``` |
| 1439 |
~ > example --range-1=<TAB> |
| 1440 |
1 2 3 4 5 6 7 8 9 |
| 1441 |
|
| 1442 |
~ > example --range-2=<TAB> |
| 1443 |
1 3 5 7 9 |
| 1444 |
``` |
| 1445 |
|
| 1446 |
--- |
| 1447 |
|
| 1448 |
### service |
| 1449 |
|
| 1450 |
> Complete systemd service names |
| 1451 |
|
| 1452 |
**SYNOPSIS** |
| 1453 |
|
| 1454 |
```yaml |
| 1455 |
['service'] |
| 1456 |
``` |
| 1457 |
|
| 1458 |
**EXAMPLE** |
| 1459 |
|
| 1460 |
```yaml |
| 1461 |
prog: 'example' |
| 1462 |
options: |
| 1463 |
- option_strings: ['--service'] |
| 1464 |
complete: ['service'] |
| 1465 |
``` |
| 1466 |
|
| 1467 |
``` |
| 1468 |
~ > example --service=<TAB> |
| 1469 |
TODO |
| 1470 |
[...] |
| 1471 |
``` |
| 1472 |
|
| 1473 |
--- |
| 1474 |
|
| 1475 |
### signal |
| 1476 |
|
| 1477 |
> Complete signal names |
| 1478 |
|
| 1479 |
**SYNOPSIS** |
| 1480 |
|
| 1481 |
```yaml |
| 1482 |
['signal'] |
| 1483 |
``` |
| 1484 |
|
| 1485 |
**EXAMPLE** |
| 1486 |
|
| 1487 |
```yaml |
| 1488 |
prog: 'example' |
| 1489 |
options: |
| 1490 |
- option_strings: ['--signal'] |
| 1491 |
complete: ['signal'] |
| 1492 |
``` |
| 1493 |
|
| 1494 |
``` |
| 1495 |
~ > example --signal=<TAB> |
| 1496 |
ABRT -- Process abort signal |
| 1497 |
ALRM -- Alarm clock |
| 1498 |
BUS -- Access to an undefined portion of a memory object |
| 1499 |
CHLD -- Child process terminated, stopped, or continued |
| 1500 |
CONT -- Continue executing, if stopped |
| 1501 |
FPE -- Erroneous arithmetic operation |
| 1502 |
HUP -- Hangup |
| 1503 |
ILL -- Illegal instruction |
| 1504 |
INT -- Terminal interrupt signal |
| 1505 |
[...] |
| 1506 |
``` |
| 1507 |
|
| 1508 |
--- |
| 1509 |
|
| 1510 |
### uid |
| 1511 |
|
| 1512 |
> Complete user IDs |
| 1513 |
|
| 1514 |
**SYNOPSIS** |
| 1515 |
|
| 1516 |
```yaml |
| 1517 |
['uid'] |
| 1518 |
``` |
| 1519 |
|
| 1520 |
**EXAMPLE** |
| 1521 |
|
| 1522 |
```yaml |
| 1523 |
prog: 'example' |
| 1524 |
options: |
| 1525 |
- option_strings: ['--uid'] |
| 1526 |
complete: ['uid'] |
| 1527 |
``` |
| 1528 |
|
| 1529 |
``` |
| 1530 |
~ > example --uid=<TAB> |
| 1531 |
0 -- root |
| 1532 |
1000 -- braph |
| 1533 |
102 -- polkitd |
| 1534 |
133 -- rtkit |
| 1535 |
14 -- ftp |
| 1536 |
1 -- bin |
| 1537 |
2 -- daemon |
| 1538 |
33 -- http |
| 1539 |
65534 -- nobody |
| 1540 |
[...] |
| 1541 |
``` |
| 1542 |
|
| 1543 |
**SEE ALSO** |
| 1544 |
|
| 1545 |
- [user](#user): For completing user names |
| 1546 |
|
| 1547 |
--- |
| 1548 |
|
| 1549 |
### user |
| 1550 |
|
| 1551 |
> Complete user names |
| 1552 |
|
| 1553 |
**SYNOPSIS** |
| 1554 |
|
| 1555 |
```yaml |
| 1556 |
['user'] |
| 1557 |
``` |
| 1558 |
|
| 1559 |
**EXAMPLE** |
| 1560 |
|
| 1561 |
```yaml |
| 1562 |
prog: 'example' |
| 1563 |
options: |
| 1564 |
- option_strings: ['--user'] |
| 1565 |
complete: ['user'] |
| 1566 |
``` |
| 1567 |
|
| 1568 |
``` |
| 1569 |
~ > example --user=<TAB> |
| 1570 |
avahi bin braph |
| 1571 |
colord daemon dbus |
| 1572 |
dhcpcd ftp git |
| 1573 |
[...] |
| 1574 |
``` |
| 1575 |
|
| 1576 |
**SEE ALSO** |
| 1577 |
|
| 1578 |
- [uid](#uid): For completing user IDs |
| 1579 |
|
| 1580 |
--- |
| 1581 |
|
| 1582 |
### value\_list |
| 1583 |
|
| 1584 |
> Complete comma-separated lists of values |
| 1585 |
|
| 1586 |
**SYNOPSIS** |
| 1587 |
|
| 1588 |
```yaml |
| 1589 |
['value_list', <OPTIONS>] |
| 1590 |
``` |
| 1591 |
|
| 1592 |
**PARAMETERS** |
| 1593 |
|
| 1594 |
`OPTIONS`: |
| 1595 |
A dictionary containing additional options for configuring the completion. |
| 1596 |
|
| 1597 |
- `values`: |
| 1598 |
A list or dictionary containing the values to offer for completion. |
| 1599 |
|
| 1600 |
If a list is supplied, all values are offered without descriptions. |
| 1601 |
|
| 1602 |
If a dictionary is supplied, the keys are used as completion values and |
| 1603 |
the values are used as descriptions. |
| 1604 |
|
| 1605 |
- `separator`: |
| 1606 |
The separator used between list elements. Defaults to `,`. |
| 1607 |
|
| 1608 |
- `duplicates`: |
| 1609 |
Allow duplicate values to be offered for completion. Defaults to `false`. |
| 1610 |
|
| 1611 |
|
| 1612 |
**EXAMPLE** |
| 1613 |
|
| 1614 |
```yaml |
| 1615 |
prog: 'example' |
| 1616 |
options: |
| 1617 |
- option_strings: ['--value-list-1'] |
| 1618 |
complete: ['value_list', {'values': ['exec', 'noexec']}] |
| 1619 |
|
| 1620 |
- option_strings: ['--value-list-2'] |
| 1621 |
complete: ['value_list', {'values': {'one': 'Description 1', 'two': 'Description 2'}}] |
| 1622 |
``` |
| 1623 |
|
| 1624 |
``` |
| 1625 |
~ > example --value-list-1=<TAB> |
| 1626 |
exec noexec |
| 1627 |
|
| 1628 |
~ > example --value-list-1=exec,<TAB> |
| 1629 |
noexec |
| 1630 |
|
| 1631 |
~ > example --value-list-2=<TAB> |
| 1632 |
one -- Description 1 |
| 1633 |
two -- Description 2 |
| 1634 |
``` |
| 1635 |
|
| 1636 |
**SEE ALSO** |
| 1637 |
|
| 1638 |
- [list](#list): For completing comma-separated lists using a completer |
| 1639 |
|
| 1640 |
- [key\_value\_list](#key_value_list): For completing comma-separated lists of key=value pairs |
| 1641 |
|
| 1642 |
--- |
| 1643 |
|
| 1644 |
### variable |
| 1645 |
|
| 1646 |
> Complete shell variable names |
| 1647 |
|
| 1648 |
**SYNOPSIS** |
| 1649 |
|
| 1650 |
```yaml |
| 1651 |
['variable'] |
| 1652 |
``` |
| 1653 |
|
| 1654 |
**EXAMPLE** |
| 1655 |
|
| 1656 |
```yaml |
| 1657 |
prog: 'example' |
| 1658 |
options: |
| 1659 |
- option_strings: ['--variable'] |
| 1660 |
complete: ['variable'] |
| 1661 |
``` |
| 1662 |
|
| 1663 |
``` |
| 1664 |
~ > example --variable=HO<TAB> |
| 1665 |
HOME HOSTNAME HOSTTYPE |
| 1666 |
``` |
| 1667 |
|
| 1668 |
**SEE ALSO** |
| 1669 |
|
| 1670 |
- [environment](#environment): For completing environment variable names |
| 1671 |
|
| 1672 |
--- |
| 1673 |
|
| 1674 |
### combine |
| 1675 |
|
| 1676 |
> Combine multiple completers |
| 1677 |
|
| 1678 |
**SYNOPSIS** |
| 1679 |
|
| 1680 |
```yaml |
| 1681 |
['combine', <COMPLETERS>] |
| 1682 |
``` |
| 1683 |
|
| 1684 |
**PARAMETERS** |
| 1685 |
|
| 1686 |
Combines multiple completers into a single completer. |
| 1687 |
|
| 1688 |
`COMPLETERS`: |
| 1689 |
A list of completers to combine. |
| 1690 |
|
| 1691 |
|
| 1692 |
**EXAMPLE** |
| 1693 |
|
| 1694 |
```yaml |
| 1695 |
prog: 'example' |
| 1696 |
options: |
| 1697 |
- option_strings: ['--combine'] |
| 1698 |
complete: ['combine', [['user'], ['pid']]] |
| 1699 |
``` |
| 1700 |
|
| 1701 |
``` |
| 1702 |
~ > example --combine=avahi,daemon,<TAB> |
| 1703 |
1439404 3488332 3571716 3607235 4134206 |
| 1704 |
alpm avahi bin braph daemon |
| 1705 |
root rtkit systemd-coredump systemd-journal-remote systemd-network |
| 1706 |
[...] |
| 1707 |
``` |
| 1708 |
|
| 1709 |
--- |
| 1710 |
|
| 1711 |
### key\_value\_list |
| 1712 |
|
| 1713 |
> Complete comma-separated lists of key=value pairs |
| 1714 |
|
| 1715 |
**SYNOPSIS** |
| 1716 |
|
| 1717 |
```yaml |
| 1718 |
['key_value_list', <PAIR_SEPARATOR>, <VALUE_SEPARATOR>, <DEFINITIONS>] |
| 1719 |
|
| 1720 |
['key_value_list', <PAIR_SEPARATOR>, <VALUE_SEPARATOR>, <DEFINITIONS>, <CONDITION_FUNCTION>] |
| 1721 |
``` |
| 1722 |
|
| 1723 |
**PARAMETERS** |
| 1724 |
|
| 1725 |
`PAIR_SEPARATOR`: |
| 1726 |
The separator used to separate individual key-value pairs. |
| 1727 |
|
| 1728 |
`VALUE_SEPARATOR`: |
| 1729 |
The separator used to separate a key from its value. |
| 1730 |
|
| 1731 |
`DEFINITIONS`: |
| 1732 |
A list of key definitions. |
| 1733 |
|
| 1734 |
Each definition has one of the following forms: |
| 1735 |
|
| 1736 |
`[<KEY>, <DESCRIPTION>, <COMPLETER>]` |
| 1737 |
|
| 1738 |
-- OR -- |
| 1739 |
|
| 1740 |
`[<KEY>, <DESCRIPTION>, <COMPLETER>, <EXCLUDES>]` |
| 1741 |
|
| 1742 |
`KEY`: |
| 1743 |
The name of the key. |
| 1744 |
Prefix the name with `*` to allow the key to be completed multiple times. |
| 1745 |
|
| 1746 |
`DESCRIPTION`: |
| 1747 |
A description shown during completion. |
| 1748 |
Use `null` to omit the description. |
| 1749 |
|
| 1750 |
`COMPLETER`: |
| 1751 |
The completer used for the value of the key. |
| 1752 |
Use `null` if the key does not take an argument. |
| 1753 |
Use `['none']` if the key takes an argument but cannot be completed. |
| 1754 |
|
| 1755 |
`EXCLUDES`: |
| 1756 |
A list of keys that should no longer be offered for completion once this key has been used. |
| 1757 |
|
| 1758 |
`CONDITION_FUNCTION`: |
| 1759 |
A command or function that determines whether a key should be offered for |
| 1760 |
completion. |
| 1761 |
|
| 1762 |
It is invoked with the key as its first argument. If it exits with status `0`, |
| 1763 |
the key is offered for completion. Any non-zero exit status suppresses the |
| 1764 |
key. |
| 1765 |
|
| 1766 |
By default, each key is offered for completion only once. |
| 1767 |
To allow a key to be completed multiple times, prefix its name with `*`. |
| 1768 |
|
| 1769 |
|
| 1770 |
**EXAMPLE** |
| 1771 |
|
| 1772 |
```yaml |
| 1773 |
prog: 'example' |
| 1774 |
options: |
| 1775 |
- option_strings: ['--key-value-list'] |
| 1776 |
complete: ['key_value_list', ',', '=', [ |
| 1777 |
['flag', 'An option flag', null], |
| 1778 |
['nodesc', null, null], |
| 1779 |
['nocomp', 'An option with arg but without completer', ['none']], |
| 1780 |
['user', 'Takes a username', ['user']], |
| 1781 |
['*repeatable', 'This option is repeatable', null], |
| 1782 |
['exclusive', 'This option disables other options', null, ['flag', 'nodesc', 'nocomp']], |
| 1783 |
['check', 'Specify file name conversions', ['choices', { |
| 1784 |
'relaxed': 'convert to lowercase before lookup', |
| 1785 |
'strict': 'no conversion' |
| 1786 |
}]] |
| 1787 |
]] |
| 1788 |
``` |
| 1789 |
|
| 1790 |
``` |
| 1791 |
~ > example --key-value-list flag,user=<TAB> |
| 1792 |
bin braph |
| 1793 |
colord dbus |
| 1794 |
dhcpcd git |
| 1795 |
[...] |
| 1796 |
``` |
| 1797 |
|
| 1798 |
**SEE ALSO** |
| 1799 |
|
| 1800 |
- [list](#list): For completing comma-separated lists using a completer |
| 1801 |
|
| 1802 |
- [value\_list](#value_list): For completing comma-separated lists of values |
| 1803 |
|
| 1804 |
- [key\_value\_pair](#key_value_pair): For completing single key=value pairs |
| 1805 |
|
| 1806 |
- [key\_value\_list\_exec](#key_value_list_exec): For completing comma-separated lists of key=value pairs (dynamically generated by a function) |
| 1807 |
|
| 1808 |
--- |
| 1809 |
|
| 1810 |
### key\_value\_pair |
| 1811 |
|
| 1812 |
> Complete single key=value pairs |
| 1813 |
|
| 1814 |
**SYNOPSIS** |
| 1815 |
|
| 1816 |
```yaml |
| 1817 |
['key_value_pair', <VALUE_SEPARATOR>, <DEFINITIONS>] |
| 1818 |
|
| 1819 |
['key_value_pair', <VALUE_SEPARATOR>, <DEFINITIONS>, <CONDITION_FUNCTION>] |
| 1820 |
``` |
| 1821 |
|
| 1822 |
**PARAMETERS** |
| 1823 |
|
| 1824 |
`VALUE_SEPARATOR`: |
| 1825 |
The separator used to separate a key from its value. |
| 1826 |
|
| 1827 |
`DEFINITIONS`: |
| 1828 |
A list of key definitions. |
| 1829 |
|
| 1830 |
Each definition has the following form: |
| 1831 |
|
| 1832 |
`[<KEY>, <DESCRIPTION>, <COMPLETER>]` |
| 1833 |
|
| 1834 |
`KEY`: |
| 1835 |
The name of the key. |
| 1836 |
Prefix the name with `*` to allow the key to be completed multiple times. |
| 1837 |
|
| 1838 |
`DESCRIPTION`: |
| 1839 |
A description shown during completion. |
| 1840 |
Use `null` to omit the description. |
| 1841 |
|
| 1842 |
`COMPLETER`: |
| 1843 |
The completer used for the value of the key. |
| 1844 |
Use `null` if the key does not take an argument. |
| 1845 |
Use `['none']` if the key takes an argument but cannot be completed. |
| 1846 |
|
| 1847 |
`CONDITION_FUNCTION`: |
| 1848 |
A command or function that determines whether a key should be offered for |
| 1849 |
completion. |
| 1850 |
|
| 1851 |
It is invoked with the key as its first argument. If it exits with status `0`, |
| 1852 |
the key is offered for completion. Any non-zero exit status suppresses the |
| 1853 |
key. |
| 1854 |
|
| 1855 |
|
| 1856 |
**EXAMPLE** |
| 1857 |
|
| 1858 |
```yaml |
| 1859 |
prog: 'example' |
| 1860 |
options: |
| 1861 |
- option_strings: ['--key-value-pair'] |
| 1862 |
complete: ['key_value_pair', '=', [ |
| 1863 |
['flag', 'An option flag', null], |
| 1864 |
['nodesc', null, null], |
| 1865 |
['nocomp', 'An option with arg but without completer', ['none']], |
| 1866 |
['user', 'Takes a username', ['user']], |
| 1867 |
['check', 'Specify file name conversions', ['choices', { |
| 1868 |
'relaxed': 'convert to lowercase before lookup', |
| 1869 |
'strict': 'no conversion' |
| 1870 |
}]] |
| 1871 |
]] |
| 1872 |
``` |
| 1873 |
|
| 1874 |
``` |
| 1875 |
~ > example --key-value-pair <TAB> |
| 1876 |
check -- Specify file name conversions |
| 1877 |
flag -- An option flag |
| 1878 |
nocomp -- An option with arg but without completer |
| 1879 |
user -- Takes a username |
| 1880 |
nodesc |
| 1881 |
|
| 1882 |
~ > example --key-value-pair user=<TAB> |
| 1883 |
bin braph |
| 1884 |
colord dbus |
| 1885 |
dhcpcd git |
| 1886 |
[...] |
| 1887 |
``` |
| 1888 |
|
| 1889 |
**SEE ALSO** |
| 1890 |
|
| 1891 |
- [key\_value\_list](#key_value_list): For completing comma-separated lists of key=value pairs |
| 1892 |
|
| 1893 |
- [key\_value\_pair\_exec](#key_value_pair_exec): For completing single key=value pairs (dynamically generated by a function) |
| 1894 |
|
| 1895 |
--- |
| 1896 |
|
| 1897 |
### list |
| 1898 |
|
| 1899 |
> Complete comma-separated lists using a completer |
| 1900 |
|
| 1901 |
**SYNOPSIS** |
| 1902 |
|
| 1903 |
```yaml |
| 1904 |
['list', <COMPLETER>] |
| 1905 |
|
| 1906 |
['list', <COMPLETER>, <OPTIONS>] |
| 1907 |
``` |
| 1908 |
|
| 1909 |
**PARAMETERS** |
| 1910 |
|
| 1911 |
`COMPLETER`: |
| 1912 |
The completer used to generate the list elements. |
| 1913 |
|
| 1914 |
`OPTIONS`: |
| 1915 |
A dictionary containing additional options for configuring the list completion. |
| 1916 |
|
| 1917 |
- `separator`: The separator used between list elements. Defaults to `,` |
| 1918 |
|
| 1919 |
- `duplicates`: Allow duplicate values to be offered for completion. Defaults to `false` |
| 1920 |
|
| 1921 |
|
| 1922 |
**EXAMPLE** |
| 1923 |
|
| 1924 |
```yaml |
| 1925 |
prog: 'example' |
| 1926 |
options: |
| 1927 |
- option_strings: ['--user-list'] |
| 1928 |
complete: ['list', ['user']] |
| 1929 |
|
| 1930 |
- option_strings: ['--option-list'] |
| 1931 |
complete: ['list', ['choices', ['setuid', 'async', 'block']], {'separator': ':', 'duplicates': true}] |
| 1932 |
``` |
| 1933 |
|
| 1934 |
``` |
| 1935 |
~ > example --user-list=avahi,daemon,<TAB> |
| 1936 |
bin braph |
| 1937 |
colord dbus |
| 1938 |
dhcpcd git |
| 1939 |
[...] |
| 1940 |
|
| 1941 |
~ > example --option-list=setuid:<TAB> |
| 1942 |
setuid async block |
| 1943 |
``` |
| 1944 |
|
| 1945 |
**SEE ALSO** |
| 1946 |
|
| 1947 |
- [value\_list](#value_list): For completing comma-separated lists of values |
| 1948 |
|
| 1949 |
- [file\_list](#file_list): For completing comma-separated lists of files |
| 1950 |
|
| 1951 |
- [directory\_list](#directory_list): For completing comma-separated lists of directories |
| 1952 |
|
| 1953 |
- [key\_value\_list](#key_value_list): For completing comma-separated lists of key=value pairs |
| 1954 |
|
| 1955 |
--- |
| 1956 |
|
| 1957 |
### none |
| 1958 |
|
| 1959 |
> No completion, but specify that an argument is required |
| 1960 |
|
| 1961 |
**SYNOPSIS** |
| 1962 |
|
| 1963 |
```yaml |
| 1964 |
['none'] |
| 1965 |
``` |
| 1966 |
|
| 1967 |
**PARAMETERS** |
| 1968 |
|
| 1969 |
Disables autocompletion for an option but still marks it as requiring an argument. |
| 1970 |
|
| 1971 |
Without specifying `complete`, the option would not take an argument. |
| 1972 |
|
| 1973 |
|
| 1974 |
**EXAMPLE** |
| 1975 |
|
| 1976 |
```yaml |
| 1977 |
prog: 'example' |
| 1978 |
options: |
| 1979 |
- option_strings: ['--none'] |
| 1980 |
complete: ['none'] |
| 1981 |
``` |
| 1982 |
|
| 1983 |
``` |
| 1984 |
~ > example --none=<TAB> |
| 1985 |
<NO OUTPUT> |
| 1986 |
``` |
| 1987 |
|
| 1988 |
--- |
| 1989 |
|
| 1990 |
### prefix |
| 1991 |
|
| 1992 |
> Prefix completions with a string |
| 1993 |
|
| 1994 |
**SYNOPSIS** |
| 1995 |
|
| 1996 |
```yaml |
| 1997 |
['prefix', <PREFIX>, <COMPLETER>] |
| 1998 |
``` |
| 1999 |
|
| 2000 |
**PARAMETERS** |
| 2001 |
|
| 2002 |
`PREFIX`: |
| 2003 |
The string to prepend to each completion candidate. |
| 2004 |
|
| 2005 |
`COMPLETER`: |
| 2006 |
The completer used to generate the completion candidates. |
| 2007 |
|
| 2008 |
|
| 2009 |
**EXAMPLE** |
| 2010 |
|
| 2011 |
```yaml |
| 2012 |
prog: 'example' |
| 2013 |
options: |
| 2014 |
- option_strings: ['--prefix'] |
| 2015 |
complete: ['prefix', 'input:', ['file']] |
| 2016 |
``` |
| 2017 |
|
| 2018 |
``` |
| 2019 |
~ > example --prefix=<TAB> |
| 2020 |
~ > example --prefix=input: |
| 2021 |
|
| 2022 |
~ > example --prefix=input:<TAB> |
| 2023 |
~ > example --prefix=input:file1.txt |
| 2024 |
``` |
| 2025 |
|
| 2026 |
--- |
| 2027 |
|
| 2028 |
### exec |
| 2029 |
|
| 2030 |
> Complete values from the output of a command or function |
| 2031 |
|
| 2032 |
**SYNOPSIS** |
| 2033 |
|
| 2034 |
```yaml |
| 2035 |
['exec', <COMMAND>] |
| 2036 |
``` |
| 2037 |
|
| 2038 |
**PARAMETERS** |
| 2039 |
|
| 2040 |
`COMMAND`: |
| 2041 |
The command or function to execute. Its output must be formatted as tab-separated values: |
| 2042 |
|
| 2043 |
``` |
| 2044 |
<ITEM_1>\t<DESCRIPTION_1> |
| 2045 |
<ITEM_2>\t<DESCRIPTION_2> |
| 2046 |
[...] |
| 2047 |
``` |
| 2048 |
|
| 2049 |
Each line represents one completion candidate. The item and its description are separated by a tab character. |
| 2050 |
|
| 2051 |
|
| 2052 |
**NOTES** |
| 2053 |
|
| 2054 |
- Functions can be put inside a file and included with `--include-file` |
| 2055 |
|
| 2056 |
**EXAMPLE** |
| 2057 |
|
| 2058 |
```yaml |
| 2059 |
prog: 'example' |
| 2060 |
options: |
| 2061 |
- option_strings: ['--exec'] |
| 2062 |
complete: ['exec', "printf '%s\\t%s\\n' 'Item 1' 'Description 1' 'Item 2' 'Description 2'"] |
| 2063 |
``` |
| 2064 |
|
| 2065 |
``` |
| 2066 |
~ > example --exec=<TAB> |
| 2067 |
Item 1 (Description 1) Item 2 (Description 2) |
| 2068 |
``` |
| 2069 |
|
| 2070 |
**SEE ALSO** |
| 2071 |
|
| 2072 |
- [exec\_fast](#exec_fast): Faster implementation of exec |
| 2073 |
|
| 2074 |
- [exec\_internal](#exec_internal): Use the shell's internal completion mechanisms |
| 2075 |
|
| 2076 |
--- |
| 2077 |
|
| 2078 |
### exec\_fast |
| 2079 |
|
| 2080 |
> Complete values from the output of a command or function (fast and unsafe) |
| 2081 |
|
| 2082 |
**SYNOPSIS** |
| 2083 |
|
| 2084 |
```yaml |
| 2085 |
['exec_fast', <COMMAND>] |
| 2086 |
``` |
| 2087 |
|
| 2088 |
**PARAMETERS** |
| 2089 |
|
| 2090 |
Faster version of `exec` for handling large amounts of data. |
| 2091 |
|
| 2092 |
Unlike `exec`, this implementation does not safely handle arbitrary output. |
| 2093 |
Completion items must not contain whitespace or special shell characters. |
| 2094 |
|
| 2095 |
|
| 2096 |
**NOTES** |
| 2097 |
|
| 2098 |
- Functions can be put inside a file and included with `--include-file` |
| 2099 |
|
| 2100 |
**EXAMPLE** |
| 2101 |
|
| 2102 |
```yaml |
| 2103 |
prog: 'example' |
| 2104 |
options: |
| 2105 |
- option_strings: ['--exec-fast'] |
| 2106 |
complete: ['exec_fast', "printf '%s\\t%s\\n' 1 one 2 two"] |
| 2107 |
``` |
| 2108 |
|
| 2109 |
``` |
| 2110 |
~ > example --exec-fast=<TAB> |
| 2111 |
1 -- one |
| 2112 |
2 -- one |
| 2113 |
``` |
| 2114 |
|
| 2115 |
--- |
| 2116 |
|
| 2117 |
### exec\_internal |
| 2118 |
|
| 2119 |
> Use the shell's internal completion mechanisms |
| 2120 |
|
| 2121 |
**SYNOPSIS** |
| 2122 |
|
| 2123 |
```yaml |
| 2124 |
['exec_internal', <COMMAND>] |
| 2125 |
``` |
| 2126 |
|
| 2127 |
**PARAMETERS** |
| 2128 |
|
| 2129 |
Execute a function that internally modifies the completion state. |
| 2130 |
|
| 2131 |
This is useful if a more advanced completion is needed. |
| 2132 |
|
| 2133 |
For **Bash**, it might look like: |
| 2134 |
|
| 2135 |
```sh |
| 2136 |
my_completion_func() { |
| 2137 |
COMPREPLY=( $(compgen -W 'read write append' -- '$cur') ) |
| 2138 |
} |
| 2139 |
``` |
| 2140 |
|
| 2141 |
For **Zsh**, it might look like: |
| 2142 |
|
| 2143 |
```sh |
| 2144 |
my_completion_func() { |
| 2145 |
local items=( |
| 2146 |
read:'Read data from a file' |
| 2147 |
write:'Write data from a file' |
| 2148 |
append:'Append data to a file' |
| 2149 |
) |
| 2150 |
|
| 2151 |
_describe 'my items' items |
| 2152 |
} |
| 2153 |
``` |
| 2154 |
|
| 2155 |
For **Fish**, it might look like: |
| 2156 |
|
| 2157 |
```sh |
| 2158 |
function my_completion_func |
| 2159 |
printf '%s\t%s\n' \ |
| 2160 |
read 'Read data from a file' \ |
| 2161 |
write 'Write data from a file' \ |
| 2162 |
append 'Append data to a file' |
| 2163 |
end |
| 2164 |
``` |
| 2165 |
|
| 2166 |
|
| 2167 |
**NOTES** |
| 2168 |
|
| 2169 |
- Functions can be put inside a file and included with `--include-file` |
| 2170 |
|
| 2171 |
**EXAMPLE** |
| 2172 |
|
| 2173 |
```yaml |
| 2174 |
prog: 'example' |
| 2175 |
options: |
| 2176 |
- option_strings: ['--exec-internal'] |
| 2177 |
complete: ['exec_internal', 'my_completion_func'] |
| 2178 |
``` |
| 2179 |
|
| 2180 |
``` |
| 2181 |
~ > example --exec-internal=<TAB> |
| 2182 |
append -- Append data to a file |
| 2183 |
read -- Read data from a file |
| 2184 |
write -- Write data from a file |
| 2185 |
``` |
| 2186 |
|
| 2187 |
--- |
| 2188 |
|
| 2189 |
### key\_value\_list\_exec |
| 2190 |
|
| 2191 |
> Complete dynamically generated comma-separted lists of key=value pairs |
| 2192 |
|
| 2193 |
**SYNOPSIS** |
| 2194 |
|
| 2195 |
```yaml |
| 2196 |
['key_value_list_exec', <PAIR_SEPARATOR>, <VALUE_SEPARATOR>, <COMMAND>] |
| 2197 |
``` |
| 2198 |
|
| 2199 |
**PARAMETERS** |
| 2200 |
|
| 2201 |
`PAIR_SEPARATOR`: |
| 2202 |
The separator used to separate individual key-value pairs. |
| 2203 |
|
| 2204 |
`VALUE_SEPARATOR`: |
| 2205 |
The separator used to separate a key from its value. |
| 2206 |
|
| 2207 |
`COMMAND`: |
| 2208 |
The command or function used to generate the available keys and values. |
| 2209 |
|
| 2210 |
If invoked without arguments, it must output the available keys in the |
| 2211 |
following format: |
| 2212 |
|
| 2213 |
``` |
| 2214 |
[*]<KEY_1>[=][?]\t<DESCRIPTION_1>\t<EXCLUDES> |
| 2215 |
[*]<KEY_2>[=][?]\t<DESCRIPTION_2>\t<EXCLUDES> |
| 2216 |
[...] |
| 2217 |
``` |
| 2218 |
|
| 2219 |
Prefixing a key with `*` marks it as repeatable. |
| 2220 |
|
| 2221 |
Appending `=` to a key indicates that it requires a value. |
| 2222 |
|
| 2223 |
Appending `=?` to a key indicates that it requires an optional value. |
| 2224 |
|
| 2225 |
`EXCLUDES` is a space-separated list of keys that should no longer be |
| 2226 |
offered once the current key has been used. |
| 2227 |
|
| 2228 |
If invoked with a single argument, the argument is the selected key. |
| 2229 |
The command must output the possible values for that key in the following |
| 2230 |
format: |
| 2231 |
|
| 2232 |
``` |
| 2233 |
<ITEM_1>\t<DESCRIPTION_1> |
| 2234 |
<ITEM_2>\t<DESCRIPTION_2> |
| 2235 |
[...] |
| 2236 |
``` |
| 2237 |
|
| 2238 |
Each line represents one completion candidate. The item and its description |
| 2239 |
are separated by a tab character. |
| 2240 |
|
| 2241 |
Example function: |
| 2242 |
|
| 2243 |
```sh |
| 2244 |
_complete_key_value_list() { |
| 2245 |
if (( $# == 0 )); then |
| 2246 |
printf '%s\t%s\t%s\n' \ |
| 2247 |
'flag' 'option without an argument' '' \ |
| 2248 |
'argument=' 'option with an argument' '' \ |
| 2249 |
'optional=?' 'option with an optional argument' '' \ |
| 2250 |
'*repeatable' 'a repeatable option' '' \ |
| 2251 |
'excludes' 'disable options' 'flag argument' |
| 2252 |
else |
| 2253 |
case '$1' in |
| 2254 |
argument|optional) |
| 2255 |
printf '%s\t%s\n' \ |
| 2256 |
'foo' 'a foo value' \ |
| 2257 |
'bar' 'a bar value';; |
| 2258 |
esac |
| 2259 |
fi |
| 2260 |
} |
| 2261 |
``` |
| 2262 |
|
| 2263 |
|
| 2264 |
**NOTES** |
| 2265 |
|
| 2266 |
- Functions can be put inside a file and included with `--include-file` |
| 2267 |
|
| 2268 |
**EXAMPLE** |
| 2269 |
|
| 2270 |
```yaml |
| 2271 |
prog: 'example' |
| 2272 |
options: |
| 2273 |
- option_strings: ['-o'] |
| 2274 |
complete: ['key_value_list_exec', ',', '=', '_complete_key_value_list'] |
| 2275 |
``` |
| 2276 |
|
| 2277 |
``` |
| 2278 |
~ > example -o <TAB> |
| 2279 |
argument -- option with an argument |
| 2280 |
excludes -- disable options |
| 2281 |
flag -- option without an argument |
| 2282 |
optional -- option with an optional argument |
| 2283 |
repeatable -- a repeatable option |
| 2284 |
|
| 2285 |
~ > example -o argument=<TAB> |
| 2286 |
foo -- a foo value |
| 2287 |
bar -- a bar value |
| 2288 |
|
| 2289 |
~ > example -o excludes,<TAB> |
| 2290 |
optional -- option with an optional argument |
| 2291 |
repeatable -- a repeatable option |
| 2292 |
``` |
| 2293 |
|
| 2294 |
**SEE ALSO** |
| 2295 |
|
| 2296 |
- [key\_value\_list](#key_value_list): For completing comma-separated lists of key=value pairs |
| 2297 |
|
| 2298 |
--- |
| 2299 |
|
| 2300 |
### key\_value\_pair\_exec |
| 2301 |
|
| 2302 |
> Complete dynamically generated a key=value pairs |
| 2303 |
|
| 2304 |
**SYNOPSIS** |
| 2305 |
|
| 2306 |
```yaml |
| 2307 |
['key_value_pair_exec', <VALUE_SEPARATOR>, <COMMAND>] |
| 2308 |
``` |
| 2309 |
|
| 2310 |
**PARAMETERS** |
| 2311 |
|
| 2312 |
`VALUE_SEPARATOR`: |
| 2313 |
The separator used to separate a key from its value. |
| 2314 |
|
| 2315 |
`COMMAND`: |
| 2316 |
The command or function used to generate the available keys and values. |
| 2317 |
|
| 2318 |
If invoked without arguments, it must output the available keys in the |
| 2319 |
following format: |
| 2320 |
|
| 2321 |
``` |
| 2322 |
<KEY_1>[=]\t<DESCRIPTION_1> |
| 2323 |
<KEY_2>[=]\t<DESCRIPTION_2> |
| 2324 |
[...] |
| 2325 |
``` |
| 2326 |
|
| 2327 |
Appending `=` to a key indicates that it requires a value. |
| 2328 |
|
| 2329 |
If invoked with a single argument, the argument is the selected key. The |
| 2330 |
command must output the possible values for that key in the following |
| 2331 |
format: |
| 2332 |
|
| 2333 |
``` |
| 2334 |
<ITEM_1>\t<DESCRIPTION_1> |
| 2335 |
<ITEM_2>\t<DESCRIPTION_2> |
| 2336 |
[...] |
| 2337 |
``` |
| 2338 |
|
| 2339 |
Each line represents one completion candidate. The item and its description |
| 2340 |
are separated by a tab character. |
| 2341 |
|
| 2342 |
Example function: |
| 2343 |
|
| 2344 |
```sh |
| 2345 |
_complete_key_value_pair() { |
| 2346 |
if (( $# == 0 )); then |
| 2347 |
printf '%s\t%s\n' \ |
| 2348 |
'flag' 'a flag' \ |
| 2349 |
'option=' 'option with value' |
| 2350 |
else |
| 2351 |
case '$1' in |
| 2352 |
option) |
| 2353 |
printf '%s\t%s\n' \ |
| 2354 |
'foo' 'a foo value' \ |
| 2355 |
'bar' 'a bar value';; |
| 2356 |
esac |
| 2357 |
fi |
| 2358 |
} |
| 2359 |
``` |
| 2360 |
|
| 2361 |
|
| 2362 |
**NOTES** |
| 2363 |
|
| 2364 |
- Functions can be put inside a file and included with `--include-file` |
| 2365 |
|
| 2366 |
**EXAMPLE** |
| 2367 |
|
| 2368 |
```yaml |
| 2369 |
prog: 'example' |
| 2370 |
options: |
| 2371 |
- option_strings: ['-o'] |
| 2372 |
complete: ['key_value_pair_exec', '=', '_complete_key_value_pair'] |
| 2373 |
``` |
| 2374 |
|
| 2375 |
``` |
| 2376 |
~ > example -o <TAB> |
| 2377 |
flag -- a flag |
| 2378 |
option -- option with value |
| 2379 |
|
| 2380 |
~ > example -o option=<TAB> |
| 2381 |
foo -- a foo value |
| 2382 |
bar -- a bar value |
| 2383 |
``` |
| 2384 |
|
| 2385 |
**SEE ALSO** |
| 2386 |
|
| 2387 |
- [key\_value\_pair](#key_value_pair): For completing single key=value pairs |
| 2388 |
|
| 2389 |
### Options |
| 2390 |
|
| 2391 |
**--version** |
| 2392 |
|
| 2393 |
> Show program version |
| 2394 |
|
| 2395 |
--- |
| 2396 |
|
| 2397 |
**--help** |
| 2398 |
|
| 2399 |
> Show program help |
| 2400 |
|
| 2401 |
--- |
| 2402 |
|
| 2403 |
**--manual=[TOPIC]** |
| 2404 |
|
| 2405 |
> Show a manual for a help topic |
| 2406 |
|
| 2407 |
--- |
| 2408 |
|
| 2409 |
**--input-type=TYPE** *(yaml, json, python, help, auto)* |
| 2410 |
|
| 2411 |
> Specify input file type. If "auto", input type is determined by the file extension |
| 2412 |
|
| 2413 |
For security reasons, reading python files must be explicitly enabled. |
| 2414 |
|
| 2415 |
This option defaults to `auto`. |
| 2416 |
|
| 2417 |
--- |
| 2418 |
|
| 2419 |
**--abbreviate-commands=BOOL** *(True, False)* |
| 2420 |
|
| 2421 |
> Sets whether sub commands can be abbreviated |
| 2422 |
|
| 2423 |
This option defaults to `False`. |
| 2424 |
|
| 2425 |
--- |
| 2426 |
|
| 2427 |
**--abbreviate-options=BOOL** *(True, False)* |
| 2428 |
|
| 2429 |
> Sets whether options can be abbreviated |
| 2430 |
|
| 2431 |
Currently only supported in Bash. |
| 2432 |
|
| 2433 |
This option defaults to `False`. |
| 2434 |
|
| 2435 |
--- |
| 2436 |
|
| 2437 |
**--repeatable-options=BOOL** *(True, False)* |
| 2438 |
|
| 2439 |
> Sets whether options are suggested multiple times during completion |
| 2440 |
|
| 2441 |
This only overrides the `repeatable` parameter of options that don't have |
| 2442 |
it explicitly set to `True` or `False`. |
| 2443 |
|
| 2444 |
If you wish to make all options repeatable regardless of how they are |
| 2445 |
defined in the definition file, use `--disable=repeatable`. |
| 2446 |
|
| 2447 |
This option defaults to `False`. |
| 2448 |
|
| 2449 |
--- |
| 2450 |
|
| 2451 |
**--inherit-options=BOOL** *(True, False)* |
| 2452 |
|
| 2453 |
> Sets whether parent options are visible to subcommands |
| 2454 |
|
| 2455 |
This option defaults to `False`. |
| 2456 |
|
| 2457 |
--- |
| 2458 |
|
| 2459 |
**--option-stacking=BOOL** *(True, False)* |
| 2460 |
|
| 2461 |
> Sets whether short option stacking is allowed |
| 2462 |
|
| 2463 |
Enables or disables short option stacking, where multiple short options are |
| 2464 |
combined in a single argument (e.g. `-fo` instead of `-f -o`). |
| 2465 |
|
| 2466 |
This option defaults to `True`. |
| 2467 |
|
| 2468 |
--- |
| 2469 |
|
| 2470 |
**--long-option-argument-separator=SEPARATOR** *(space, equals, both)* |
| 2471 |
|
| 2472 |
> Sets which separators are used for delimiting a long option from its argument |
| 2473 |
|
| 2474 |
If `space`, only the form `--option argument` is allowed. |
| 2475 |
If `equals`, only the form `--option=argument` is allowed. |
| 2476 |
If `both`, both forms are allowed. |
| 2477 |
|
| 2478 |
Currently only supported in Bash and Zsh. |
| 2479 |
|
| 2480 |
This option defaults to `both`. |
| 2481 |
|
| 2482 |
--- |
| 2483 |
|
| 2484 |
**--disable=FEATURES** *(hidden, final, groups, repeatable, when)* |
| 2485 |
|
| 2486 |
> Disable features |
| 2487 |
|
| 2488 |
- hidden: Disable hidden options |
| 2489 |
- final: Disable final options |
| 2490 |
- groups: Disable option groups |
| 2491 |
- repeatable: Make all options repeatable |
| 2492 |
- when: Disable conditional options and positionals |
| 2493 |
|
| 2494 |
--- |
| 2495 |
|
| 2496 |
**--vim-modeline=BOOL** *(True, False)* |
| 2497 |
|
| 2498 |
> Sets whether a vim modeline comment shall be appended to the generated code |
| 2499 |
|
| 2500 |
The modeline comment looks like this: |
| 2501 |
|
| 2502 |
`# vim: ft=zsh ts=2 sts=2 sw=2 et` |
| 2503 |
|
| 2504 |
This option defaults to `True`. |
| 2505 |
|
| 2506 |
--- |
| 2507 |
|
| 2508 |
**--bash-completions-version=VERSION** |
| 2509 |
|
| 2510 |
> Generate code for a specific bash-completions version |
| 2511 |
|
| 2512 |
Use a value greater or equal to `2.12` to generate code for the "new" |
| 2513 |
version of bash-completions. |
| 2514 |
|
| 2515 |
This option defaults to `2.0`. |
| 2516 |
|
| 2517 |
--- |
| 2518 |
|
| 2519 |
**--zsh-compdef=BOOL** *(True, False)* |
| 2520 |
|
| 2521 |
> Sets whether #compdef is used in zsh scripts |
| 2522 |
|
| 2523 |
Set this option to `False` if the generated script should be sourcable. |
| 2524 |
|
| 2525 |
This option defaults to `True`. |
| 2526 |
|
| 2527 |
--- |
| 2528 |
|
| 2529 |
**--fish-inline-conditions=BOOL** *(True, False)* |
| 2530 |
|
| 2531 |
> Don't store conditions in a variable |
| 2532 |
|
| 2533 |
This option defaults to `False`. |
| 2534 |
|
| 2535 |
--- |
| 2536 |
|
| 2537 |
**--parser-variable=VARIABLE** |
| 2538 |
|
| 2539 |
> Specify the variable name of the ArgumentParser object (for --input-type=python) |
| 2540 |
|
| 2541 |
--- |
| 2542 |
|
| 2543 |
**--include-file=FILE** |
| 2544 |
|
| 2545 |
> Include file in output |
| 2546 |
|
| 2547 |
--- |
| 2548 |
|
| 2549 |
**--comment=COMMENT** |
| 2550 |
|
| 2551 |
> Add a comment to output |
| 2552 |
|
| 2553 |
--- |
| 2554 |
|
| 2555 |
**--keep-comments=BOOL** *(True, False)* |
| 2556 |
|
| 2557 |
> Keep comments of helper functions used in the generated code |
| 2558 |
|
| 2559 |
This option defaults to `False`. |
| 2560 |
|
| 2561 |
--- |
| 2562 |
|
| 2563 |
**--function-prefix=PREFIX** |
| 2564 |
|
| 2565 |
> Set the prefix for generated functions |
| 2566 |
|
| 2567 |
The placeholder `$PROG` will be replaced by the program name. |
| 2568 |
|
| 2569 |
This option defaults to `_$PROG`. |
| 2570 |
|
| 2571 |
--- |
| 2572 |
|
| 2573 |
**--debug** |
| 2574 |
|
| 2575 |
> Enable debug mode |
| 2576 |
|
| 2577 |
Keep comments, generate shell code for debugging and print a full stack |
| 2578 |
trace in case of an error. |
| 2579 |
|
| 2580 |
--- |
| 2581 |
|
| 2582 |
**-o|--output=FILE** |
| 2583 |
|
| 2584 |
> Write output to destination file [default: stdout] |
| 2585 |
|
| 2586 |
--- |
| 2587 |
|
| 2588 |
**-i|--install-system-wide** |
| 2589 |
|
| 2590 |
> Write output to the system-wide completions dir of shell |
| 2591 |
|
| 2592 |
--- |
| 2593 |
|
| 2594 |
**-u|--uninstall-system-wide** |
| 2595 |
|
| 2596 |
> Uninstall the system-wide completion file for program |
| 2597 |
|
| 2598 |
## When Conditionals |
| 2599 |
|
| 2600 |
Options and Positional Arguments can include a `when` attribute that defines |
| 2601 |
a condition under which the option (or positional argument) should be |
| 2602 |
activated. |
| 2603 |
|
| 2604 |
### has\_option |
| 2605 |
|
| 2606 |
> **Syntax**: `has_option OPTION...` |
| 2607 |
|
| 2608 |
> Checks if one or more specified options have been provided on the command line. |
| 2609 |
|
| 2610 |
> **NOTE**: The options used inside the condition have also to be defined as options! |
| 2611 |
|
| 2612 |
**Examples:** |
| 2613 |
|
| 2614 |
```yaml |
| 2615 |
# This activates --conditional if --foo, --bar or --baz are present on the command line |
| 2616 |
|
| 2617 |
[...] |
| 2618 |
options: |
| 2619 |
- option_strings: ["--conditional"] |
| 2620 |
when: "has_option --foo --bar --baz" |
| 2621 |
|
| 2622 |
- option_strings: ["--foo", "--bar", "--baz"] |
| 2623 |
[...] |
| 2624 |
``` |
| 2625 |
|
| 2626 |
### option\_is |
| 2627 |
|
| 2628 |
> **Syntax**: `option_is [ANY] [NOCASE] OPTION... -- VALUE...` |
| 2629 |
|
| 2630 |
> Checks if one or more specified options have been set to a specific value. |
| 2631 |
|
| 2632 |
> If `ANY` is specified, the match succeeds if any of the found options matches; otherwise, only the last option is checked. |
| 2633 |
|
| 2634 |
> If `NOCASE` is specified, perform a case-insensitive match. |
| 2635 |
|
| 2636 |
> **NOTE**: The options used inside the condition have also to be defined as options! |
| 2637 |
|
| 2638 |
**Example:** |
| 2639 |
|
| 2640 |
```yaml |
| 2641 |
# This activates --conditional if --foo, --bar or --baz are set to value1, value2 or value3 |
| 2642 |
|
| 2643 |
[...] |
| 2644 |
options: |
| 2645 |
- option_strings: ["--conditional"] |
| 2646 |
when: "option_is --foo --bar --baz -- value1 value2 value3" |
| 2647 |
|
| 2648 |
- option_strings: ["--foo", "--bar", "--baz"] |
| 2649 |
complete: ["none"] |
| 2650 |
[...] |
| 2651 |
``` |
| 2652 |
|
| 2653 |
### option\_match |
| 2654 |
|
| 2655 |
> **Syntax**: `option_match [ANY] [NOCASE] OPTION... -- REGEX` |
| 2656 |
|
| 2657 |
> Checks if one or more specified options match an extended regular expression. |
| 2658 |
|
| 2659 |
> If `ANY` is specified, the match succeeds if any of the found options matches; otherwise, only the last option is checked. |
| 2660 |
|
| 2661 |
> If `NOCASE` is specified, perform a case-insensitive match. |
| 2662 |
|
| 2663 |
> **NOTE**: The options used inside the condition have also to be defined as options! |
| 2664 |
|
| 2665 |
**Example:** |
| 2666 |
|
| 2667 |
```yaml |
| 2668 |
[...] |
| 2669 |
options: |
| 2670 |
- option_strings: ["--conditional"] |
| 2671 |
when: "option_match NOCASE --foo --bar -- 'foo[0-9]+'" |
| 2672 |
|
| 2673 |
- option_strings: ["--foo", "--bar"] |
| 2674 |
complete: ["none"] |
| 2675 |
[...] |
| 2676 |
``` |
| 2677 |
|
| 2678 |
|
| 2679 |
### positional\_count |
| 2680 |
|
| 2681 |
> **Syntax**: `positional_count OPERATOR NUMBER` |
| 2682 |
|
| 2683 |
> Checks the number of given positionals on the command line. |
| 2684 |
|
| 2685 |
**Example:** |
| 2686 |
|
| 2687 |
```yaml |
| 2688 |
# This activates --conditional if one or more positionals are given on the command line |
| 2689 |
|
| 2690 |
[...] |
| 2691 |
options: |
| 2692 |
- option_strings: ["--conditional"] |
| 2693 |
when: "positional_count >= 1" |
| 2694 |
|
| 2695 |
positionals: |
| 2696 |
- number: 1 |
| 2697 |
repeatable: true |
| 2698 |
[...] |
| 2699 |
``` |
| 2700 |
|
| 2701 |
### positional\_contains |
| 2702 |
|
| 2703 |
> **Syntax**: `positional_contains [NOCASE] NUMBER VALUES...` |
| 2704 |
|
| 2705 |
> Checks if a positional has a specific value. |
| 2706 |
|
| 2707 |
> If `NOCASE` is specified, perform a case-insensitive match. |
| 2708 |
|
| 2709 |
**Example:** |
| 2710 |
|
| 2711 |
```yaml |
| 2712 |
# This activates --conditional if positional number 1 is either "foo" or "bar" |
| 2713 |
|
| 2714 |
[...] |
| 2715 |
options: |
| 2716 |
- option_strings: ["--conditional"] |
| 2717 |
when: "positional_contains 1 foo bar" |
| 2718 |
|
| 2719 |
positionals: |
| 2720 |
- number: 1 |
| 2721 |
[...] |
| 2722 |
``` |
| 2723 |
|
| 2724 |
### positional\_match |
| 2725 |
|
| 2726 |
> **Syntax**: `positional_match [NOCASE] NUMBER REGEX` |
| 2727 |
|
| 2728 |
> Checks if a positional matches an extended reguar expression. |
| 2729 |
|
| 2730 |
> If `NOCASE` is specified, perform a case-insensitive match. |
| 2731 |
|
| 2732 |
**Example:** |
| 2733 |
|
| 2734 |
```yaml |
| 2735 |
[...] |
| 2736 |
options: |
| 2737 |
- option_strings: ["--conditional"] |
| 2738 |
when: "positional_match NOCASE 1 'foo[0-9]+'" |
| 2739 |
|
| 2740 |
positionals: |
| 2741 |
- number: 1 |
| 2742 |
[...] |
| 2743 |
``` |
| 2744 |
|
| 2745 |
### Multiple conditions |
| 2746 |
|
| 2747 |
> Multiple conditions can be combined using the logical operators `&&` (**AND**) and `||` (**OR**). |
| 2748 |
|
| 2749 |
> Expressions can be grouped using parentheses `(` and `)` to control evaluation order. |
| 2750 |
|
| 2751 |
> The negation operator `!` is also supported for logical **NOT** expressions. |
| 2752 |
|
| 2753 |
**Example:** |
| 2754 |
|
| 2755 |
```yaml |
| 2756 |
# This activates --conditional if --foo is given but --bar is not given. |
| 2757 |
|
| 2758 |
[...] |
| 2759 |
options: |
| 2760 |
- option_strings: ["--conditional"] |
| 2761 |
when: "has_option --foo && ! has_option --bar" |
| 2762 |
|
| 2763 |
- option_strings: ["--foo"] |
| 2764 |
|
| 2765 |
- option_strings: ["--bar"] |
| 2766 |
[...] |
| 2767 |
``` |
| 2768 |
|
| 2769 |
## Capturing Options |
| 2770 |
|
| 2771 |
Options can include a `capture` field to store their values for later use. |
| 2772 |
|
| 2773 |
The value of `capture` is the **name of a variable** that will receive all values passed to that option. |
| 2774 |
|
| 2775 |
- The captured variable is always an **array**, containing one element for each occurence of the option on the command line. |
| 2776 |
- This makes it easy to implement **context-sensitive completions** that depend on previously supplied option values |
| 2777 |
|
| 2778 |
> **NOTE:** In **Fish**, captured variables are stored as global variables. |
| 2779 |
> To avoid interfering with the user's environment, it is highly recommended to use distinctive variable names. |
| 2780 |
> Variable names should begin with an underscore and include a program-specific prefix (for example, `_MYTOOL_DATABASE`). |
| 2781 |
|
| 2782 |
**Example:** |
| 2783 |
|
| 2784 |
```yaml |
| 2785 |
prog: my_db_tool |
| 2786 |
options: |
| 2787 |
- option_strings: ["--database", "-d"] |
| 2788 |
complete: ["choices", ["mysql", "postgres", "sqlite"]] |
| 2789 |
capture: "_MYDBTOOL_DATABASE" |
| 2790 |
|
| 2791 |
- option_strings: ["--table", "-t"] |
| 2792 |
complete: ["exec", "_my_db_tool_complete_table"] |
| 2793 |
``` |
| 2794 |
|
| 2795 |
For **Bash** and **Zsh**: |
| 2796 |
|
| 2797 |
```bash |
| 2798 |
_my_db_tool_complete_table() { |
| 2799 |
case "${_MYDBTOOL_DATABASE[-1]}" in |
| 2800 |
mysql) printf '%s\n' users orders products;; |
| 2801 |
postgres) printf '%s\n' customers invoices transactions;; |
| 2802 |
sqlite) printf '%s\n' local_cache config sessions;; |
| 2803 |
esac |
| 2804 |
} |
| 2805 |
``` |
| 2806 |
|
| 2807 |
For **Fish**: |
| 2808 |
|
| 2809 |
```fish |
| 2810 |
function _my_db_tool_complete_table |
| 2811 |
switch $_MYDBTOOL_DATABASE[-1] |
| 2812 |
case mysql; printf '%s\n' users orders products |
| 2813 |
case postgres; printf '%s\n' customers invoices transactions |
| 2814 |
case sqlite; printf '%s\n' local_cache config sessions |
| 2815 |
end |
| 2816 |
end |
| 2817 |
``` |
| 2818 |
|
| 2819 |
## Tips and Tricks |
| 2820 |
|
| 2821 |
It is always recommended to define your command line **as precisely as possible**. |
| 2822 |
This helps crazy-complete generate reliable completions. Key practices include: |
| 2823 |
- **Final options**: Use `final: true` for options like `--help` and `--version` that should |
| 2824 |
prevent further options from being completed |
| 2825 |
- **Hidden options**: Use `hidden: true` for options that should be completable but not shown |
| 2826 |
in the suggestion list |
| 2827 |
- **Mutually exclusive options**: Use `groups: [...]` to define sets of options that cannot appear |
| 2828 |
together |
| 2829 |
- **Repeatable options**: Use `repeatable: true` for options that may be used more than once |
| 2830 |
|
| 2831 |
### Trying out zsh autocompletion scripts |
| 2832 |
|
| 2833 |
By default, crazy-complete generates scripts that should be installed under `/usr/share/zsh/site-functions` |
| 2834 |
and loaded from there. If you want to try the generated scripts directly, use `--zsh-compdef=False`. |
| 2835 |
|
| 2836 |
### Optimizing Script Output |
| 2837 |
|
| 2838 |
Especially for **Fish** scripts, performance can decrease if many options are defined. |
| 2839 |
Features like final options and non-repeatable options require extra conditional code to execute, which can make completions slower. |
| 2840 |
|
| 2841 |
To improve performance these features can be completely disabled using: |
| 2842 |
|
| 2843 |
``` |
| 2844 |
crazy-complete fish --disable=final,repeatable DEFINITION_FILE |
| 2845 |
``` |
| 2846 |
|
| 2847 |
This turns off final and repeatable option handling, reducing script size and improving completion speed |