|
| 1 | +# Completely - Bash Completions Generator |
| 2 | + |
| 3 | +[](https://badge.fury.io/rb/completely) |
| 4 | +[](https://github.com/DannyBen/completely/actions?query=workflow%3ATest) |
| 5 | + |
| 6 | +--- |
| 7 | + |
| 8 | +Completely is a command line utility and a Ruby library that lets you generate |
| 9 | +bash completion scripts from simple YAML configuration. |
| 10 | + |
| 11 | +This tool is for you it: |
| 12 | + |
| 13 | +1. You develop your own command line tools. |
| 14 | +2. Your life feels empty without bash completions. |
| 15 | +3. Bash completion scripts scare you. |
| 16 | + |
| 17 | +--- |
| 18 | + |
| 19 | + |
| 20 | +## Install |
| 21 | + |
| 22 | +``` |
| 23 | +$ gem install completely |
| 24 | +``` |
| 25 | + |
| 26 | +## Usage |
| 27 | + |
| 28 | +The `completely` command line works with a simple YAML configuration file as |
| 29 | +input, and generates a bash completions script as output. |
| 30 | + |
| 31 | +The configuration file is built like this: |
| 32 | + |
| 33 | +```yaml |
| 34 | +pattern: |
| 35 | + - --argument |
| 36 | + - --param |
| 37 | + - command |
| 38 | +``` |
| 39 | +
|
| 40 | +You can save a sample YAML file by running: |
| 41 | +
|
| 42 | +``` |
| 43 | +$ completely new |
| 44 | +``` |
| 45 | + |
| 46 | +This will generate a file named `completely.yaml` with this content: |
| 47 | + |
| 48 | +```yaml |
| 49 | +mygit: |
| 50 | +- --help |
| 51 | +- --version |
| 52 | +- status |
| 53 | +- init |
| 54 | +- commit |
| 55 | + |
| 56 | +mygit status: |
| 57 | +- --help |
| 58 | +- --verbose |
| 59 | +- --branch |
| 60 | + |
| 61 | +mygit init: |
| 62 | +- --bare |
| 63 | +- <directory> |
| 64 | + |
| 65 | +mygit commit: |
| 66 | +- <file> |
| 67 | +- --help |
| 68 | +- --message |
| 69 | +- --all |
| 70 | +- -a |
| 71 | +- --quiet |
| 72 | +- -q |
| 73 | +``` |
| 74 | +
|
| 75 | +Each pattern in this configuration file will be checked against the user's |
| 76 | +input, and if the input **starts with** a matching pattern, the list that |
| 77 | +follows it will be suggested as completions. |
| 78 | +
|
| 79 | +To generate the bash script, simply run: |
| 80 | +
|
| 81 | +``` |
| 82 | +$ completely generate |
| 83 | + |
| 84 | +# or, to just preview it without saving: |
| 85 | +$ completely preview |
| 86 | +``` |
| 87 | + |
| 88 | +For more options (like setting input/output path), run |
| 89 | + |
| 90 | +``` |
| 91 | +$ completely --help |
| 92 | +``` |
| 93 | + |
| 94 | +### Suggesting files and directories |
| 95 | + |
| 96 | +You may have noticed that the sample file contains two special entries: |
| 97 | + |
| 98 | +- `<file>` |
| 99 | +- `<directory>` |
| 100 | + |
| 101 | +These patterns will add the list of files and directories |
| 102 | +(when `<file>` is used) or just directories (when `<directory` is used) to |
| 103 | +the list of suggestions. |
| 104 | + |
| 105 | +For those interested in the technical details, any word between `<...>` will |
| 106 | +simply be added using the [`compgen -A action`][compgen] function, so you can |
| 107 | +in fact use any of its supported arguments. |
| 108 | + |
| 109 | + |
| 110 | +### Using the generated completion scripts |
| 111 | + |
| 112 | +In order to enable the completions, simply source the generated script: |
| 113 | + |
| 114 | +``` |
| 115 | +$ source completely.bash |
| 116 | +``` |
| 117 | + |
| 118 | +You may wish to add this to your `~/.bashrc` file to enable this for future |
| 119 | +sessions (just be sure to use absolute path). |
| 120 | + |
| 121 | + |
| 122 | +## Contributing / Support |
| 123 | + |
| 124 | +If you experience any issue, have a question or a suggestion, or if you wish |
| 125 | +to contribute, feel free to [open an issue][issues]. |
| 126 | + |
| 127 | +--- |
| 128 | + |
| 129 | +[issues]: https://github.com/DannyBen/completely/issues |
| 130 | +[compgen]: https://www.gnu.org/software/bash/manual/html_node/Programmable-Completion-Builtins.html |
0 commit comments