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 193584c commit 557aefc
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions data/share/bash-completion/completions/pkgdev
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,14 @@ _pkgdev() {
COMPREPLY=($(compgen -W "${base_options}" -- "${cur}"))

# find the subcommand
while [[ "${i}" -lt "${COMP_CWORD}" ]]; do
local s="${COMP_WORDS[i]}"
case "${s}" in
-*) ;;
*)
cmd="${s}"
break
;;
esac
((i++))
for (( i=1; i < COMP_CWORD; i++ )); do
if [[ ${COMP_WORDS[i]} != -* ]]; then
cmd=${COMP_WORDS[i]}
break
fi
done

if [[ "${i}" -eq "${COMP_CWORD}" ]]; then
if (( i == COMP_CWORD )); then
COMPREPLY+=($(compgen -W "${subcommands}" -- "${cur}"))
return
fi
Expand Down Expand Up @@ -88,7 +83,7 @@ _pkgdev() {
COMPREPLY=()
;;
-M | --message-template)
COMPREPLY=($(compgen -f -- "${cur}"))
_filedir
;;
-s | --scan | --mangle)
COMPREPLY=($(compgen -W "${boolean_options}" -- "${cur}"))
Expand All @@ -108,7 +103,7 @@ _pkgdev() {

case "${prev}" in
-d | --distdir)
COMPREPLY=($(compgen -d -- "${cur}"))
_filedir -d
;;
*)
COMPREPLY+=($(compgen -W "${subcmd_options}" -- "${cur}"))
Expand Down Expand Up @@ -224,10 +219,10 @@ _pkgdev() {
COMPREPLY=()
;;
--template-file)
COMPREPLY=($(compgen -f -- "${cur}"))
_filedir
;;
--logs-dir)
COMPREPLY=($(compgen -d -- "${cur}"))
_filedir -d
;;
--extra-env-file)
if [[ -d /etc/portage/env/ ]]; then
Expand Down Expand Up @@ -264,7 +259,7 @@ _pkgdev() {
COMPREPLY=()
;;
--dot)
COMPREPLY=($(compgen -f -- "${cur}"))
_filedir
;;
*)
COMPREPLY+=($(compgen -W "${subcmd_options}" -- "${cur}"))
Expand Down

0 comments on commit 557aefc

Please sign in to comment.