Gopass: ZSH completion does not work with oh-my-zsh

Created on 10 Oct 2017  路  14Comments  路  Source: gopasspw/gopass

I'm using this ZSH configuration file: https://github.com/frebib/dotfiles/blob/3915bfa6bb514f44a58bae6753707f1a3d9e8166/.zshrc#L58

Removing line 58 (source $ZSH/oh-my-zsh.sh) and inserting the gopass completion source as below works as expected however completion falls back to standard file completion with oh-my-zsh enabled.

diff --git a/.zshrc b/.zshrc
index d7d4cbc..58017f2 100644
--- a/.zshrc
+++ b/.zshrc
@@ -52,16 +52,18 @@ zstyle ':completion:*' matcher-list '' 'm:{[:lower:][:upper:]}={[:upper:][:lower
 zstyle ':completion:*' rehash true
 zstyle :compinstall filename "$HOME/.zshrc"

-autoload -U compinit ; compinit
+autoload -U compinit && compinit
+autoload -U bashcompinit && bashcompinit
+
+source <(gopass completion bash)

 plugins=(command-not-found history-substring-search sudo zsh-autosuggestions zsh-completions)
-source $ZSH/oh-my-zsh.sh
 source $ZSH/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh

 ZSH_AUTOSUGGEST_CLEAR_WIDGETS=("${(@)ZSH_AUTOSUGGEST_CLEAR_WIDGETS:#(up|down)-line-or-history}")
 ZSH_AUTOSUGGEST_CLEAR_WIDGETS+=(history-substring-search-up history-substring-search-down)
documentation help-wanted

Most helpful comment

I thought I had tested this thoroughly but obviously not well enough. Using this specific arrangement seems to work. oh-my-zsh seems to screw with other plugins quite a lot it seems.

If I was to guess, I'd say it was something to do with load-order of completion handlers, of which oh-my-zsh overrides all or most of them.

diff --git a/.zshrc b/.zshrc
index d7d4cbc..8ac42bd 100644
--- a/.zshrc
+++ b/.zshrc
@@ -52,16 +52,17 @@ zstyle ':completion:*' matcher-list '' 'm:{[:lower:][:upper:]}={[:upper:][:lower
 zstyle ':completion:*' rehash true
 zstyle :compinstall filename "$HOME/.zshrc"

-autoload -U compinit ; compinit
+autoload -U compinit && compinit
+autoload -U bashcompinit && bashcompinit

 plugins=(command-not-found history-substring-search sudo zsh-autosuggestions zsh-completions)
 source $ZSH/oh-my-zsh.sh
 source $ZSH/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
+source <(gopass completion bash)

 ZSH_AUTOSUGGEST_CLEAR_WIDGETS=("${(@)ZSH_AUTOSUGGEST_CLEAR_WIDGETS:#(up|down)-line-or-history}")
 ZSH_AUTOSUGGEST_CLEAR_WIDGETS+=(history-substring-search-up history-substring-search-down)

Can I request this is added to the documentation somewhere to prevent this issue re-occurring with someone else in the future?

All 14 comments

I thought I had tested this thoroughly but obviously not well enough. Using this specific arrangement seems to work. oh-my-zsh seems to screw with other plugins quite a lot it seems.

If I was to guess, I'd say it was something to do with load-order of completion handlers, of which oh-my-zsh overrides all or most of them.

diff --git a/.zshrc b/.zshrc
index d7d4cbc..8ac42bd 100644
--- a/.zshrc
+++ b/.zshrc
@@ -52,16 +52,17 @@ zstyle ':completion:*' matcher-list '' 'm:{[:lower:][:upper:]}={[:upper:][:lower
 zstyle ':completion:*' rehash true
 zstyle :compinstall filename "$HOME/.zshrc"

-autoload -U compinit ; compinit
+autoload -U compinit && compinit
+autoload -U bashcompinit && bashcompinit

 plugins=(command-not-found history-substring-search sudo zsh-autosuggestions zsh-completions)
 source $ZSH/oh-my-zsh.sh
 source $ZSH/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
+source <(gopass completion bash)

 ZSH_AUTOSUGGEST_CLEAR_WIDGETS=("${(@)ZSH_AUTOSUGGEST_CLEAR_WIDGETS:#(up|down)-line-or-history}")
 ZSH_AUTOSUGGEST_CLEAR_WIDGETS+=(history-substring-search-up history-substring-search-down)

Can I request this is added to the documentation somewhere to prevent this issue re-occurring with someone else in the future?

Yes, definitely. We can add this to the docs.

Since I'm not a ZSH user myself: @frebib How would you phrase this?
Either respond here or open an PR.

Thanks!

Simply, "source <(gopass completion bash) must be run after source wherever/oh-my-zsh.zsh to ensure the completion is loaded correctly."

Something like that but probably from the mouth of someone who can phrase things better than I 馃構

@dominikschulz @codegoalie sorry to ping you directly but for few weeks now I have

_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:313: can only be called from completion function
_arguments:comparguments:313: can only be called from completion function
_values:compvalues:10: can only be called from completion function

when I start my zsh session.

I do have the source <(gopass completion bash) after the source $ZSH/oh-my-zsh.sh. GoPass is in version 1.60.10 (on Ubuntu), zsh is in version 5.2.

As soon as I comment the source instruction for gopass, I don't have this problem. In either configuration, the completion for gopass is not working.

@alecharp I'm sorry, but I really can't help with zsh :disappointed:

no problem, I can survive without autocompletion. The day it becomes more problematic, I'll take a night to dig into the code. Thank you for gopass anyway!

I've the same issue on macOS High Sierra after updating gopass to version 1.6.11:

_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:10: can only be called from completion function

I've the source <(gopass completion zsh) as the last instruction in the .zshrc file.

I've added oh-my-zsh plugin, please someone test and +1 PR, so it gets to upstream https://github.com/robbyrussell/oh-my-zsh/pull/6856

@aanpilov thanks!!!

@aanpilov @alecharp I checked and https://github.com/robbyrussell/oh-my-zsh/pull/6856 is not merged to master. Is this bug still open?
I made an arch installation and the zsh configuration wizard that came with Manjaro generated this for me:

The following lines were added by compinstall

zstyle :compinstall filename '/home/zeta/.zshrc'

autoload -Uz compinit
compinit

End of lines added by compinstall

So compinstall appears to be heavily supported in Manjaro/Arch (zsh is even the default shell)

I wish to install oh-my-zsh, however I'm afraid I might loose completions. Suggestions?

hi guys, any news?
on my mac with the latest oh-my-zsh version, gopass autocomplete make some complaints :(

_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

Error: password-store is not initialized. Try 'gopass init'
_values:compvalues:11: can only be called from completion function

I don't know if it's right or respects best practices, but I found a way to have something working...

Add these lines to your .zshrc

gopass completion zsh > $HOME/.gopass
chmod +x $HOME/.gopass
ln -s $HOME/.gopass /usr/local/share/zsh/site-functions/_gopass
autoload -U compinit && compinit

$HOME/.gopass can be replaced as you wish.

It's not working as all others, but it's better than nothing for now!

@bygui86 This did the trick w/o your workaround for me:

eval `gopass completion zsh`

@rngtng thanks for sharing! This is for sure a suitable alternative, but it depends on your needs.
I tried that solution before the one I proposed but I experience a side effect: every time I open a new terminal, that command is evaluated again causing a slow down in the opening.
Both solutions are solving the problem ;)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

fortrieb picture fortrieb  路  6Comments

aperum picture aperum  路  4Comments

sevenmaxis picture sevenmaxis  路  4Comments

worldofpeace picture worldofpeace  路  4Comments

nilskuhn picture nilskuhn  路  6Comments