|
| 1 | +# API and naming |
| 2 | + |
| 3 | +Due to its nature, bash-completion adds a number of functions and variables in |
| 4 | +the shell's environment. |
| 5 | + |
| 6 | +| | `bash_completion` | `completions/*` | |
| 7 | +| :----------------------------- | :------------------ | :----------------------------------------------------- | |
| 8 | +| public configuration variables | `BASH_COMPLETION_*` | `BASH_COMPLETION_CMD_${Command^^}_${Config^^}` | |
| 9 | +| non-local internal variables | `_comp__*` | `_comp_cmd_${Command}__${Data}` | |
| 10 | +| public/exported functions | `_comp_*` | `_comp_cmd_${Command}` (functions for `complete -F`) | |
| 11 | +| private/internal functions | `_comp__*` | `_comp_cmd_${Command}__${Utility}` (utility functions) | |
| 12 | + |
| 13 | +`${Command}` refers to a command name (with characters not allowed in POSIX |
| 14 | +function or variable names replaced by an underscore), `${Config}` the name of |
| 15 | +a configurable thing, `^^` means uppercase, `${Data}` is an identifier for the |
| 16 | +data contained in the variable, and `${Utility}` describes the typical usage of |
| 17 | +the function. |
| 18 | + |
| 19 | +Variables and functions affecting multiple completions are usually defined |
| 20 | +in the main `bash_completion` file and do not require any additional files to |
| 21 | +be sourced. Variables and functions in command specific completion files in |
| 22 | +`completions/*` follow a slightly different naming scheme; they include |
| 23 | +`cmd` in their name as well as the name of the command. |
| 24 | + |
| 25 | +Public configuration variables are shell ones that affect the runtime behavior |
| 26 | +of various completions. As a rule of thumb, we lean towards not providing |
| 27 | +customizability but rather strive to provide great completion behavior out of |
| 28 | +the box. But there are some, see [configuration](configuration.md). |
| 29 | + |
| 30 | +Variables and functions whose name contains a double underscore (`__`) anywhere |
| 31 | +in their name are private implementation details, not part of the stable API, |
| 32 | +and not intended to be used outside of their defining context. |
| 33 | + |
| 34 | +Function names start with an underscore in order to avoid them being |
| 35 | +included in completions of command names. (Except naturally when a command |
| 36 | +starting with an underscore is being completed.) The underscore prefix does |
| 37 | +not have anything to do with whether the thing is considered public or |
| 38 | +private in the API, nor anything else really. |
| 39 | + |
| 40 | +The `BASH_COMPLETION_` prefix provides a namespace and makes it clear what |
| 41 | +these variables relate to. The `_comp` in other names serves a similar purpose, |
| 42 | +but because these are used a lot in the code (unlike the public configuration |
| 43 | +variables), using something shorter is beneficial. We hope and believe this is |
| 44 | +distinctive and clash free enough. |
| 45 | + |
| 46 | +It is known that a lot of functions and variables in the tree do not follow |
| 47 | +these naming rules yet. Things introduced after version 2.11 should, and we are |
| 48 | +evaluating our options for handling older ones. |
0 commit comments