mirror of
https://github.com/spf13/cobra
synced 2024-11-24 14:47:12 +00:00
Merge pull request #178 from mattnenterprise/completions-osx
Modifying bash completions so they can run on OSX
This commit is contained in:
commit
9199ed1e52
1 changed files with 13 additions and 3 deletions
|
@ -60,7 +60,9 @@ __handle_reply()
|
||||||
__debug "${FUNCNAME}"
|
__debug "${FUNCNAME}"
|
||||||
case $cur in
|
case $cur in
|
||||||
-*)
|
-*)
|
||||||
|
if builtin compopt > /dev/null 2>&1; then
|
||||||
compopt -o nospace
|
compopt -o nospace
|
||||||
|
fi
|
||||||
local allflags
|
local allflags
|
||||||
if [ ${#must_have_one_flag[@]} -ne 0 ]; then
|
if [ ${#must_have_one_flag[@]} -ne 0 ]; then
|
||||||
allflags=("${must_have_one_flag[@]}")
|
allflags=("${must_have_one_flag[@]}")
|
||||||
|
@ -68,7 +70,9 @@ __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
|
||||||
[[ $COMPREPLY == *= ]] || compopt +o nospace
|
[[ $COMPREPLY == *= ]] || compopt +o nospace
|
||||||
|
fi
|
||||||
return 0;
|
return 0;
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
@ -216,7 +220,13 @@ func postscript(out *bytes.Buffer, name string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
`, name)
|
`, name)
|
||||||
fmt.Fprintf(out, "complete -F __start_%s %s\n", name, name)
|
fmt.Fprintf(out, `
|
||||||
|
if builtin compopt > /dev/null 2>&1; then
|
||||||
|
complete -F __start_%s %s
|
||||||
|
else
|
||||||
|
complete -o nospace -F __start_%s %s
|
||||||
|
fi
|
||||||
|
`, 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")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue