diff --git a/contrib/completions/zsh/kubectl b/contrib/completions/zsh/kubectl index 3285a5036b7..b7aa9264c23 100755 --- a/contrib/completions/zsh/kubectl +++ b/contrib/completions/zsh/kubectl @@ -139,17 +139,26 @@ __kubectl_quote() { autoload -U +X compinit && compinit autoload -U +X bashcompinit && bashcompinit + +# use word boundary patterns for BSD or GNU sed +LWORD='[[:<:]]' +RWORD='[[:>:]]' +if sed --help 2>&1 | grep -q GNU; then + LWORD='\<' + RWORD='\>' +fi + __kubectl_bash_source <(sed \ -e 's/declare -F/whence -w/' \ -e 's/local \([a-zA-Z0-9_]*\)=/local \1; \1=/' \ -e 's/flags+=("\(--.*\)=")/flags+=("\1"); two_word_flags+=("\1")/' \ -e 's/must_have_one_flag+=("\(--.*\)=")/must_have_one_flag+=("\1")/' \ - -e 's/[[:<:]]_filedir[[:>:]]/__kubectl_filedir/g' \ - -e 's/[[:<:]]_get_comp_words_by_ref[[:>:]]/__kubectl_get_comp_words_by_ref/g' \ - -e 's/[[:<:]]__ltrim_colon_completions[[:>:]]/__kubectl_ltrim_colon_completions/g' \ - -e 's/[[:<:]]compgen[[:>:]]/__kubectl_compgen/g' \ - -e 's/[[:<:]]compopt[[:>:]]/__kubectl_compopt/g' \ - -e 's/[[:<:]]declare[[:>:]]/__kubectl_declare/g' \ - -e 's/\$(type[[:>:]]/$(__kubectl_type/g' \ + -e "s/${LWORD}_filedir${RWORD}/__kubectl_filedir/g" \ + -e "s/${LWORD}_get_comp_words_by_ref${RWORD}/__kubectl_get_comp_words_by_ref/g" \ + -e "s/${LWORD}__ltrim_colon_completions${RWORD}/__kubectl_ltrim_colon_completions/g" \ + -e "s/${LWORD}compgen${RWORD}/__kubectl_compgen/g" \ + -e "s/${LWORD}compopt${RWORD}/__kubectl_compopt/g" \ + -e "s/${LWORD}declare${RWORD}/__kubectl_declare/g" \ + -e "s/\\\$(type${RWORD}/\$(__kubectl_type/g" \ $(dirname $0)/../bash/kubectl )