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
- Merge pull request #12420 from Keyhoh/issue/11348 fix issue #11348 zsh completion broken — committed to kubernetes/minikube by spowelljr 3 years ago
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.,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:After that I added the patched script to
~/.zshrcviasource $HOME/minikube_autocomplete.sh.Either re-login the zsh, or
source ~/.zshrcto 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
minikubein plugin in~/.zsh.rcthen remove double quotes for
aliashashcommands in completion cached file:Obviously this will work until the cached version at
~/.oh-my-zsh/cache/minikube_completiongets overwritten…try this,it works in mac m1。
sed -i "" 's/aliashash\["\([a-z]*\)"\]/aliashash[\1]/g' ~/.minikube-completionsource ~/.minikube-completionRunning into the same/similar issue here:
Trying to tab complete gives me the following:
I think I found why the completion is not working.
In the zsh completion script,
flaghashis an array wherealiashashhas to be an associative array. The way I fixed this in local is to add this line in my.zshrcfile :Note to maintainers:
In the completion script, it seems the
declare -A aliashashhas a scope limited to the function__start_minikube, so thealiashashvariable is not declared in__minikube_root_command.The reason why it works fine with
flaghashis 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_flagfunction:If I run
declare -A flaghashthensource .minikube/minikube.completion.zshI have this debug message: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:
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:
In MacOS using homebrew, an autocompletion file is provided to ZSH:
So, I have applied previous workaround in this way:
This has worked for me as well.
Same here.
My environment:
After
source <(minikube completion zsh), error when using zsh’s auto-complete forminikube: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.
This worked for me too, thanks!
A couple hiccups on the way though…
realpathisn’t available by default (or wasn’t on a fresh Intel MBP) but is withbrew install coreutils.For searchability for anyone else seeing this… the error was:
where the
sed -I or -i may not be used with stdinline of the error is a result ofrealpathnot being found and thus thesedcommand effectively being run onstdin.Another issue was that, as others have noted, there is an
oh-my-zshcashed version of the completion script. I recommend just deleting the cashed version.TL;DR - this is what I did: