From 4fec4b67661b7cc48b8ed1f1c5827a255c74db75 Mon Sep 17 00:00:00 2001 From: Marc Khouzam Date: Sat, 9 Mar 2019 22:28:36 -0500 Subject: [PATCH 1/2] Fix debug printouts for zsh completion Cobra provides some out-of-the-box debugging for bash completion. To use it, one must set the variable BASH_COMP_DEBUG_FILE to some file where the debug output will be written. Many of the debug printouts indicate the current method name; they do so by using bash's ${FUNCNAME[0]} variable. This variable is different in zsh. To obtain the current method name in zsh we must use ${funcstack[1]}. This commit adds the proper sed modification to convert from bash to zsh. 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 3c0318941..962f06e3b 100644 --- a/cmd/helm/completion.go +++ b/cmd/helm/completion.go @@ -213,6 +213,7 @@ __helm_convert_bash_to_zsh() { -e "s/${LWORD}declare${RWORD}/__helm_declare/g" \ -e "s/\\\$(type${RWORD}/\$(__helm_type/g" \ -e 's/aliashash\["\(.\{1,\}\)"\]/aliashash[\1]/g' \ + -e 's/FUNCNAME\[0\]/funcstack[1]/g' \ <<'BASH_COMPLETION_EOF' ` out.Write([]byte(zshInitialization)) From 9cc6902875135a26c5edb2fecb08f39d9eeb2dd6 Mon Sep 17 00:00:00 2001 From: Marc Khouzam Date: Sun, 10 Mar 2019 00:22:08 -0500 Subject: [PATCH 2/2] Must use index 0 for funcstack Normally zsh arrays start at index 1 but when emulating other shells this may change. During completion, we run the command emulate -L sh which affects the indexing of zsh arrays to make it start at 0. Consequently, when replacing FUNCNAME by funcstack, we should not change the index. Signed-off-by: Marc Khouzam --- cmd/helm/completion.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/helm/completion.go b/cmd/helm/completion.go index 962f06e3b..039dcbe5f 100644 --- a/cmd/helm/completion.go +++ b/cmd/helm/completion.go @@ -213,7 +213,7 @@ __helm_convert_bash_to_zsh() { -e "s/${LWORD}declare${RWORD}/__helm_declare/g" \ -e "s/\\\$(type${RWORD}/\$(__helm_type/g" \ -e 's/aliashash\["\(.\{1,\}\)"\]/aliashash[\1]/g' \ - -e 's/FUNCNAME\[0\]/funcstack[1]/g' \ + -e 's/FUNCNAME/funcstack/g' \ <<'BASH_COMPLETION_EOF' ` out.Write([]byte(zshInitialization))