Skip to content

Commit bd77d1a

Browse files
committed
docs(api-and-naming): start exporter local var names with underscores
Exporter functions must avoid conflicts between the passed variable names and their internal local variables. Differentiate using an underscore. #539 (comment)
1 parent c2097d5 commit bd77d1a

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

doc/api-and-naming.md

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
Due to its nature, bash-completion adds a number of functions and variables in
44
the shell's environment.
55

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-
| | | `_comp_xfunc_${Command}_${Utility}` (functions for use with `_comp_xfunc`) |
12-
| private/internal functions | `_comp__*` | `_comp_cmd_${Command}__${Utility}` (utility functions) |
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+
| exporter function local variables | `_*` (not `_comp*`) | `_*` (not `_comp*`) |
11+
| public/exported functions | `_comp_*` | `_comp_cmd_${Command}` (functions for `complete -F`) |
12+
| | | `_comp_xfunc_${Command}_${Utility}` (functions for use with `_comp_xfunc`) |
13+
| private/internal functions | `_comp__*` | `_comp_cmd_${Command}__${Utility}` (utility functions) |
1314

1415
`${Command}` refers to a command name (with characters not allowed in POSIX
1516
function or variable names replaced by an underscore), `${Config}` the name of
@@ -38,6 +39,11 @@ sharing a common prefix. For example, a function named `_comp_foo` is "allowed"
3839
to access `_comp_foo__*` where `*` does not contain any double underscores,
3940
i.e. it should not access `_comp_foo__something__*` despite the common prefix.
4041

42+
Internal local variables of functions that "export" their results using a
43+
variable name that is passed in start with an underscore and do not start with
44+
`_comp`. The variable names that are passed in for this purpose must not start
45+
with an underscore.
46+
4147
Functions with names prefixed with `_comp_xfunc_` are intended to be used
4248
through the `_comp_xfunc` function from files other than the one they are
4349
defined in. From the same file they can be used directly using their complete

0 commit comments

Comments
 (0)