charm icon indicating copy to clipboard operation
charm copied to clipboard

First tab doesn't show suggestions on Zsh completion

Open mcornella opened this issue 2 years ago • 1 comments

I've installed charm to test the Zsh completion. The instructions say to put the generated output from charm completion zsh to a file _charm in $fpath. The generated output defines all the necessary completion functions, but does not call _charm at the end.

This means that in the first tab completion, only the function definitions are loaded, so you need to press TAB a second time to get completions.

I've seen you use https://github.com/spf13/cobra for the completion generation. Something like this would be needed to fix it, so maybe you just need to update Cobra: https://github.com/spf13/cobra/blob/52e6099aead5c377be3c46f34bf0c2d3e0c128b6/zsh_completions.go#L251-L254

Thanks!

mcornella avatar Mar 29 '22 09:03 mcornella

I forgot to add that this does not happen if completions are loaded using eval, since that automatically adds the function definition. The downside is that you still need to call compdef _charm charm, which by the other method is automatically done by compinit:

eval "$(charm completion zsh)"
compdef _charm charm

mcornella avatar Mar 29 '22 16:03 mcornella

If you install charm from our pre-packaged deb/rpm/brew, you should get [bash|zsh|fish] autocompletion out-of-the-box. Otherwise, you could do charm completion zsh > /usr/local/share/zsh/site-functions/_charm && chmod +x /usr/local/share/zsh/site-functions/_charm

aymanbagabas avatar Aug 09 '22 22:08 aymanbagabas