summaryrefslogtreecommitdiff
path: root/contrib/pass.bash-completion
diff options
context:
space:
mode:
authorBrian Mattern <rephorm@rephorm.com>2012-09-21 14:41:16 -0700
committerBrian Mattern <rephorm@rephorm.com>2012-09-21 14:41:16 -0700
commit34b0a3ba7ff1932977672e12ad728441cf859aab (patch)
tree5f49da8207f8e5b334a8a9f8e8ffeaa2f1b8c32e /contrib/pass.bash-completion
parentb947ef162265060fc79933403968f0fa8d37e214 (diff)
downloadpass-34b0a3ba7ff1932977672e12ad728441cf859aab.tar.gz
pass-34b0a3ba7ff1932977672e12ad728441cf859aab.tar.bz2
pass-34b0a3ba7ff1932977672e12ad728441cf859aab.zip
Better gpg key completion for `pass init`
Diffstat (limited to 'contrib/pass.bash-completion')
-rw-r--r--contrib/pass.bash-completion17
1 files changed, 15 insertions, 2 deletions
diff --git a/contrib/pass.bash-completion b/contrib/pass.bash-completion
index bd7ed61..e0cdea9 100644
--- a/contrib/pass.bash-completion
+++ b/contrib/pass.bash-completion
@@ -33,6 +33,20 @@ _pass_complete_entries () {
done
}
+_pass_complete_keys () {
+ local IFS=$'\n'
+ # Extract names and email addresses from gpg --list-keys
+ keys="$(gpg --list-keys | grep uid | sed -e 's/uid *\([^<]*\)\(<\(.*\)>\)\?/\1\n\3/' | sed -e 's/\(^ *\| *$\)//g')"
+ matches="$(compgen -W "${keys}" -- ${cur})"
+ local l=${#cur}
+ for key in ${matches}; do
+ key="$(printf "%q" "${key}")"
+ if [[ $l -eq 0 || "${key:0:$l}" == "${cur}" ]]; then
+ COMPREPLY+=("$key")
+ fi
+ done
+}
+
_pass()
{
local cur prev opts base
@@ -46,8 +60,7 @@ _pass()
case "${COMP_WORDS[1]}" in
init)
COMPREPLY+=($(compgen -W "-e --reencrypt" -- ${cur}))
- keys=$(gpg --list-keys |grep uid |sed 's/.*<\(.*\)>/\1/')
- COMPREPLY+=($(compgen -W "${keys}" -- ${cur}))
+ _pass_complete_keys
;;
ls|list)
_pass_complete_entries