@@ -145,7 +145,8 @@ specified by `-v var` in `OPTS`).
145
145
### Implementing a generator function
146
146
147
147
To implement a generator function, one should generate completion candidates by
148
- calling ` _comp_compgen ` or other generators. One should not directly modify or
148
+ calling ` _comp_compgen ` or other generators. To avoid conflicts with the
149
+ options specified to ` _comp_compgen ` , one should not directly modify or
149
150
reference the target variable. When post-filtering is needed, store them in
150
151
local arrays, filter them, and finally append them by `_ comp_compgen -- -W
151
152
"${arr[ @] }"`.
@@ -166,9 +167,11 @@ The exit status is implementation-defined.
166
167
` _comp_compgen_help || _comp_compgen_usage ` .
167
168
168
169
Whether to clear the target variable on runtime error (when ` -a ` is not
169
- specified in ` OPTS ` ) is implementation-defined. On the other hand, the
170
+ specified in ` OPTS ` ) is implementation-defined. On the other hand, the
170
171
generator function should not leave any side effects in the target variable on
171
- usage error.
172
+ usage error. Note that the target variable might be cleared by the internal
173
+ calls of ` _comp_compgen ` . To explicitly clear the target variable,
174
+ ` _comp_compgen_set ` can be called without arguments.
172
175
173
176
Exported generators are defined with the names ` _comp_xfunc_CMD_compgen_NAME `
174
177
and called by ` _comp_compgen [opts] -x CMD NAME args ` . Internal generators are
0 commit comments