Skip to content

Commit

Permalink
bash-completion: use _filedir
Browse files Browse the repository at this point in the history
This handles spaces and such much much better

Signed-off-by: Arthur Zamarin <[email protected]>
  • Loading branch information
arthurzam committed Jul 4, 2024
1 parent ccb467c commit 5c76974
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions data/share/bash-completion/completions/pkgcheck
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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}"))
Expand All @@ -90,7 +87,7 @@ _pkgcheck() {

case ${prev} in
--failures)
COMPREPLY=($(compgen -f -- "${cur}"))
_filedir
;;
*)
COMPREPLY+=($(compgen -W "${subcmd_options[*]}" -- "${cur}"))
Expand All @@ -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
;;
Expand Down Expand Up @@ -146,7 +146,7 @@ _pkgcheck() {
COMPREPLY=()
;;
--cache-dir)
COMPREPLY=($(compgen -d -- "${cur}"))
_filedir -d
;;
-r | --repo)
COMPREPLY=($(compgen -W "$(_parsereposconf -l)" -- "${cur}"))
Expand Down

0 comments on commit 5c76974

Please sign in to comment.