From b947ef162265060fc79933403968f0fa8d37e214 Mon Sep 17 00:00:00 2001 From: Brian Mattern Date: Fri, 21 Sep 2012 14:40:43 -0700 Subject: Append to COMPREPLY instead of inserting by index --- contrib/pass.bash-completion | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'contrib') diff --git a/contrib/pass.bash-completion b/contrib/pass.bash-completion index 36c0cf2..bd7ed61 100644 --- a/contrib/pass.bash-completion +++ b/contrib/pass.bash-completion @@ -10,7 +10,6 @@ _pass_complete_entries () { autoexpand=${1:-0} local IFS=$'\n' - local i=0 for item in $(compgen -f $prefix$cur); do if [[ $item == $prefix.* ]]; then continue @@ -30,8 +29,7 @@ _pass_complete_entries () { fi done item="${item%$suffix}" - COMPREPLY[$i]=$(printf "%q" "${item#$prefix}" ) - (( i++ )) + COMPREPLY+=($(printf "%q" "${item#$prefix}" )) done } -- cgit v1.2.3 From 34b0a3ba7ff1932977672e12ad728441cf859aab Mon Sep 17 00:00:00 2001 From: Brian Mattern Date: Fri, 21 Sep 2012 14:41:16 -0700 Subject: Better gpg key completion for `pass init` --- contrib/pass.bash-completion | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'contrib') 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 -- cgit v1.2.3