Skip to content

helm completion fails in zsh (prezto) with "bad math expression: operand expected" #5046

Closed

Description

@ezekills

I noticed helm completion in zsh is not working.
One part of the problem is that _helm is not executable per default.
Second when I type helm and hit tab I get:

helm _helm_root_command:12: bad math expression: operand expected at `"del"'

I found that removing the doublequotes in _helm at every aliashash key value fixes it.
(/usr/local/Cellar/kubernetes-helm/2.12.0/share/zsh/site-functions/_helm)

not working:

aliashash["del"]="delete" 

fixed:

aliashash[del]="delete"

I am using prezto and I installed helm with homebrew.

Activity

  1. philoserf commented on Dec 11, 2018

    @philoserf

    I have confirmed the issue does not appear in helm 2.11.0

    This may have been introduced by #4851. It is the only mention of completion in release 2.12.0.

    ref: https://github.com/helm/helm/releases/tag/v2.12.0

  2. added
    bug
    on Dec 12, 2018
  3. Sarke commented on Dec 18, 2018

    @Sarke
    Contributor

    Same with oh-my-zsh, so the issue seems to be the quotes in the hash maps not being allowed by ZSH.

    Here's a diff of the two versions' helm completion zsh.

    --- v2.11.0.zsh
    +++ v2.12.0.zsh
    @@ -1,4 +1,3 @@
    -
     #compdef helm
     
     __helm_bash_source() {
    @@ -240,7 +239,13 @@
         fi
     
         if [[ ${#COMPREPLY[@]} -eq 0 ]]; then
    -        declare -F __custom_func >/dev/null && __custom_func
    +		if declare -F __helm_custom_func >/dev/null; then
    +			# try command name qualified custom func
    +			__helm_custom_func
    +		else
    +			# otherwise fall back to unqualified for compatibility
    +			declare -F ___custom_func >/dev/null && __custom_func
    +		fi
         fi
     
         # available in bash-completion >= 2, not always present on macOS
    @@ -362,6 +367,14 @@
             __helm_handle_command
         elif [[ $c -eq 0 ]]; then
             __helm_handle_command
    +    elif __helm_contains_word "${words[c]}" "${command_aliases[@]}"; then
    +        # aliashash variable is an associative array which is only supported in bash > 3.
    +        if [[ -z "${BASH_VERSION}" || "${BASH_VERSINFO[0]}" -gt 3 ]]; then
    +            words[c]=${aliashash[${words[c]}]}
    +            __helm_handle_command
    +        else
    +            __helm_handle_noun
    +        fi
         else
             __helm_handle_noun
         fi
    @@ -371,6 +384,9 @@
     _helm_completion()
     {
         last_command="helm_completion"
    +
    +    command_aliases=()
    +
         commands=()
     
         flags=()
    @@ -400,6 +416,9 @@
     _helm_create()
     {
         last_command="helm_create"
    +
    +    command_aliases=()
    +
         commands=()
     
         flags=()
    @@ -427,6 +446,9 @@
     _helm_delete()
     {
         last_command="helm_delete"
    +
    +    command_aliases=()
    +
         commands=()
     
         flags=()
    @@ -473,6 +495,9 @@
     _helm_dependency_build()
     {
         last_command="helm_dependency_build"
    +
    +    command_aliases=()
    +
         commands=()
     
         flags=()
    @@ -501,6 +526,9 @@
     _helm_dependency_list()
     {
         last_command="helm_dependency_list"
    +
    +    command_aliases=()
    +
         commands=()
     
         flags=()
    @@ -525,6 +553,9 @@
     _helm_dependency_update()
     {
         last_command="helm_dependency_update"
    +
    +    command_aliases=()
    +
         commands=()
     
         flags=()
    @@ -555,10 +586,21 @@
     _helm_dependency()
     {
         last_command="helm_dependency"
    +
    +    command_aliases=()
    +
         commands=()
         commands+=("build")
         commands+=("list")
    +    if [[ -z "${BASH_VERSION}" || "${BASH_VERSINFO[0]}" -gt 3 ]]; then
    +        command_aliases+=("ls")
    +        aliashash["ls"]="list"
    +    fi
         commands+=("update")
    +    if [[ -z "${BASH_VERSION}" || "${BASH_VERSINFO[0]}" -gt 3 ]]; then
    +        command_aliases+=("up")
    +        aliashash["up"]="update"
    +    fi
     
         flags=()
         two_word_flags=()
    @@ -582,6 +624,9 @@
     _helm_fetch()
     {
         last_command="helm_fetch"
    +
    +    command_aliases=()
    +
         commands=()
     
         flags=()
    @@ -635,6 +680,9 @@
     _helm_get_hooks()
     {
         last_command="helm_get_hooks"
    +
    +    command_aliases=()
    +
         commands=()
     
         flags=()
    @@ -673,6 +721,9 @@
     _helm_get_manifest()
     {
         last_command="helm_get_manifest"
    +
    +    command_aliases=()
    +
         commands=()
     
         flags=()
    @@ -711,6 +762,9 @@
     _helm_get_notes()
     {
         last_command="helm_get_notes"
    +
    +    command_aliases=()
    +
         commands=()
     
         flags=()
    @@ -749,6 +803,9 @@
     _helm_get_values()
     {
         last_command="helm_get_values"
    +
    +    command_aliases=()
    +
         commands=()
     
         flags=()
    @@ -760,6 +817,8 @@
         flags+=("--all")
         flags+=("-a")
         local_nonpersistent_flags+=("--all")
    +    flags+=("--output=")
    +    local_nonpersistent_flags+=("--output=")
         flags+=("--revision=")
         local_nonpersistent_flags+=("--revision=")
         flags+=("--tls")
    @@ -790,6 +849,9 @@
     _helm_get()
     {
         last_command="helm_get"
    +
    +    command_aliases=()
    +
         commands=()
         commands+=("hooks")
         commands+=("manifest")
    @@ -832,6 +894,9 @@
     _helm_history()
     {
         last_command="helm_history"
    +
    +    command_aliases=()
    +
         commands=()
     
         flags=()
    @@ -875,6 +940,9 @@
     _helm_home()
     {
         last_command="helm_home"
    +
    +    command_aliases=()
    +
         commands=()
     
         flags=()
    @@ -899,6 +967,9 @@
     _helm_init()
     {
         last_command="helm_init"
    +
    +    command_aliases=()
    +
         commands=()
     
         flags=()
    @@ -974,6 +1045,9 @@
     _helm_inspect_chart()
     {
         last_command="helm_inspect_chart"
    +
    +    command_aliases=()
    +
         commands=()
     
         flags=()
    @@ -1016,6 +1090,9 @@
     _helm_inspect_readme()
     {
         last_command="helm_inspect_readme"
    +
    +    command_aliases=()
    +
         commands=()
     
         flags=()
    @@ -1054,6 +1131,9 @@
     _helm_inspect_values()
     {
         last_command="helm_inspect_values"
    +
    +    command_aliases=()
    +
         commands=()
     
         flags=()
    @@ -1096,6 +1176,9 @@
     _helm_inspect()
     {
         last_command="helm_inspect"
    +
    +    command_aliases=()
    +
         commands=()
         commands+=("chart")
         commands+=("readme")
    @@ -1141,6 +1224,9 @@
     _helm_install()
     {
         last_command="helm_install"
    +
    +    command_aliases=()
    +
         commands=()
     
         flags=()
    @@ -1229,6 +1315,9 @@
     _helm_lint()
     {
         last_command="helm_lint"
    +
    +    command_aliases=()
    +
         commands=()
     
         flags=()
    @@ -1266,6 +1355,9 @@
     _helm_list()
     {
         last_command="helm_list"
    +
    +    command_aliases=()
    +
         commands=()
     
         flags=()
    @@ -1339,6 +1431,9 @@
     _helm_package()
     {
         last_command="helm_package"
    +
    +    command_aliases=()
    +
         commands=()
     
         flags=()
    @@ -1381,6 +1476,9 @@
     _helm_plugin_install()
     {
         last_command="helm_plugin_install"
    +
    +    command_aliases=()
    +
         commands=()
     
         flags=()
    @@ -1407,6 +1505,9 @@
     _helm_plugin_list()
     {
         last_command="helm_plugin_list"
    +
    +    command_aliases=()
    +
         commands=()
     
         flags=()
    @@ -1431,6 +1532,9 @@
     _helm_plugin_remove()
     {
         last_command="helm_plugin_remove"
    +
    +    command_aliases=()
    +
         commands=()
     
         flags=()
    @@ -1455,6 +1559,9 @@
     _helm_plugin_update()
     {
         last_command="helm_plugin_update"
    +
    +    command_aliases=()
    +
         commands=()
     
         flags=()
    @@ -1479,6 +1586,9 @@
     _helm_plugin()
     {
         last_command="helm_plugin"
    +
    +    command_aliases=()
    +
         commands=()
         commands+=("install")
         commands+=("list")
    @@ -1507,6 +1617,9 @@
     _helm_repo_add()
     {
         last_command="helm_repo_add"
    +
    +    command_aliases=()
    +
         commands=()
     
         flags=()
    @@ -1543,6 +1656,9 @@
     _helm_repo_index()
     {
         last_command="helm_repo_index"
    +
    +    command_aliases=()
    +
         commands=()
     
         flags=()
    @@ -1571,6 +1687,9 @@
     _helm_repo_list()
     {
         last_command="helm_repo_list"
    +
    +    command_aliases=()
    +
         commands=()
     
         flags=()
    @@ -1595,6 +1714,9 @@
     _helm_repo_remove()
     {
         last_command="helm_repo_remove"
    +
    +    command_aliases=()
    +
         commands=()
     
         flags=()
    @@ -1619,14 +1741,19 @@
     _helm_repo_update()
     {
         last_command="helm_repo_update"
    -    commands=()
    -
    -    flags=()
    -    two_word_flags=()
    -    local_nonpersistent_flags=()
    -    flags_with_completion=()
    -    flags_completion=()
    -
    +
    +    command_aliases=()
    +
    +    commands=()
    +
    +    flags=()
    +    two_word_flags=()
    +    local_nonpersistent_flags=()
    +    flags_with_completion=()
    +    flags_completion=()
    +
    +    flags+=("--strict")
    +    local_nonpersistent_flags+=("--strict")
         flags+=("--debug")
         flags+=("--home=")
         flags+=("--host=")
    @@ -1643,12 +1770,23 @@
     _helm_repo()
     {
         last_command="helm_repo"
    +
    +    command_aliases=()
    +
         commands=()
         commands+=("add")
         commands+=("index")
         commands+=("list")
         commands+=("remove")
    +    if [[ -z "${BASH_VERSION}" || "${BASH_VERSINFO[0]}" -gt 3 ]]; then
    +        command_aliases+=("rm")
    +        aliashash["rm"]="remove"
    +    fi
         commands+=("update")
    +    if [[ -z "${BASH_VERSION}" || "${BASH_VERSINFO[0]}" -gt 3 ]]; then
    +        command_aliases+=("up")
    +        aliashash["up"]="update"
    +    fi
     
         flags=()
         two_word_flags=()
    @@ -1672,6 +1810,9 @@
     _helm_reset()
     {
         last_command="helm_reset"
    +
    +    command_aliases=()
    +
         commands=()
     
         flags=()
    @@ -1713,6 +1854,9 @@
     _helm_rollback()
     {
         last_command="helm_rollback"
    +
    +    command_aliases=()
    +
         commands=()
     
         flags=()
    @@ -1763,6 +1907,9 @@
     _helm_search()
     {
         last_command="helm_search"
    +
    +    command_aliases=()
    +
         commands=()
     
         flags=()
    @@ -1798,6 +1945,9 @@
     _helm_serve()
     {
         last_command="helm_serve"
    +
    +    command_aliases=()
    +
         commands=()
     
         flags=()
    @@ -1828,6 +1978,9 @@
     _helm_status()
     {
         last_command="helm_status"
    +
    +    command_aliases=()
    +
         commands=()
     
         flags=()
    @@ -1869,6 +2022,9 @@
     _helm_template()
     {
         last_command="helm_template"
    +
    +    command_aliases=()
    +
         commands=()
     
         flags=()
    @@ -1920,6 +2076,9 @@
     _helm_test()
     {
         last_command="helm_test"
    +
    +    command_aliases=()
    +
         commands=()
     
         flags=()
    @@ -1960,6 +2119,9 @@
     _helm_upgrade()
     {
         last_command="helm_upgrade"
    +
    +    command_aliases=()
    +
         commands=()
     
         flags=()
    @@ -2048,6 +2210,9 @@
     _helm_verify()
     {
         last_command="helm_verify"
    +
    +    command_aliases=()
    +
         commands=()
     
         flags=()
    @@ -2074,6 +2239,9 @@
     _helm_version()
     {
         last_command="helm_version"
    +
    +    command_aliases=()
    +
         commands=()
     
         flags=()
    @@ -2120,20 +2288,41 @@
     _helm_root_command()
     {
         last_command="helm"
    +
    +    command_aliases=()
    +
         commands=()
         commands+=("completion")
         commands+=("create")
         commands+=("delete")
    +    if [[ -z "${BASH_VERSION}" || "${BASH_VERSINFO[0]}" -gt 3 ]]; then
    +        command_aliases+=("del")
    +        aliashash["del"]="delete"
    +    fi
         commands+=("dependency")
    +    if [[ -z "${BASH_VERSION}" || "${BASH_VERSINFO[0]}" -gt 3 ]]; then
    +        command_aliases+=("dep")
    +        aliashash["dep"]="dependency"
    +        command_aliases+=("dependencies")
    +        aliashash["dependencies"]="dependency"
    +    fi
         commands+=("fetch")
         commands+=("get")
         commands+=("history")
    +    if [[ -z "${BASH_VERSION}" || "${BASH_VERSINFO[0]}" -gt 3 ]]; then
    +        command_aliases+=("hist")
    +        aliashash["hist"]="history"
    +    fi
         commands+=("home")
         commands+=("init")
         commands+=("inspect")
         commands+=("install")
         commands+=("lint")
         commands+=("list")
    +    if [[ -z "${BASH_VERSION}" || "${BASH_VERSINFO[0]}" -gt 3 ]]; then
    +        command_aliases+=("ls")
    +        aliashash["ls"]="list"
    +    fi
         commands+=("package")
         commands+=("plugin")
         commands+=("repo")
    @@ -2171,6 +2360,7 @@
     {
         local cur prev words cword
         declare -A flaghash 2>/dev/null || :
    +    declare -A aliashash 2>/dev/null || :
         if declare -F _init_completion >/dev/null 2>&1; then
             _init_completion -s || return
         else
  4. added a commit that references this issue on Dec 18, 2018
    de232c4
  5. scandeezy commented on Jan 24, 2019

    @scandeezy

    Hey there, I was wondering when this change might make it in? Happy New Year.

  6. pavdmyt commented on Jan 29, 2019

    @pavdmyt

    Having the same issue with helm v2.12.2:

    $ source <(helm completion zsh)
    $
    # Typing 'helm' and hitting "Tab"
    $ helm _helm_root_command:12: bad math expression: operand expected at `"del"'
    $
    $ helm version -c
    Client: &version.Version{SemVer:"v2.12.2", GitCommit:"7d2b0c73d734f6586ed222a567c5d103fed435be", GitTreeState:"clean"}
    

    Running ZSH under OSX:

    $ zsh --version
    zsh 5.3 (x86_64-apple-darwin17.0)
    
  7. added a commit that references this issue on Jan 29, 2019
    4c1edcf
  8. NZhuravlev commented on Feb 8, 2019

    @NZhuravlev

    v2.12.3 - still have the same issue.

    helm _helm_root_command:12: bad math expression: operand expected at `"del"'
    macOS 10.14.2 (18C54)
    zsh 5.3 (x86_64-apple-darwin18.0)
    Client: &version.Version{SemVer:"v2.12.3", GitCommit:"eecf22f77df5f65c823aacd2dbd30ae6c65f186e", GitTreeState:"clean"}

  9. eddiezane commented on Feb 8, 2019

    @eddiezane

    @NZhuravlev this fix made it in after v2.12.3 shipped. You'll unfortunately have to wait for the next release or build from source.

  10. bacongobbler commented on Feb 8, 2019

    @bacongobbler
    Member
  11. arogarth commented on Feb 14, 2019

    @arogarth

    quick local fix in .zshrc...

    source <(helm completion zsh | sed -E 's/\["(.+)"\]/\[\1\]/g')
    

    hope it will fix in the next release. Current rc does not fix it

  12. bacongobbler commented on Feb 14, 2019

    @bacongobbler
    Member

    Do you mean to say that the fix proposed in #5072 did not fix the issue? You were testing 2.13.0-rc.1, right?

  13. koenpunt commented on Feb 16, 2019

    @koenpunt

    When installed through Homebrew you can use the following to fix autocompletion:

    sed -i orig -E 's/\["(.+)"\]/\[\1\]/g' /usr/local/Cellar/kubernetes-helm/2.12.3/share/zsh/site-functions/_helm
    

    Don't forget to reload your shell; this can be done by opening a new window, or by running exec $SHELL

  14. pavdmyt commented on Feb 18, 2019

    @pavdmyt

    @bacongobbler having the same issue with 2.13.0-rc.1:

    $ source <(helm completion zsh)
    $
    # Typing 'helm' and hitting "Tab"
    $ helm _helm_root_command:12: bad math expression: operand expected at `"del"'
    $
    $ helm version -c
    Client: &version.Version{SemVer:"v2.13.0-rc.1", GitCommit:"e0e5197f8d9b3fa13626a273ad8b3f49a8aab67e", GitTreeState:"clean"}
    $
    $ zsh --version
    zsh 5.3 (x86_64-apple-darwin18.0)
  15. 6 remaining items

  16. bacongobbler commented on Mar 5, 2019

    @bacongobbler
    Member

    fixed via #5406, hopefully for real this time! 😄

  17. marckhouzam commented on Mar 6, 2019

    @marckhouzam
    Member

    Out of curiosity, how come the maintainers don't use bash completion? I guess you don't actually use helm manually that much?

  18. bacongobbler commented on Mar 6, 2019

    @bacongobbler
    Member

    I simply find bash autocompletion gets in my way so I don't use it. Nothing much else to it. 🤷‍♂️

    Generally speaking, I'm testing and/or using several different development builds of Helm any given day, so I'd have to keep switching between different autocompletion scripts for varying versions of Helm. I'm typically context switching between Helm 2 and Helm 3 once every few hours. Again, just getting in the way of my day-to-day workflow.

  19. added 6 commits that reference this issue on Mar 7, 2019
    748583d
    56e4c35
    7137293
    8e45b05
    9a9e789
    a40e3c5
  20. added a commit that references this issue on Mar 21, 2019
    5524720
  21. added a commit that references this issue on Mar 21, 2019
    a6ccbda
  22. added a commit that references this issue on May 20, 2019
  23. marckhouzam commented on May 20, 2019

    @marckhouzam
    Member

    Turns out that the real root of this bug was that the 'aliashash' associative array was not being declared properly. PR #5680 fixes it and removes the previous fix to the current issue.

  24. added a commit that references this issue on Jan 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions