Skip to content

Commit 557aefc

Browse files
committed
bash-completion: use _filedir
This handles spaces and such much much better Signed-off-by: Arthur Zamarin <arthurzam@gentoo.org>
1 parent 193584c commit 557aefc

1 file changed

Lines changed: 11 additions & 16 deletions

File tree

  • data/share/bash-completion/completions

data/share/bash-completion/completions/pkgdev

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,14 @@ _pkgdev() {
4646
COMPREPLY=($(compgen -W "${base_options}" -- "${cur}"))
4747

4848
# find the subcommand
49-
while [[ "${i}" -lt "${COMP_CWORD}" ]]; do
50-
local s="${COMP_WORDS[i]}"
51-
case "${s}" in
52-
-*) ;;
53-
*)
54-
cmd="${s}"
55-
break
56-
;;
57-
esac
58-
((i++))
49+
for (( i=1; i < COMP_CWORD; i++ )); do
50+
if [[ ${COMP_WORDS[i]} != -* ]]; then
51+
cmd=${COMP_WORDS[i]}
52+
break
53+
fi
5954
done
6055

61-
if [[ "${i}" -eq "${COMP_CWORD}" ]]; then
56+
if (( i == COMP_CWORD )); then
6257
COMPREPLY+=($(compgen -W "${subcommands}" -- "${cur}"))
6358
return
6459
fi
@@ -88,7 +83,7 @@ _pkgdev() {
8883
COMPREPLY=()
8984
;;
9085
-M | --message-template)
91-
COMPREPLY=($(compgen -f -- "${cur}"))
86+
_filedir
9287
;;
9388
-s | --scan | --mangle)
9489
COMPREPLY=($(compgen -W "${boolean_options}" -- "${cur}"))
@@ -108,7 +103,7 @@ _pkgdev() {
108103

109104
case "${prev}" in
110105
-d | --distdir)
111-
COMPREPLY=($(compgen -d -- "${cur}"))
106+
_filedir -d
112107
;;
113108
*)
114109
COMPREPLY+=($(compgen -W "${subcmd_options}" -- "${cur}"))
@@ -224,10 +219,10 @@ _pkgdev() {
224219
COMPREPLY=()
225220
;;
226221
--template-file)
227-
COMPREPLY=($(compgen -f -- "${cur}"))
222+
_filedir
228223
;;
229224
--logs-dir)
230-
COMPREPLY=($(compgen -d -- "${cur}"))
225+
_filedir -d
231226
;;
232227
--extra-env-file)
233228
if [[ -d /etc/portage/env/ ]]; then
@@ -264,7 +259,7 @@ _pkgdev() {
264259
COMPREPLY=()
265260
;;
266261
--dot)
267-
COMPREPLY=($(compgen -f -- "${cur}"))
262+
_filedir
268263
;;
269264
*)
270265
COMPREPLY+=($(compgen -W "${subcmd_options}" -- "${cur}"))

0 commit comments

Comments
 (0)