@@ -2549,39 +2549,28 @@ __load_completion()
2549
2549
# For loading 3rd party completions wrapped in shopt reset
2550
2550
local IFS=$' \t\n'
2551
2551
2552
- for dir in " ${dirs[@]} " ; do
2553
- [[ -d $dir ]] || continue
2554
- for compfile in " $cmdname " " $cmdname .bash" ; do
2555
- compfile=" $dir /$compfile "
2556
- # Avoid trying to source dirs as long as we support bash < 4.3
2557
- # to avoid an fd leak; https://bugzilla.redhat.com/903540
2558
- if [[ -d $compfile ]]; then
2559
- # Do not warn with . or .. (especially the former is common)
2560
- [[ $compfile == */.?(.) ]] ||
2561
- echo " bash_completion: $compfile : is a directory" >&2
2562
- elif [[ -e $compfile ]] && . " $compfile " ; then
2563
- [[ $backslash ]] && $( complete -p " $cmdname " ) " \\ $cmdname "
2564
- return 0
2565
- fi
2552
+ # Look up and source
2553
+ shift
2554
+ local prefix
2555
+ for prefix in " " _; do # Regular from all dirs first, then fallbacks
2556
+ for dir in " ${dirs[@]} " ; do
2557
+ [[ -d $dir ]] || continue
2558
+ for compfile in " $prefix$cmdname " " $prefix$cmdname .bash" ; do
2559
+ compfile=" $dir /$compfile "
2560
+ # Avoid trying to source dirs as long as we support bash < 4.3
2561
+ # to avoid an fd leak; https://bugzilla.redhat.com/903540
2562
+ if [[ -d $compfile ]]; then
2563
+ # Do not warn with . or .. (especially the former is common)
2564
+ [[ $compfile == */.?(.) ]] ||
2565
+ echo " bash_completion: $compfile : is a directory" >&2
2566
+ elif [[ -e $compfile ]] && . " $compfile " " $cmd " " $@ " ; then
2567
+ [[ $backslash ]] && $( complete -p " $cmdname " ) " \\ $cmdname "
2568
+ return 0
2569
+ fi
2570
+ done
2566
2571
done
2567
2572
done
2568
2573
2569
- # Search fallback completions named " _$cmdname "
2570
- for dir in " ${dirs[@]} " ; do
2571
- [[ -d $dir ]] || continue
2572
- compfile=" $dir /_$cmdname "
2573
- # Avoid trying to source dirs as long as we support bash < 4.3
2574
- # to avoid an fd leak; https://bugzilla.redhat.com/903540
2575
- if [[ -d $compfile ]]; then
2576
- # Do not warn with . or .. (especially the former is common)
2577
- [[ $compfile == */.?(.) ]] ||
2578
- echo " bash_completion: $compfile : is a directory" >&2
2579
- elif [[ -e $compfile ]] && . " $compfile " " $cmd " " $@ " ; then
2580
- [[ $backslash ]] && $( complete -p " $cmdname " ) " \\ $cmdname "
2581
- return 0
2582
- fi
2583
- done
2584
-
2585
2574
# Look up simple " xspec" completions
2586
2575
[[ -v _xspecs[$cmdname ] ]] &&
2587
2576
complete -F _filedir_xspec " $cmdname " " $backslash$cmdname " && return 0
0 commit comments