1Password on Mastodon

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

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

    for ((i = 2; i < CURRENT; i++)); do
        if [[ ${words[i]} == -- ]]; 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/\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

Comments

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file