aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2015-05-29 18:16:46 +1200
committerTom Ryder <tom@sanctum.geek.nz>2015-05-29 18:16:46 +1200
commit0d9ba4983546acafc768ac087e0d92e94e489202 (patch)
tree5022c22578df69cedf8cd365a3cc506c4875bcc4
parentUse custom function for pass(1) completion (diff)
downloaddotfiles-0d9ba4983546acafc768ac087e0d92e94e489202.tar.gz
dotfiles-0d9ba4983546acafc768ac087e0d92e94e489202.zip
A few safety fixes to pass completion
-rw-r--r--bash/bashrc.d/pass.bash17
1 files changed, 12 insertions, 5 deletions
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}")