blob: 14a248e268a15720bb12291fc727c6845b39bb93 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# Requires Bash >= 4.0 for dotglob and globstar
if ((${BASH_VERSINFO[0]} < 4)) ; then
return
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=${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]}
local entry
while read -d '' -r entry ; do
if [[ $entry == "$word"* ]] ; then
COMPREPLY=("${COMPREPLY[@]}" "$entry")
fi
# This part provides the input to the while loop
done < <(
# Set shell options to expand globs the way we expect
shopt -u dotglob
shopt -s globstar
# 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}")
# Print all the entries, null-delimited
printf '%s\0' "${entries[@]}"
)
}
complete -F _pass pass
|