commit:     5c76974cb0e7ab54ddd900785319e3ac6fd2ffa8
Author:     Arthur Zamarin <arthurzam <AT> gentoo <DOT> org>
AuthorDate: Thu Jul  4 20:06:15 2024 +0000
Commit:     Arthur Zamarin <arthurzam <AT> gentoo <DOT> org>
CommitDate: Thu Jul  4 20:06:15 2024 +0000
URL:        
https://gitweb.gentoo.org/proj/pkgcore/pkgcheck.git/commit/?id=5c76974c

bash-completion: use _filedir

This handles spaces and such much much better

Signed-off-by: Arthur Zamarin <arthurzam <AT> gentoo.org>

 data/share/bash-completion/completions/pkgcheck | 30 ++++++++++++-------------
 1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/data/share/bash-completion/completions/pkgcheck 
b/data/share/bash-completion/completions/pkgcheck
index 8801391b..972fc1e5 100644
--- a/data/share/bash-completion/completions/pkgcheck
+++ b/data/share/bash-completion/completions/pkgcheck
@@ -43,18 +43,15 @@ _pkgcheck() {
     COMPREPLY=($(compgen -W "${base_options[*]}" -- "${cur}"))
 
     # find the subcommand
-    for ((i = 1; i < ${COMP_CWORD}; i++)); do
-        case "${COMP_WORDS[i]}" in
-            -*) ;;
-            *)
-                cmd=${COMP_WORDS[i]}
-                break
-                ;;
-        esac
+    for (( i=1; i < COMP_CWORD; i++ )); do
+        if [[ ${COMP_WORDS[i]} != -* ]]; then
+            cmd=${COMP_WORDS[i]}
+            break
+        fi
     done
 
-    if [[ ${i} == ${COMP_CWORD} ]]; then
-        COMPREPLY+=($(compgen -W "${subcommands[*]}" -- "${cur}"))
+    if (( i == COMP_CWORD )); then
+        COMPREPLY+=($(compgen -W "${subcommands}" -- "${cur}"))
         return
     fi
 
@@ -73,7 +70,7 @@ _pkgcheck() {
 
             case ${prev} in
                 --cache-dir)
-                               COMPREPLY=($(compgen -d -- "${cur}"))
+                               _filedir -d
                     ;;
                 -t | --type)
                     COMPREPLY=($(compgen -W "$(</usr/share/pkgcheck/caches)" 
-- "${cur}"))
@@ -90,7 +87,7 @@ _pkgcheck() {
 
             case ${prev} in
                 --failures)
-                    COMPREPLY=($(compgen -f -- "${cur}"))
+                    _filedir
                     ;;
                 *)
                     COMPREPLY+=($(compgen -W "${subcmd_options[*]}" -- 
"${cur}"))
@@ -111,8 +108,11 @@ _pkgcheck() {
                     COMPREPLY=()
                     ;;
                 *)
-                    COMPREPLY+=($(compgen -W "${subcmd_options[*]}" -- 
"${cur}"))
-                    COMPREPLY+=($(compgen -f -- "${cur}"))
+                    if [[ ${cur} == -* ]]; then
+                        COMPREPLY+=($(compgen -W "${subcmd_options[*]}" -- 
"${cur}"))
+                    else
+                        _filedir
+                    fi
                     ;;
             esac
             ;;
@@ -146,7 +146,7 @@ _pkgcheck() {
                     COMPREPLY=()
                     ;;
                 --cache-dir)
-                               COMPREPLY=($(compgen -d -- "${cur}"))
+                               _filedir -d
                     ;;
                 -r | --repo)
                     COMPREPLY=($(compgen -W "$(_parsereposconf -l)" -- 
"${cur}"))

Reply via email to