Gopass: zsh completions fail to parse

Created on 17 Jun 2020  Â·  5Comments  Â·  Source: gopasspw/gopass

➜  ~ gopass --version
gopass 1.9.2+e2d1549f452a0df1fc52e42e7d0f654334d7144e (e2d1549f452a0df1fc52e42e7d0f654334d7144e) go1.14.2 linux amd64
➜  ~ echo $(gopass completion zsh) > .oh-my-zsh/completions/_gopass
➜  ~ source .oh-my-zsh/completions/_gopass
.oh-my-zsh/completions/_gopass:2: command not found:  _values gpg
.oh-my-zsh/completions/_gopass:4: unmatched '

Maybe it's worth a thought to use https://github.com/spf13/cobra on the longer run, which has decent support for autocompletion generation for all major shells, including PowerShell. (just a random thought)

bug

All 5 comments

Thanks for reporting. Shell completion tends to be annoying and I'm not much into that topic.

cobra would be a pretty invasive change requiring a lot of effort.
Also I like the current CLI lib more than cobra or other CLI libs, so this is rather unlikely to happen.

But fixing zsh completion would be nice. It did work in the past.

Oh, I guess I know what's wrong.

 ./gopass completion zsh | less # OK
echo $(./gopass completion zsh) | less # Broken

The echo messes up the output. Is that in our docs?

Looks like you have a point, still it seems parsing is failing...

➜  ~ gopass completion zsh > .oh-my-zsh/completions/_gopass
➜  ~ source .oh-my-zsh/completions/_gopass
_tags:comptags:36: can only be called from completion function
_tags:comptry:55: can only be called from completion function
_tags:comptags:60: can only be called from completion function
_tags:comptags:67: can only be called from completion function
_arguments:comparguments:325: can only be called from completion function
_arguments:comparguments:325: can only be called from completion function
_values:compvalues:11: can only be called from completion function

Is that in our docs?

Caught me, I didn't check but did it by "muscle" memory.

Btw, thanks for reckoning as a bug.

It doesn't work because you must not source it.

You need to load the completion function without sourcing the file but using the builtin ZSH autoload and compinit functions, as per:
https://github.com/gopasspw/gopass/blob/ce948cd47eca79dd4c1b31300e8016011b208749/docs/setup.md#enable--z-shell-auto-completion

The make install completion command should take care of putting the _gopass file you're generating above in the right folder so that it's in your fpath and then it's just important you have a autoload -U compinit && compinit in your .zshrc otherwise it won't load on boot.

Otherwise if you wish to have the file in your .oh-my-zsh/completions/_gopass path, then make sure that your .zshrc contains:

fpath=(path/to/.oh-my-zsh/completions $fpath)
autoload -U compinit && compinit

This should work upon reboot, but you might have to force rebuild zcompdump if you want it to work directly: rm -f ~/.zcompdump; compinit

Wow, didn't htink echo would mess it up, thanks for the documentation PR!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

prune998 picture prune998  Â·  6Comments

stevesbrain picture stevesbrain  Â·  6Comments

dragetd picture dragetd  Â·  3Comments

Brixy picture Brixy  Â·  7Comments

Zamiell picture Zamiell  Â·  6Comments