[PATCH] add custom bash completion for extensions

Jason A. Donenfeld Jason at zx2c4.com
Wed Jul 18 02:42:27 CEST 2018


Hey Lars,

This is a super idea.

Two questions:

On Tue, Jul 17, 2018 at 10:43 PM Lars Flitter
<password-store at larsflitter.de> wrote:
> To add extension commands to the list of commands append the PASSWORD_STORE_EXTENSION_COMMANDS variable with a leading space:
> PASSWORD_STORE_EXTENSION_COMMANDS=+" COMMAND"

Why not make this a proper bash array? I'm potentially fine with the
flat string, but I'd like to know your reasoning, or if an array was
even considered in designing this feature.

>
> +       local commands="init ls find grep show insert generate edit rm mv cp git help version ${PASSWORD_STORE_EXTENSION_COMMANDS}"

Don't use { and } in this context.


>         if [[ $COMP_CWORD -gt 1 ]]; then
> +               # To complete after an extension command define a function like this:
> +               # __password_store_extension_complete_<COMMAND>() {
> +               #     COMPREPLY+=($(compgen -W "-o --option" -- ${cur}))
> +               #     _pass_complete_entries 1
> +               # }
> +               if type __password_store_extension_complete_${COMP_WORDS[1]} &> /dev/null ;then
> +                       __password_store_extension_complete_${COMP_WORDS[1]}
> +               fi
> +

This should be checked _after_ the built-in commands.

Also, in addition to the nice type check you have, you probably should
also make sure this is part of PASSWORD_STORE_EXTENSION_COMMANDS.
There's an easy way to do that via:

[[ " $PASSWORD_STORE_EXTENSION_COMMANDS " == *" ${COMP_WORDS[1]} "* ]]

Notice the use of spaces inside the quotes.

If you clean this up and resubmit, I'll apply it.

Regards,
Jason


More information about the Password-Store mailing list