From 5e85ea875bc234b70a7ff5294fdea11b9c8f3d63 Mon Sep 17 00:00:00 2001 From: Anas Syed Date: Thu, 28 Jan 2016 22:44:59 +0000 Subject: completion: Output a space when appropriate on bash completion Did this by not passing "-o nospace" to complete. Instead, put "compopt -o nospace" after a COMPREPLY that shouldn't add a space when autocompleting the only match --- src/completion/pass.bash-completion | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'src/completion/pass.bash-completion') diff --git a/src/completion/pass.bash-completion b/src/completion/pass.bash-completion index efd4b70..456485b 100644 --- a/src/completion/pass.bash-completion +++ b/src/completion/pass.bash-completion @@ -12,6 +12,13 @@ _pass_complete_entries () { local IFS=$'\n' local items=($(compgen -f $prefix$cur)) + + # Remember the value of the first item, to see if it is a directory. If + # it is a directory, then don't add a space to the completion + local firstitem="" + # Use counter, can't use ${#items[@]} as we skip hidden directories + local i=0 + for item in ${items[@]}; do [[ $item =~ /\.[^/]*$ ]] && continue @@ -38,7 +45,17 @@ _pass_complete_entries () { item="${item%$suffix}" COMPREPLY+=("${item#$prefix}") + if [[ $i -eq 0 ]]; then + firstitem=$item + fi + let i+=1 done + + # The only time we want to add a space to the end is if there is only + # one match, and it is not a directory + if [[ $i -gt 1 || ( $i -eq 1 && -d $firstitem ) ]]; then + compopt -o nospace + fi } _pass_complete_folders () { @@ -71,6 +88,7 @@ _pass() init) if [[ $lastarg == "-p" || $lastarg == "--path" ]]; then _pass_complete_folders + compopt -o nospace else COMPREPLY+=($(compgen -W "-p --path" -- ${cur})) _pass_complete_keys @@ -109,4 +127,4 @@ _pass() fi } -complete -o filenames -o nospace -F _pass pass +complete -o filenames -F _pass pass -- cgit v1.2.3