minikube: Minikube image zsh completion broken

The minikube image tab completion on ZSH doesn’t work:

$ minikube image <tab here>_minikube_image:10: bad math expression: operand expected at `"ls"'tion-name:

zsh: do you wish to see all 195 possibilities (98 lines)?

For some reason, part of the previously added image name is part of the error message (application-name)

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 12
  • Comments: 24 (1 by maintainers)

Commits related to this issue

Most upvoted comments

I have the same issue.

$ minikube <single_tab> _minikube_root_command:36: bad math expression: operand expected at `"resume"'

And my environment:

$ zsh --version
zsh 5.8 (x86_64-apple-darwin19.6.0)
$ minikube version
minikube version: v1.21.0
commit: 76d74191d82c47883dc7e1319ef7cebd3e00ee11

I tried to apply the same line from the commit [de232c] but it didn’t work for me. Any other ideas?

Not sure how you did it. Here are my steps in detail:

In stead of adding a line of source <(minikube completion zsh) into my ~/.zshrc, I exported the completion script to a local file, e.g.,

$ minikube completion zsh > ~/minikube_autocomplete.sh

In the generated minikube_autocomplete.sh, I was able to find the function __minikube_convert_bash_to_zsh() at around line 132. Near the end of that function, I added the patch line:

        -e 's/aliashash\["\(\w\+\)"\]/aliashash[\1]/g' \

After that I added the patched script to ~/.zshrc via source $HOME/minikube_autocomplete.sh.

Either re-login the zsh, or source ~/.zshrc to apply the changes, I got minikube auto-complete works.

Just putting this here in case it helps someone who’s also using oh-my-zsh

In my case the autocompletion works by doing:

add minikube in plugin in ~/.zsh.rc

plugins=(
  minikube
)

then remove double quotes for aliashash commands in completion cached file:

sed -i "" 's/aliashash\["\([a-z]*\)"\]/aliashash[\1]/g' ~/.oh-my-zsh/cache/minikube_completion

Obviously this will work until the cached version at ~/.oh-my-zsh/cache/minikube_completion gets overwritten…

try this,it works in mac m1。

  1. sed -i "" 's/aliashash\["\([a-z]*\)"\]/aliashash[\1]/g' ~/.minikube-completion
  2. source ~/.minikube-completion

Running into the same/similar issue here:

minikube version: v1.21.0
commit: 76d74191d82c47883dc7e1319ef7cebd3e00ee11

Distributor ID: Debian
Description:    Debian GNU/Linux 11 (bullseye)
Release:        11
Codename:       bullseye

Trying to tab complete gives me the following:

$ minikube _minikube_root_command:36: bad math expression: operand expected at `"resume"'

I think I found why the completion is not working.

In the zsh completion script, flaghash is an array where aliashash has to be an associative array. The way I fixed this in local is to add this line in my .zshrc file :

declare -A aliashash 2>/dev/null # the only way I found to make the completion work on my laptop
source <(minikube completion zsh)

Note to maintainers:

In the completion script, it seems the declare -A aliashash has a scope limited to the function __start_minikube, so the aliashash variable is not declared in __minikube_root_command.

The reason why it works fine with flaghash is because it’s a simple array and not an associative array as mentioned in debug logs when adding __minikube_debug "${FUNCNAME[0]}: flaghash has type ${(t)flaghash}" to __minikube_handle_flag function:

__minikube_handle_flag: flaghash has type array

If I run declare -A flaghash then source .minikube/minikube.completion.zsh I have this debug message:

__minikube_handle_flag: flaghash has type association

I don’t really know how to fix this in the repo. Moreover I see this Opened PR !11329 dealing with zsh completion simplification which can be relative to this issue ?

For information:

$ minikube version
minikube version: v1.22.0
commit: a03fbcf166e6f74ef224d4a63be4277d017bb62e

$ zsh --version
zsh 5.8 (x86_64-apple-darwin20.0)

I tried the above method, it did not work, but this PR #5406 for my mac-os worked.

For people searching for a oneliner fix:

source <(minikube completion zsh | sed --expression='s/aliashash\["\([a-z]*\)"\]/aliashash[\1]/g')

In MacOS using homebrew, an autocompletion file is provided to ZSH:

╙──→ brew install minikube
==> Downloading https://ghcr.io/v2/homebrew/core/minikube/manifests/1.23.2
Already downloaded: /Users/gon/Library/Caches/Homebrew/downloads/e39b99d0d3817291d3a48689b13fde6a5d52e2e503d47bf328156f61efca8bba--minikube-1.23.2.bottle_manifest.json
==> Downloading https://ghcr.io/v2/homebrew/core/minikube/blobs/sha256:0f123e76f
Already downloaded: /Users/gon/Library/Caches/Homebrew/downloads/5ea3e54e66517ad09bf0fef454eacf0a853a1b13aee8a390dc3790f0d57c4966--minikube--1.23.2.big_sur.bottle.tar.gz
==> Pouring minikube--1.23.2.big_sur.bottle.tar.gz
==> Caveats
zsh completions have been installed to:
  /usr/local/share/zsh/site-functions
==> Summary
🍺  /usr/local/Cellar/minikube/1.23.2: 9 files, 68.7MB

So, I have applied previous workaround in this way:

sed -i "" 's/aliashash\["\([a-z]*\)"\]/aliashash[\1]/g' $(realpath /usr/local/share/zsh/site-functions/_minikube)

try this,it works in mac m1。

  1. sed -i "" 's/aliashash\["\([a-z]*\)"\]/aliashash[\1]/g' ~/.minikube-completion
  2. source ~/.minikube-completion

This has worked for me as well.

Same here.

My environment:

# zsh --version
zsh 5.8 (x86_64-ubuntu-linux-gnu)
# minikube version
minikube version: v1.21.0
commit: 76d74191d82c47883dc7e1319ef7cebd3e00ee11

After source <(minikube completion zsh), error when using zsh’s auto-complete for minikube:

_minikube_root_command:36: bad math expression: operand expected at `"resume"'

I believe this is the same with Helm issue #5046 that has been fixed in two years ago.

In Helm, the issue was fixed by the commit de232c. I have tested the same patch to minikube and it works.

In MacOS using homebrew, an autocompletion file is provided to ZSH:

╙──→ brew install minikube
==> Downloading https://ghcr.io/v2/homebrew/core/minikube/manifests/1.23.2
Already downloaded: /Users/gon/Library/Caches/Homebrew/downloads/e39b99d0d3817291d3a48689b13fde6a5d52e2e503d47bf328156f61efca8bba--minikube-1.23.2.bottle_manifest.json
==> Downloading https://ghcr.io/v2/homebrew/core/minikube/blobs/sha256:0f123e76f
Already downloaded: /Users/gon/Library/Caches/Homebrew/downloads/5ea3e54e66517ad09bf0fef454eacf0a853a1b13aee8a390dc3790f0d57c4966--minikube--1.23.2.big_sur.bottle.tar.gz
==> Pouring minikube--1.23.2.big_sur.bottle.tar.gz
==> Caveats
zsh completions have been installed to:
  /usr/local/share/zsh/site-functions
==> Summary
🍺  /usr/local/Cellar/minikube/1.23.2: 9 files, 68.7MB

So, I have applied previous workaround in this way:

sed -i "" 's/aliashash\["\([a-z]*\)"\]/aliashash[\1]/g' $(realpath /usr/local/share/zsh/site-functions/_minikube)

This worked for me too, thanks!

A couple hiccups on the way though… realpath isn’t available by default (or wasn’t on a fresh Intel MBP) but is with brew install coreutils.

For searchability for anyone else seeing this… the error was:

zsh: command not found: realpath
sed: -I or -i may not be used with stdin

where the sed -I or -i may not be used with stdin line of the error is a result of realpath not being found and thus the sed command effectively being run on stdin.

Another issue was that, as others have noted, there is an oh-my-zsh cashed version of the completion script. I recommend just deleting the cashed version.

TL;DR - this is what I did:

# Remove cached completion script
rm $ZSH_CACHE_DIR/minikube_completion

# Install coreutils to get `realpath` to work
brew install coreutils

# Patch the source of the completions
sed -i "" 's/aliashash\["\([a-z]*\)"\]/aliashash[\1]/g' $(realpath /usr/local/share/zsh/site-functions/_minikube)