GNU advises to use --name=value syntax for passing argument for long option. It enables a long option to accept an argument that is itself optional.
Suppose you have a complete set of possible arguments. How do you write a bash completion code for such an option? I want the completion to add space when it completes an unambiguous argument, but not before.
Here is the template code I wrote for completing GNU options given in the code for imaginary command
gnu-options
.Options that do not take arguments are defined in array
opts
. Options that do possibly take argument are defined in associative arrayargs
. Note that aswith-args0
appears in both it is an option with optional argument.The script supports even case where
$COMP_WORDBREAKS
does not include '=', but the shown completions are longer then.