aboutsummaryrefslogtreecommitdiff
path: root/bash/bash_completion.d/pass.bash
diff options
context:
space:
mode:
Diffstat (limited to 'bash/bash_completion.d/pass.bash')
-rw-r--r--bash/bash_completion.d/pass.bash62
1 files changed, 35 insertions, 27 deletions
diff --git a/bash/bash_completion.d/pass.bash b/bash/bash_completion.d/pass.bash
index af7926d9..5a6e0b6c 100644
--- a/bash/bash_completion.d/pass.bash
+++ b/bash/bash_completion.d/pass.bash
@@ -1,11 +1,11 @@
+# Load _completion_ignore_case helper function
+if ! declare -F _completion_ignore_case >/dev/null ; then
+ source "$HOME"/.bash_completion.d/_completion_ignore_case.bash
+fi
+
# Custom completion for pass(1), because I don't like the one included with the
# distribution
-_pass()
-{
- # If we can't read the password directory, just bail
- local passdir
- passdir=${PASSWORD_STORE_DIR:-"$HOME"/.password-store}
- [[ -r $passdir ]] || return
+_pass() {
# Iterate through completions produced by subshell
local ci comp
@@ -13,35 +13,43 @@ _pass()
COMPREPLY[ci++]=$comp
done < <(
- # Set shell options to expand globs the way we expect
+ # Make globs expand appropriately
shopt -u dotglob
shopt -s nullglob
+ if _completion_ignore_case ; then
+ shopt -s nocaseglob
+ fi
+
+ # Set password store path
+ pass_dir=${PASSWORD_STORE_DIR:-"$HOME"/.password-store}
- # Check Readline settings for case-insensitive matching
- while read -r _ setting ; do
- if [[ $setting == 'completion-ignore-case on' ]] ; then
- shopt -s nocaseglob
- break
- fi
- done < <(bind -v)
+ # Gather the entries
+ for entry in "$pass_dir"/"$2"*.gpg ; do
+ entries[ei++]=$entry
+ done
- # Gather the entries, use ** for depth search if we can
- entries=("$passdir"/"$2"*.gpg)
+ # Try to iterate into subdirs, use depth search with ** if available
if shopt -s globstar 2>/dev/null ; then
- entries=("${entries[@]}" "$passdir"/"$2"**/*.gpg)
+ for entry in "$pass_dir"/"$2"**/*.gpg ; do
+ entries[ei++]=$entry
+ done
else
- entries=("${entries[@]}" "$passdir"/"$2"*/*.gpg)
+ for entry in "$pass_dir"/"$2"*/*.gpg ; do
+ entries[ei++]=$entry
+ done
fi
- # Bail out if there are no entries
- ((${#entries[@]})) || exit
-
- # Strip leading path and .gpg suffix from entry names
- entries=("${entries[@]#"$passdir"/}")
- entries=("${entries[@]%.gpg}")
-
- # Print entries, quoted and null-delimited
- printf '%q\0' "${entries[@]}"
+ # Iterate through entries
+ for entry in "${entries[@]}" ; do
+ # Skip directories
+ ! [[ -d $entry ]] || continue
+ # Strip leading path
+ entry=${entry#"$pass_dir"/}
+ # Strip .gpg suffix
+ entry=${entry%.gpg}
+ # Print shell-quoted entry, null terminated
+ printf '%q\0' "$entry"
+ done
)
}
complete -F _pass pass