From 3f1ea67c5647c51001642e93121836f96075f81c Mon Sep 17 00:00:00 2001 From: Brian Mattern Date: Sat, 22 Sep 2012 08:47:30 -0700 Subject: simplify logic slightly --- contrib/pass.bash-completion | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'contrib') diff --git a/contrib/pass.bash-completion b/contrib/pass.bash-completion index a7d0f28..72f2abb 100644 --- a/contrib/pass.bash-completion +++ b/contrib/pass.bash-completion @@ -15,20 +15,23 @@ _pass_complete_entries () { if [[ $item == $prefix.* ]]; then continue fi - # append / to directories and recursively expand single-entry dir - while [[ -d $item ]]; do - item="$item/" - if [[ ${#items[@]} -eq 1 && $autoexpand -eq 1 ]]; then - local subitems=($(compgen -f $item)) + + # if there is a unique match, and it is a directory with one entry + # autocomplete the subentry as well (recursively) + if [[ ${#items[@]} -eq 1 && $autoexpand -eq 1 ]]; then + while [[ -d $item ]]; do + local subitems=($(compgen -f "$item/")) if [[ ${#subitems[@]} -eq 1 ]]; then item="${subitems[0]}" else break fi - else - break - fi - done + done + fi + + # append / to directories + [[ -d $item ]] && item="$item/" + item="${item%$suffix}" COMPREPLY+=("${item#$prefix}") done -- cgit v1.2.3-59-g8ed1b