tadfisher / pass-otp

A pass extension for managing one-time-password (OTP) tokens
GNU General Public License v3.0
1.28k stars 85 forks source link

Bash completion #137

Open hoxu opened 3 years ago

hoxu commented 3 years ago

Is bash completion (on Debian) supposed to work out of box?

As far as I understand /usr/share/bash-completion/bash_completion should contain magic to load the right completion under /usr/share/bash-completion/completions/, and this works for pass, but /usr/share/bash-completion/completions/pass-otp does not seem to be automatically loaded.

source /usr/share/bash-completion/completions/pass-otp works.

Should this work out of box? Or should adding that line to bash profile scripts be documented?

ghost commented 3 years ago

Not quite as technical as hoxu, but I think we're having the same issue (me on Ubuntu 20.04).

In layman's terms; With pass you can give the first few letters of the gpg password file name, then use Tab and like straight bash it will auto-complete as far as it can.

But with pass otp no such Tab completion is present.

Adding Tab completion to pass otp would make it much quicker and more usable, well, just as quick and usable as pass.

bedwardly-down commented 3 years ago

I second this. Although, upon installing through Gentoo's portage system, this error message shows up:

 * Problems with installed bash completions were found:
 *
 *      pass-otp: does not define any completions (failed to source?).
 *
 * For more details on installing bash-completions, please see:
 * https://wiki.gentoo.org/wiki/Bash/Installing_completion_files
 *

It installs version 1.2.0 but my assumption is that something changed with bash-completion between bash releases but I'm not 100% sure on that.

m4lvin commented 2 years ago

Should this work out of box? Or should adding that line to bash profile scripts be documented?

Source'ing that files also enables completion for me, but I think it should work out of the box, because /usr/share/bash-completion/completions/pass from pass itself contains code at the end which is supposed to activate completion for all pass extensions. See https://git.zx2c4.com/password-store/tree/src/completion/pass.bash-completion#n128

# To add completion for an extension command define a function like this:
# __password_store_extension_complete_<COMMAND>() {
#     COMPREPLY+=($(compgen -W "-o --option" -- ${cur}))
#     _pass_complete_entries 1
# }
#
# and add the command to the $PASSWORD_STORE_EXTENSION_COMMANDS array
if [[ " ${PASSWORD_STORE_EXTENSION_COMMANDS[*]} " == *" ${COMP_WORDS[1]} "* ]] && type "__password_store_extension_complete_${COMP_WORDS[1]}" &> /dev/null; then
    "__password_store_extension_complete_${COMP_WORDS[1]}"
fi

Also, the issue here seems to be a duplicate of https://github.com/tadfisher/pass-otp/issues/28 or vice versa ;-)

quentinmit commented 6 months ago

I stumbled on this while trying to debug missing completion for pass otp. I don't actually think there's anything wrong with pass-otp.bash.completion, nor is there anything wrong with the upstream bash-completion package. It's pass's own bash completion code that is wrong - as far as bash-completion is concerned, pass is the command that's being run, not pass-otp. pass.bash-completion needs to trigger loading of pass-otp.bash.completion by calling _completion_loader pass-otp. See how e.g. the git completion does it:

__git_complete_command () {
        local command="$1"
        local completion_func="_git_${command//-/_}"
        if ! __git_have_func $completion_func &&
                __git_have_func _completion_loader
        then
                _completion_loader "git-$command"
        fi
        if __git_have_func $completion_func
        then
                $completion_func
                return 0
        elif __git_support_parseopt_helper "$command"
        then
                __git_complete_common "$command"
                return 0
        else
                return 1
        fi
}