m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--contrib/pass.bash-completion52
1 files changed, 21 insertions, 31 deletions
diff --git a/contrib/pass.bash-completion b/contrib/pass.bash-completion
index e0cdea9..1b9e20e 100644
--- a/contrib/pass.bash-completion
+++ b/contrib/pass.bash-completion
@@ -10,59 +10,52 @@ _pass_complete_entries () {
autoexpand=${1:-0}
local IFS=$'\n'
- for item in $(compgen -f $prefix$cur); do
+ local items=($(compgen -f $prefix$cur))
+ for item in ${items[@]}; do
if [[ $item == $prefix.* ]]; then
continue
fi
- # append / to directories and recursively expand single-entry dirs
- while [[ -d $item ]]; do
- item="$item/"
- if [[ $autoexpand -eq 1 ]]; then
- 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+=($(printf "%q" "${item#$prefix}" ))
+ COMPREPLY+=("${item#$prefix}")
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
+ local keys="$(gpg --list-keys | grep uid | sed -e 's/uid *\([^<]*\)\(<\(.*\)>\)\?/\1\n\3/' | sed -e 's/\(^ *\| *$\)//g')"
+ COMPREPLY+=($(compgen -W "${keys}" -- ${cur}))
}
_pass()
{
- local cur prev opts base
-
COMPREPLY=()
- cur="${COMP_WORDS[COMP_CWORD]}"
- prev="${COMP_WORDS[COMP_CWORD-1]}"
-
- commands="init ls show insert generate edit rm git help --help version --version"
+ local cur="${COMP_WORDS[COMP_CWORD]}"
+ local commands="init ls show insert generate edit rm git help --help version --version"
if [[ $COMP_CWORD -gt 1 ]]; then
case "${COMP_WORDS[1]}" in
init)
COMPREPLY+=($(compgen -W "-e --reencrypt" -- ${cur}))
_pass_complete_keys
;;
- ls|list)
+ ls|list|edit)
_pass_complete_entries
;;
show|-*)
@@ -77,9 +70,6 @@ _pass()
COMPREPLY+=($(compgen -W "-n --no-symbols -c --clip -f --force" -- ${cur}))
_pass_complete_entries
;;
- edit)
- _pass_complete_entries
- ;;
rm|remove|delete)
COMPREPLY+=($(compgen -W "-r --recursive -f --force" -- ${cur}))
_pass_complete_entries
@@ -94,4 +84,4 @@ _pass()
fi
}
-complete -o nospace -F _pass pass
+complete -o filenames -o nospace -F _pass pass