Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Command not found for zsh completion #585

Closed
SevereOverfl0w opened this issue Jan 1, 2018 · 25 comments · Fixed by #1525
Closed

Command not found for zsh completion #585

SevereOverfl0w opened this issue Jan 1, 2018 · 25 comments · Fixed by #1525

Comments

@SevereOverfl0w
Copy link

I use zsh -d -f to start zsh without an rc.

❯ zsh -d -f
bianca2% source <(gopass completion zsh)
_gopass:213: command not found: _describe
_gopass:214: command not found: _arguments
_gopass_complete_passwords:1: command not found: _arguments
_gopass_complete_passwords:3: command not found: _values
@SevereOverfl0w
Copy link
Author

Actually, this is the wrong error, I'm getting something different in my host terminal.

bianca2% autoload -Uz compinit
compinit
bianca2% source <(gopass completion zsh)
_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:319: can only be called from completion function
_arguments:comparguments:319: can only be called from completion function
_values:compvalues:11: can only be called from completion function

@dominikschulz
Copy link
Member

Hi, I'm afraid but I'd need help from someone familiar with zsh to resolve this issue.

@SevereOverfl0w
Copy link
Author

This seems to work if I do gopass completion zsh > ~/newdir/_gopass.zsh and then add fpath=(~/newdir $fpath) to my .zshrc.

Reading some issues, I suspect the intention was that the completion would be a build artifact that ended up at /usr/lib/gopass/_gopass.zsh or something.

https://github.com/zsh-users/zsh-completions/blob/master/zsh-completions-howto.org might be worth reading, but I'm not certain.

@SevereOverfl0w
Copy link
Author

Naturally, I think I found the dynamic solution straight after I posted that. compdef _gopass gopass hooks it up. Resulting lines in .zshrc:

source <(gopass completion zsh | head -n -1 | tail -n +2)
compdef _gopass gopass

The head/tail drop the "broken" lines. I think the compdef should be added to the output of gopass completion zsh. If I use source <((gopass completion zsh | head -n -1 | tail -n +2); echo 'compdef _gopass gopass') to append the compdef to the output, this also works.

@dominikschulz
Copy link
Member

Thanks for investigating! I'm still not exactly sure what the fix should look like. Would be amazing if someone using zsh could create a PR. Otherwise I'll need some time to have a look at the zsh docs and see what I can do, but this may take a few days.

@SevereOverfl0w
Copy link
Author

@dominikschulz I think you need to remove the #compdef gopass from the generated output, and remove the bottom line _gopass.

Then add compdef _gopass gopass to the bottom of the file.

@dominikschulz
Copy link
Member

Not sure if that breaks the changes we tried to do in #565. WDYT @Foxboron ?

@Foxboron
Copy link
Contributor

Foxboron commented Jan 2, 2018

Sourcing gopass completion zsh is the wrong approach to get zsh completions. The file needs to enter a compinit directory, and zsh will handle it. If there is documentation that is needed to resolve the confusion I'll fix it.

Yes, the suggested changes will break the completion.

@Foxboron
Copy link
Contributor

Foxboron commented Jan 2, 2018

I don't know the given distro/OS. But if the completion is not package properly the solution is gopass completion zsh > /usr/share/zsh/site-functions/_gopass.

Then you remove ~/.zcompdump and reload compinit.

@SevereOverfl0w
Copy link
Author

I don't know the given distro/OS. But if the completion is not package properly the solution is gopass completion zsh > /usr/share/zsh/site-functions/_gopass.

The documentation doesn't indicate this, and says to source from the output of that.

@Foxboron
Copy link
Contributor

Foxboron commented Jan 2, 2018

@SevereOverfl0w I'll look over the documentation try explain the situation better. Thanks

@ninrod
Copy link

ninrod commented Jan 4, 2018

I've just hit this installing the rpm in centos. completion is not working. not sure what to do.

this hack worked by @SevereOverfl0w for me:

source <(gopass completion zsh | head -n -1 | tail -n +2)
compdef _gopass gopass

@ninrod
Copy link

ninrod commented Jan 4, 2018

@Foxboron, how do you actually restart compinit? I have a _gopass file in that dir, but not sure how to proceed in relation to compinit.

@Foxboron
Copy link
Contributor

Foxboron commented Jan 4, 2018

rm the .zcompdump file in home then autoload -U compinit && compinit.

If your distribution doesn't include completion create a bug report to them.

@eli-schwartz
Copy link
Contributor

eli-schwartz commented Jan 4, 2018

The whole purpose of @Foxboron's change, is that attempting to source the completion definition is a completely broken way to handle zsh completion and should not be done. zsh has an excellent completion system that works properly, as long as you actually use it.

Given that one of the major touted benefits of zsh is the completion system, any zsh installation that does not even use it is, well, broken.

The properly-written zsh completion for gopass is meant to be installed in the zsh completions directory, as defined by either the OS-level /usr/share/zsh/site-functions/, or the user-specified fpath. If gopass is installed via a package manager to usr/ then this should Just Work™, if it is installed to the user's home directory in ~/bin or wherever, then the completion file should likewise be generated and stored in $fpath.
The result is that zsh can automatically detect the completion, and load it when necessary, similar to how bash completions are stored in a global completions directory and automatically lazy-loaded when the command is tab-completed for the first time.

No user action or configuration in any way shape or form is required, other than making sure that the generic completion system is hooked up. This is, after all, far more convenient than requiring every single user-installed program to inject itself into the user's shell rc files.

Again, this is the recommended and intended way that zsh completions are meant to be done. The fact that people were sourceing anything ever, was a bug that has been fixed.

@ninrod
Copy link

ninrod commented Jan 4, 2018

@Foxboron @eli-schwartz, I just tried the procedure on an updated arch linux now.

/usr/share/zsh/site-functions has the _gopass file properly installed in my system. I did nothing, just pacman -S gopass and the file is already there.

however, after deleting ~/.zcompdump and issuing autoload -U compinit && compinit and restarting my shell, gopass does not have completions. Is this something on my end or in archlinux?

here is the result of print -l $fpath:

/usr/local/share/zsh/site-functions
/usr/share/zsh/site-functions
/usr/share/zsh/functions/Calendar
/usr/share/zsh/functions/Chpwd
/usr/share/zsh/functions/Completion
/usr/share/zsh/functions/Completion/Base
/usr/share/zsh/functions/Completion/Linux
/usr/share/zsh/functions/Completion/Unix
/usr/share/zsh/functions/Completion/X
/usr/share/zsh/functions/Completion/Zsh
/usr/share/zsh/functions/Exceptions
/usr/share/zsh/functions/Math
/usr/share/zsh/functions/MIME
/usr/share/zsh/functions/Misc
/usr/share/zsh/functions/Newuser
/usr/share/zsh/functions/Prompts
/usr/share/zsh/functions/TCP
/usr/share/zsh/functions/VCS_Info
/usr/share/zsh/functions/VCS_Info/Backends
/usr/share/zsh/functions/Zftp
/usr/share/zsh/functions/Zle
/home/ninrod/.dotfiles/deps/zsh/ninrod/docker-compose-zsh-completion/src
/home/ninrod/.dotfiles/deps/zsh/ninrod/docker-zsh-completion/src
/home/ninrod/.dotfiles/deps/zsh/ninrod/pass-zsh-completion/src
/home/ninrod/.dotfiles/deps/zsh/zsh-users/zsh-completions/src

here are my full zsh dotfiles: https://github.com/ninrod/dotfiles/tree/master/zsh

@Foxboron
Copy link
Contributor

Foxboron commented Jan 4, 2018

@ninrod Works for me so unsure, make sure all .zcompdump files are deleted. If it still doesn't work it's better to submit a bug to our tracker then using the upstream tracker.

@ninrod
Copy link

ninrod commented Jan 5, 2018

@Foxboron it worked allright for me. the issue was that I was using gopass 1.6.6. upgrading to 1.6.7 did the trick.

@clovis818
Copy link

This worked for me on mac os.

print -l $fpath | grep '.oh-my-zsh/completions'
mkdir ~/.oh-my-zsh/completions
gopass completion zsh > ~/.oh-my-zsh/completions/_gopass
rm ~/.zcompdump*

@bumi
Copy link

bumi commented Jan 10, 2018

having the same problem after upgrading my system (arch linux) I'd assume some zsh update issue?

@SevereOverfl0w
Copy link
Author

It depends on if the arch linux package has been updated to respect the newly generated files.

@kepi
Copy link
Contributor

kepi commented Feb 3, 2018

In debian package file _gopass (probably generated from gopass completion zsh) should be placed to /usr/local/share/zsh/site-functions.

Current workaround for me:

gopass completion zsh | sudo tee /usr/local/share/zsh/site-functions/_gopass

@AnomalRoil
Copy link
Member

The biggest problem I can see coming with this, is the update process when using go get directly to update Gopass, since then if there are new commands or so, the zsh completion file must be manually updated. But then it must be done with write access to the completion folder...

Maybe the simplest way around it could be to instruct people to add this in their .zshrc:

fpath=( ${GOPATH}/src/github.com/justwatchcom/gopass/completions "${fpath[@]}" )

so it would add the folder completions in the Gopass repo as a way to provide completion and then you could have a Travis after_success callback so that the file gopass/completions/_gopass would be automatically created using gopass completion zsh when Travis succeeds.

However I do not know whether it is considered bad practice or not to tell people to add a folder to their fpath.

@stale
Copy link

stale bot commented Aug 26, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Aug 26, 2018
@katiehockman
Copy link

I'm getting a similar, possibly related issue. If I press any key, then space (for completion), it prints something like this:

_tags:36: command not found: comptags
_tags:55: command not found: comptry
_tags:60: command not found: comptags
_tags:67: command not found: comptags
_tags:36: command not found: comptags
_tags:55: command not found: comptry
_tags:60: command not found: comptags
_tags:67: command not found: comptags
_tags:36: command not found: comptags
_tags:55: command not found: comptry
_tags:60: command not found: comptags
_tags:67: command not found: comptags
_tags:36: command not found: comptags
_tags:55: command not found: comptry
_tags:60: command not found: comptags
_tags:67: command not found: comptags
_tags:36: command not found: comptags
_tags:55: command not found: comptry
_tags:60: command not found: comptags
_tags:67: command not found: comptags
_tags:36: command not found: comptags
_tags:55: command not found: comptry
_tags:60: command not found: comptags
_tags:67: command not found: comptags


dominikschulz pushed a commit that referenced this issue Aug 14, 2020
Fixes #585
Fixes #1424

RELEASE_NOTES=[DOCUMENTATION] Improve documentation of Zsh completion setup

Signed-off-by: Yolan Romailler <yolan@romailler.ch>
kpitt pushed a commit to kpitt/gopass that referenced this issue Jul 21, 2022
Fixes gopasspw#585
Fixes gopasspw#1424

RELEASE_NOTES=[DOCUMENTATION] Improve documentation of Zsh completion setup

Signed-off-by: Yolan Romailler <yolan@romailler.ch>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants