Signing back into the Community for the first time? You'll need to reset your password to access your account. Find out more.
Forum Discussion
whitw
2 years agoNew Contributor
[ZSH] Plugin aliases break completion for the command run by the plugin
I have ZSH set up to introspect aliases and run plugin functions based on what the alias is calling.
This means that an alias set up for gh
: alias gh='op plugin run -- gh'
will actually trigger the _op_plugin_run
completion function, not that for gh
itself.
I have worked around this with this in my .zshrc
(I don't really want to edit the completion file as I'll definitely forget to keep it updated):
```
function __my_op_plugin_run() {
_op_plugin_run
for ((i = 2; i < CURRENT; i++)); do
if [[ ${words} == -- ]]; then
shift $i words
((CURRENT -= i))
_normal
return
fi
done
}
function load_op_completion() {
completion_function="$(op completion zsh)"
sed -E 's/^( +)_op_plugin_run/\1my_op_plugin_run/' <<<"${completion_function}"
}
eval "$(__load_op_completion)"
compdef _op op
```
In lay-terms, this:
1. Checks if the previous word is --
2. Takes --
and everything prior to it out of the scope of the completion
3. completes as normal from the first argument after --
.
This is the pattern used by aws-vault
This is also possible in bash and fish
It would be really helpful if the CLI team could update the completion function generated by op completion $SHELL
to trigger this reset, so we don't lose shell functionality by using op plugin
s!
1Password Version: Not Provided
Extension Version: Not Provided
OS Version: Not Provided
Browser:_ Not Provided
- Tom_HarrisonOccasional Contributor
Hi Jack_P_1P -- any updates on this? I recently reinstalled the 1P cli to get the terraform beta and realized the workaround above doesn't seem to work anymore (I have plugins for aws, gh, and now terraform installed with CLI --version == 2.19.0-beta.01)
- Former Member
I hit this problem today. Thank you whitw for the workaround!
Been a personal 1P user for a long time because is phenomenal!
We just rolled out 1Password in our enterprise, would like this fixed as I demo to others in our community. - Tom_HarrisonOccasional Contributor
Hey Jack_P_1P -- I just realized I had the same issue as whitw with the 1p plugin aliases breaking zsh completion (and gh). His solution has some serious shell-foo, and I have big respect. But I think this is a bug, and it's pretty simple.
An alias for a command that has completions breaks the completions.
So the op alias for
gh
oraws
breaks their completions. This is seriously painful for aws :-)Still, I tried whitw's hack above and it worked for me. I think y'all at 1P are going to need to get this worked out as more plugins are developed. Looks like the solution above handles the general case.
- Jack_P_1P
1Password Team