I'm trying to make a generic autocomplete function (which actually takes several parameters, and has a bunch of shared logic), so that I can easily and neatly maintain a long list of similar commands, with similar autocompletes (number of arguments, etc).
I've got a bash function, which takes an argument (simplified as much as possible):
_autocomplete() {
COMPREPLY=( $(compgen -W "$1" -- "${COMP_WORDS[COMP_CWORD]}") )
return 0
}
And when I reference it, using a command which takes a function name as an argument, I want to also pass it a parameter to run in the function:
complete -F "_autocomplete example_param" some_function
However, this does not work when I hit tab, and instead errors with:
some_function bash: completion: function `_autocomplete example_param' not found
Is this a limitation of complete?
Is there any way around this, or a better approach?
Thanks.