summaryrefslogtreecommitdiff
path: root/contrib/pass.bash-completion
diff options
context:
space:
mode:
authorBrian Mattern <rephorm@rephorm.com>2012-09-22 08:47:30 -0700
committerBrian Mattern <rephorm@rephorm.com>2012-09-22 08:47:30 -0700
commit3f1ea67c5647c51001642e93121836f96075f81c (patch)
treef55b6c0d5aa5de7807029eb84f1e803fb32b10c0 /contrib/pass.bash-completion
parent206e28caa3737f87e8efb1be38294d3279cbed77 (diff)
downloadpass-3f1ea67c5647c51001642e93121836f96075f81c.tar.gz
pass-3f1ea67c5647c51001642e93121836f96075f81c.tar.bz2
pass-3f1ea67c5647c51001642e93121836f96075f81c.zip
simplify logic slightly
Diffstat (limited to 'contrib/pass.bash-completion')
-rw-r--r--contrib/pass.bash-completion21
1 files changed, 12 insertions, 9 deletions
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