Skip to content

Commit 260a118

Browse files
committed
docs(api-and-naming): add general conventions/output variables section
1 parent 5435b7c commit 260a118

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

doc/api-and-naming.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,25 @@
11
# API and naming
22

3+
## General API conventions
4+
5+
Most of the functions in bash-completion generate completions and directly
6+
inject them to the `COMPREPLY` array variable, as required for completions to
7+
work.
8+
9+
Most other functions make use of "output" variables, i.e. assign values to
10+
them. The most common one of these is named `ret`. Consult the commentary
11+
before each function in the source to find out the specific names.
12+
`local`izing output variables before invoking a function that populates them
13+
is the caller's responsibility.
14+
Note that if calling multiple functions that assign output to the same variable
15+
during one completion function run, each result should be copied to another
16+
variable between the calls to avoid it possibly being overwritten and lost on
17+
the next call. Also, the variables should also be ensured to be clear before
18+
each call, typically by `unset -v`ing them when multiple such calls are used,
19+
to avoid them interfering with each other.
20+
21+
## Naming
22+
323
Due to its nature, bash-completion adds a number of functions and variables in
424
the shell's environment.
525

0 commit comments

Comments
 (0)