Home

Fuzzy pass completion in bash

Written on 2020-05-24

The following snippet enables fzf completion when the Tab key is pressed after writing pass ** in bash:

_fzf_pass_completion() {
    prefix=${PASSWORD_STORE_DIR-~/.password-store}
    password_files=( "$prefix"/**/*.gpg )
    password_files=( "${password_files[@]#"$prefix"/}" )
    password_files=( "${password_files[@]%.gpg}" )
    passwords=$(printf '%s\n' "${password_files[@]}")
    _fzf_complete '+m' "$@" <<< "$passwords"
}

_fzf_setup_completion 'pass' pass