From 3e1ca6fe6e3e2add0518925c5273b650fcb64280 Mon Sep 17 00:00:00 2001 From: Marc Khouzam Date: Mon, 6 May 2019 21:14:01 -0400 Subject: [PATCH 1/3] fix(completion): --flag=val breaks zsh completion This is a bug I ran into when working on Helm completion. I was surprised that it didn't happen when I was using kubectl, so I investigated and found a PR that fixed this bug in kubectl: https://github.com/kubernetes/kubernetes/pull/48553 I duplicated the code in this commit which: Removes __helm_declare, which is safe to do since `declare -F` is already replaced to `whence -w` by __helm_convert_bash_to_zsh(). The problem was that calling "declare" from inside a function scopes the declaration to that function only. So "declare" should not be called through __helm_declare() but instead directly. To reproduce: 1- setup helm completion in zsh 2- helm --kubeconfig=$HOME/.kube/config statu you will get the error: __helm_handle_flag:27: bad math expression: operand expected at end of string Co-authored-by: Kazuki Suda Signed-off-by: Marc Khouzam --- cmd/helm/completion.go | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/cmd/helm/completion.go b/cmd/helm/completion.go index 039dcbe5f..051f946fd 100644 --- a/cmd/helm/completion.go +++ b/cmd/helm/completion.go @@ -126,13 +126,6 @@ __helm_compgen() { __helm_compopt() { true # don't do anything. Not supported by bashcompinit in zsh } -__helm_declare() { - if [ "$1" == "-F" ]; then - whence -w "$@" - else - builtin declare "$@" - fi -} __helm_ltrim_colon_completions() { if [[ "$1" == *:* && "$COMP_WORDBREAKS" == *:* ]]; then @@ -210,7 +203,7 @@ __helm_convert_bash_to_zsh() { -e "s/${LWORD}__ltrim_colon_completions${RWORD}/__helm_ltrim_colon_completions/g" \ -e "s/${LWORD}compgen${RWORD}/__helm_compgen/g" \ -e "s/${LWORD}compopt${RWORD}/__helm_compopt/g" \ - -e "s/${LWORD}declare${RWORD}/__helm_declare/g" \ + -e "s/${LWORD}declare${RWORD}/builtin declare/g" \ -e "s/\\\$(type${RWORD}/\$(__helm_type/g" \ -e 's/aliashash\["\(.\{1,\}\)"\]/aliashash[\1]/g' \ -e 's/FUNCNAME/funcstack/g' \ From 0239cc4457463cfd6af1f61ec26aa35845dcb1c5 Mon Sep 17 00:00:00 2001 From: Marc Khouzam Date: Mon, 20 May 2019 12:56:22 -0400 Subject: [PATCH 2/3] (helm): Proper fix for #5046 PR #5072 followed by #5406 tweaked the handling of the associative array 'aliashash' when in zsh. However, upon further investigation the root of the problem was the 'aliashash' was not being declared properly as it was declared within a method and therefore not accessible to the rest of the completion script. The previous commit of this PR makes the necessary change to properly declare 'aliashash' which makes the previous tweak unecessary. This commit removes the tweak. Signed-off-by: Marc Khouzam --- cmd/helm/completion.go | 1 - 1 file changed, 1 deletion(-) diff --git a/cmd/helm/completion.go b/cmd/helm/completion.go index 051f946fd..f0345d32a 100644 --- a/cmd/helm/completion.go +++ b/cmd/helm/completion.go @@ -205,7 +205,6 @@ __helm_convert_bash_to_zsh() { -e "s/${LWORD}compopt${RWORD}/__helm_compopt/g" \ -e "s/${LWORD}declare${RWORD}/builtin declare/g" \ -e "s/\\\$(type${RWORD}/\$(__helm_type/g" \ - -e 's/aliashash\["\(.\{1,\}\)"\]/aliashash[\1]/g' \ -e 's/FUNCNAME/funcstack/g' \ <<'BASH_COMPLETION_EOF' ` From 48f0e3101d49a3de1466ff75fc786ce012f369cc Mon Sep 17 00:00:00 2001 From: Marc Khouzam Date: Wed, 5 Jun 2019 22:09:15 -0400 Subject: [PATCH 3/3] Allow for completion of aliases Turns out that removing the quotes from the associate array 'aliashash' is still required, but because it is needed for completion of alias commands. For example helm dep does not complete as expected (as if it was 'helm dependency') if the quotes are not removed. This is because although bash ignores quotes when using associative arrays, zsh does not. So when looking for an alias aliashash[dep] will not match the entry aliashash["dep"] in zsh but will for bash. Therefore, removing the quotes fixes things. Signed-off-by: Marc Khouzam --- cmd/helm/completion.go | 1 + 1 file changed, 1 insertion(+) diff --git a/cmd/helm/completion.go b/cmd/helm/completion.go index f0345d32a..051f946fd 100644 --- a/cmd/helm/completion.go +++ b/cmd/helm/completion.go @@ -205,6 +205,7 @@ __helm_convert_bash_to_zsh() { -e "s/${LWORD}compopt${RWORD}/__helm_compopt/g" \ -e "s/${LWORD}declare${RWORD}/builtin declare/g" \ -e "s/\\\$(type${RWORD}/\$(__helm_type/g" \ + -e 's/aliashash\["\(.\{1,\}\)"\]/aliashash[\1]/g' \ -e 's/FUNCNAME/funcstack/g' \ <<'BASH_COMPLETION_EOF' `