Hi all, When one uses autocompletion on bash, autocompleting the only match doesn't add an extra space. This is necessary when we are completing directory names, however, when we are completing commands and other command line flags, then we want an extra space, as is usual with the completion for other programs.
I've fixed this by not passing "-o nospace" to complete, (so the default is that spaces are added). I then put "compopt -o nospace" whenever we don't want to add an extra space. I have attached the patch that fixes this. Best Regards, Anas
From 02f885c77296a10826c19ca7b73c612e1d51b78b Mon Sep 17 00:00:00 2001 From: Anas Syed <[email protected]> Date: Thu, 28 Jan 2016 22:44:59 +0000 Subject: [PATCH] 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(-) 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 -- 2.1.4
_______________________________________________ Password-Store mailing list [email protected] http://lists.zx2c4.com/mailman/listinfo/password-store
