Restore bash completion behaviour for bash 4.x

In Pull Request #178, the use of `builtin compopt` as a test condition
is inappropriate.  Use `[[ $(type -t compopt) = "builtin" ]]` instead.

Also clean up formatting of the resulting bash completion script.
This commit is contained in:
Anthony Fok 2015-11-07 04:33:18 -07:00
parent 5c40aa85ca
commit 0e4c02d9cb
1 changed files with 13 additions and 13 deletions

View File

@ -60,7 +60,7 @@ __handle_reply()
__debug "${FUNCNAME}" __debug "${FUNCNAME}"
case $cur in case $cur in
-*) -*)
if builtin compopt > /dev/null 2>&1; then if [[ $(type -t compopt) = "builtin" ]]; then
compopt -o nospace compopt -o nospace
fi fi
local allflags local allflags
@ -70,7 +70,7 @@ __handle_reply()
allflags=("${flags[*]} ${two_word_flags[*]}") allflags=("${flags[*]} ${two_word_flags[*]}")
fi fi
COMPREPLY=( $(compgen -W "${allflags[*]}" -- "$cur") ) COMPREPLY=( $(compgen -W "${allflags[*]}" -- "$cur") )
if builtin compopt > /dev/null 2>&1; then if [[ $(type -t compopt) = "builtin" ]]; then
[[ $COMPREPLY == *= ]] || compopt +o nospace [[ $COMPREPLY == *= ]] || compopt +o nospace
fi fi
return 0; return 0;
@ -220,12 +220,12 @@ func postscript(out *bytes.Buffer, name string) {
} }
`, name) `, name)
fmt.Fprintf(out, ` fmt.Fprintf(out, `if [[ $(type -t compopt) = "builtin" ]]; then
if builtin compopt > /dev/null 2>&1; then
complete -F __start_%s %s complete -F __start_%s %s
else else
complete -o nospace -F __start_%s %s complete -o nospace -F __start_%s %s
fi fi
`, name, name, name, name) `, name, name, name, name)
fmt.Fprintf(out, "# ex: ts=4 sw=4 et filetype=sh\n") fmt.Fprintf(out, "# ex: ts=4 sw=4 et filetype=sh\n")
} }