I am trying to write a Bash completion function for completing long command line options like --param1=value1
. This works fine if value1
is not quoted. But in many cases value1
needs to be quoted, for example, --param1='Hello world'
. In this case, Bash completion stops working. For example:
_myprog()
{
local cur="${COMP_WORDS[$COMP_CWORD]}"
local words=(--param1 --param2)
COMPREPLY=( $(compgen -W "${words[*]}" -- "$cur") )
}
complete -F _myprog myprog
If I source this source script.sh
and then type myprog --param1='hello' <tab><tab>
nothing happens. It works fine if I start the quote before the double dashes, like myprog '--param1=hello' <tab><tab>
..
Any suggestions?