Add word boundary support for GNU sed in zsh completion

pull/6/head
Dr. Stefan Schimanski 2016-04-22 18:29:38 +02:00
parent 8c170ff5ff
commit 0d6d0a5662
1 changed files with 16 additions and 7 deletions

View File

@ -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
)