For my bash completion scripts, which necessarily run on across a variety of versions of bash with differing levels of support for completion, I use the following idiom to attempt the best "complete" possible, then gracefully fallback to at least something that should work; e.g., assuming a command svn2
, and a completion function called _complete_svn2
:
complete -o bashdefault -o default -o nospace -F _complete_svn2 svn2 2>/dev/null \
|| complete -o default -o nospace -F _complete_svn2 svn2 2>/dev/null \
|| complete -o default -F _complete_svn2 svn2 2>/dev/null \
|| complete -F _complete_svn2 svn2
Ideally "-o nospace
" exists and works, but if it doesn't, you can fallback to "-o default
".
Also, the above example uses a function to generate the completions, arbitrarily called _complete_svn2
. Perhaps you can try using something like that also. The following example works for me, showing matching options, not adding in the extra space, etc (it intentionally does not complete "-" options):
_complete_svn2() {
local options="one two three four five"
local cur="${COMP_WORDS[COMP_CWORD]}"
COMPREPLY=()
[[ ${cur} != -* ]] && COMPREPLY=( $(compgen -W "${options}" -- ${cur}) )
}
E.g., (and no space is added after "five")
$ svn2 f[tab]
five four
$ svn2 fi[tab]
$ svn2 five