[ZSH] Plugin aliases break completion for the command run by the plugin

Community Member

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() {

    for ((i = 2; i < CURRENT; i++)); do
        if [[ ${words[i]} == -- ]]; then
            shift $i words
            ((CURRENT -= i))


function __load_op_completion() {
    completion_function="$(op completion zsh)"
    sed -E 's/^( +)_op_plugin_run/\1__my_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 plugins!

1Password Version: Not Provided
Extension Version: Not Provided
OS Version: Not Provided
Browser:_ Not Provided


  • Hey @whitw:

    Thanks for sharing! I'll flag this with the team.


  • Tom Harrison
    Tom Harrison
    Community Member

    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 or aws 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.

  • kulack
    Community 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.

  • msgongora
    Community Member

    I had gh cli completion broken for quite some time now and just today I realized that I have configured op. Thank you @whitw, I'm looking forward to seeing the solution from 1pass team.

  • Tom Harrison
    Tom Harrison
    Community Member

    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)

This discussion has been closed.