m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnas Syed <anas27@gmail.com>2016-01-28 22:44:59 +0000
committerJason A. Donenfeld <Jason@zx2c4.com>2016-02-06 20:09:57 +0100
commit5e85ea875bc234b70a7ff5294fdea11b9c8f3d63 (patch)
treeb2fcbb36e0ecb3cf6b850b9f53c0575f0959ea33 /src
parentfcb92ed69fc191e39379bad715371d8c28410885 (diff)
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
Diffstat (limited to 'src')
-rw-r--r--src/completion/pass.bash-completion20
1 files changed, 19 insertions, 1 deletions
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