From 0d9ba4983546acafc768ac087e0d92e94e489202 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Fri, 29 May 2015 18:16:46 +1200 Subject: A few safety fixes to pass completion --- bash/bashrc.d/pass.bash | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'bash') diff --git a/bash/bashrc.d/pass.bash b/bash/bashrc.d/pass.bash index 0c5f2214..14a248e2 100644 --- a/bash/bashrc.d/pass.bash +++ b/bash/bashrc.d/pass.bash @@ -7,9 +7,16 @@ fi # distribution _pass() { + # If we can't read the password directory, just bail + local passdir=${PASSWORD_STORE_DIR:-$HOME/.password-store} + if [[ ! -r "$passdir" ]] ; then + return 1 + fi + + # Iterate through list of .gpg paths, extension stripped, null-delimited, + # and filter them down to the ones matching the completing word (compgen + # doesn't seem to do this properly with a null delimiter) local word=${COMP_WORDS[COMP_CWORD]} - - # Iterate through list of .gpg paths, extension stripped, null-delimited local entry while read -d '' -r entry ; do if [[ $entry == "$word"* ]] ; then @@ -23,11 +30,11 @@ _pass() shopt -u dotglob shopt -s globstar - # Figure out password directory and change into it - passdir=${PASSWORD_STORE_DIR:-$HOME/.password-store} - cd -- "$passdir" || return + # Change into password directory, or bail + cd -- "$passdir" 2>/dev/null || exit # Gather the entries and remove their .gpg suffix + declare -a entries entries=(**/*.gpg) entries=("${entries[@]%.gpg}") -- cgit v1.2.3