| 1 |
crazy-complete |
| 2 |
============== |
| 3 |
|
| 4 |
Every program should have autocompletion in the shell to enhance user experience and productivity. crazy-complete helps solve this task by generating robust and reliable autocompletion scripts. |
| 5 |
|
| 6 |
**Key Features**: |
| 7 |
- **Generates Robust Scripts**: Ensures that the autocompletion scripts are reliable and efficient. |
| 8 |
- **Multi-Shell Support**: Works seamlessly with **Bash**, **Fish**, and **Zsh**, providing flexibility across different environments. |
| 9 |
- **Minimal Dependencies**: The only external dependency is PyYAML. |
| 10 |
- **Configurable and Extendable**: The generated autocompletion scripts are highly configurable and can be easily extended to suit your specific needs. |
| 11 |
- **Standalone Scripts**: The generated scripts are standalone and do not depend on modified environments, unlike some alternatives like argcomplete. |
| 12 |
- **Easy to Use**: Simple and intuitive to set up, allowing you to quickly add autocompletion functionality to your programs. |
| 13 |
|
| 14 |
With crazy-complete, adding autocompletion to your programs has never been easier. Try it out and see the difference it makes in your command-line applications! |
| 15 |
|
| 16 |
Table of Contents |
| 17 |
================= |
| 18 |
|
| 19 |
- [Benefits of Using crazy-complete](#benefits-of-using-crazy-complete) |
| 20 |
- [Disadvantages of crazy-complete](#disadvantages-of-crazy-complete) |
| 21 |
- [Installation](#installation) |
| 22 |
- [Synposis](#synopsis) |
| 23 |
- [Usage examples](#usage-examples) |
| 24 |
- [Definition file examples](#definition-file-examples) |
| 25 |
- [Documentation](#documentation) |
| 26 |
- [Comparision with other auto-complete generators](#comparision-with-other-auto-complete-generators) |
| 27 |
- [Questions or problems](#questions-or-problems) |
| 28 |
|
| 29 |
Benefits of Using crazy-complete |
| 30 |
================================ |
| 31 |
|
| 32 |
- **Focus on what matters:** |
| 33 |
crazy-complete generates the basic structure of your autocompletion scripts, |
| 34 |
so you can focus entirely on defining options and their completions instead of dealing with repetitive setup code. |
| 35 |
|
| 36 |
- **Cross-shell consistency:** |
| 37 |
Write your completion logic once and get reliable completions for **Bash**, **Zsh**, and **Fish**, with identical behavior across all shells. |
| 38 |
|
| 39 |
- **Powerful argument completion:** |
| 40 |
crazy-complete provides a rich set of [built-in](docs/documentation.md#built-in-commands) helpers for argument completion and makes it simple to define your own [custom argument handlers](docs/documentation.md#user-defined-commands). |
| 41 |
|
| 42 |
- **Arbitrary levels of subcommands:** |
| 43 |
No matter how deeply nested your CLI structure is, crazy-complete can handle it. |
| 44 |
You can define completions for commands, subcommands, and even sub-subcommands without extra effort. |
| 45 |
|
| 46 |
- **Full control over options:** |
| 47 |
- **Repeatable / non-repeatable options**: control whether options can be used once or multiple times. |
| 48 |
- **Mutually exclusive options**: ensure that incompatible options cannot appear together. |
| 49 |
- **Conditional options**: only suggest options when certain conditions are met. |
| 50 |
- **Final options**: options that prevent any further options from being completed. |
| 51 |
- **Hidden options**: completable options that are not shown in the suggestion list. |
| 52 |
- **Capturing options**: collect options and their values to enable advanced, context-sensitive completions. |
| 53 |
|
| 54 |
Disadvantages of crazy-complete |
| 55 |
=============================== |
| 56 |
|
| 57 |
While crazy-complete offers many advantages, there are some trade-offs to be aware of: |
| 58 |
|
| 59 |
- **Code size and verbosity:** |
| 60 |
Its biggest strength - **secure, fully controlled completions** - can also be its biggest weakness. |
| 61 |
- For **Bash**, this means the generated scripts contain a significant amount of boilerplate code for parsing options and positional arguments. |
| 62 |
- For **Fish**, large command-line definitions (more than 1000 options) may result in slower completions, although performance is usually acceptable for most use cases. |
| 63 |
- **Mitigation:** There are ways to reduce script size and improve performance. See [Tips And Tricks](docs/documentation.md#tips-and-tricks) for more details. |
| 64 |
- **Not as optimized as hand-written scripts:** |
| 65 |
The generated scripts prioritize correctness and reliability over minimal size or maximum performance. Hand-written scripts may be more compact and slightly faster in some cases. |
| 66 |
|
| 67 |
Installation |
| 68 |
============ |
| 69 |
|
| 70 |
|Operating System | Download | Command | |
| 71 |
|-----------------------|--------------------------------|------------------------------------------------- |
| 72 |
|Arch Linux | [%TAG%](%ARCHLINUX_URL%) | `sudo pacman -U ./%ARCHLINUX_PACKAGE%` | |
| 73 |
|Debian Trixie | [%TAG%](%DEBIAN_TRIXIE_URL%) | `sudo apt install ./%DEBIAN_TRIXIE_PACKAGE%` | |
| 74 |
|Debian Bookworm | [%TAG%](%DEBIAN_BOOKWORM_URL%) | `sudo apt install ./%DEBIAN_BOOKWORM_PACKAGE%` | |
| 75 |
|Ubuntu Noble | [%TAG%](%UBUNTU_NOBLE_URL%) | `sudo apt install ./%UBUNTU_NOBLE_PACKAGE%` | |
| 76 |
|Ubuntu Jammy | [%TAG%](%UBUNTU_JAMMY_URL%) | `sudo apt install ./%UBUNTU_JAMMY_PACKAGE%` | |
| 77 |
|Linux Mint 22 | [%TAG%](%LINUX_MINT_22_URL%) | `sudo apt install ./%LINUX_MINT_22_PACKAGE%` | |
| 78 |
|Linux Mint 21 | [%TAG%](%LINUX_MINT_21_URL%) | `sudo apt install ./%LINUX_MINT_21_PACKAGE%` | |
| 79 |
|Fedora 44 | [%TAG%](%FEDORA_44_URL%) | `sudo dnf install ./%FEDORA_44_PACKAGE%` | |
| 80 |
|Fedora 43 | [%TAG%](%FEDORA_43_URL%) | `sudo dnf install ./%FEDORA_43_PACKAGE%` | |
| 81 |
|OpenSuse (Tumbleweed) | [%TAG%](%OPENSUSE_URL%) | `sudo zypper install ./%OPENSUSE_PACKAGE%` | |
| 82 |
|
| 83 |
- For other Linux distributions: |
| 84 |
``` |
| 85 |
git clone https://github.com/crazy-complete/crazy-complete |
| 86 |
cd crazy-complete |
| 87 |
python3 -m pip install . |
| 88 |
``` |
| 89 |
|
| 90 |
Synopsis |
| 91 |
======== |
| 92 |
|
| 93 |
> `crazy-complete [OPTIONS] {bash,fish,zsh,yaml,json} <DEFINITION_FILE>` |
| 94 |
|
| 95 |
See [docs/documentation.md#options](docs/documentation.md#options) for a list of options. |
| 96 |
|
| 97 |
Completions for crazy-complete |
| 98 |
============================== |
| 99 |
|
| 100 |
To install system-wide completion files for crazy-complete, execute the following: |
| 101 |
|
| 102 |
``` |
| 103 |
sudo crazy-complete --input-type=python -i bash "$(which crazy-complete)" |
| 104 |
sudo crazy-complete --input-type=python -i fish "$(which crazy-complete)" |
| 105 |
sudo crazy-complete --input-type=python -i zsh "$(which crazy-complete)" |
| 106 |
``` |
| 107 |
|
| 108 |
If you want to uninstall the completion files, pass `-u` to crazy-complete: |
| 109 |
|
| 110 |
``` |
| 111 |
sudo crazy-complete --input-type=python -u bash "$(which crazy-complete)" |
| 112 |
sudo crazy-complete --input-type=python -u fish "$(which crazy-complete)" |
| 113 |
sudo crazy-complete --input-type=python -u zsh "$(which crazy-complete)" |
| 114 |
``` |
| 115 |
|
| 116 |
Usage examples |
| 117 |
============== |
| 118 |
|
| 119 |
Converting a Python script to YAML: |
| 120 |
|
| 121 |
``` |
| 122 |
crazy-complete --input-type=python yaml my_program.py |
| 123 |
``` |
| 124 |
|
| 125 |
Generate a YAML file from help text: |
| 126 |
|
| 127 |
``` |
| 128 |
grep --help > help_file |
| 129 |
crazy-complete --input-type=help yaml help_file |
| 130 |
- or - |
| 131 |
grep --help | crazy-complete --input-type=help yaml /dev/stdin |
| 132 |
``` |
| 133 |
|
| 134 |
Generate shell auto completions for Bash: |
| 135 |
|
| 136 |
``` |
| 137 |
crazy-complete --input-type=yaml --include-file my_program.bash bash my_program.yaml |
| 138 |
``` |
| 139 |
|
| 140 |
Definition file examples |
| 141 |
======================== |
| 142 |
|
| 143 |
See [examples](https://github.com/crazy-complete/crazy-complete/tree/main/examples) for examples. |
| 144 |
|
| 145 |
See [completions](https://github.com/crazy-complete/completions) for real world applications of crazy-complete. |
| 146 |
|
| 147 |
You can even have a look at the [tests](https://github.com/crazy-complete/crazy-complete/tree/main/test). |
| 148 |
|
| 149 |
Documentation |
| 150 |
============= |
| 151 |
|
| 152 |
See [docs/documentation.md](docs/documentation.md). |
| 153 |
|
| 154 |
Comparision with other auto-complete generators |
| 155 |
=============================================== |
| 156 |
|
| 157 |
See [docs/comparision.md](docs/comparision.md) for a comparision with other tools. |
| 158 |
|
| 159 |
Questions or problems |
| 160 |
===================== |
| 161 |
|
| 162 |
Don't hesitate to open an issue on [GitHub](https://github.com/crazy-complete/crazy-complete/issues). |