Skip to content

Commit 9e07654

Browse files
committed
feat(__load_completion): source all completions with same args
For consistency and completeness, e.g. arg #'s > 1 for fallback loaders, and the same (possibly processed) command.
1 parent e01c4a1 commit 9e07654

File tree

1 file changed

+19
-30
lines changed

1 file changed

+19
-30
lines changed

bash_completion

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2549,39 +2549,28 @@ __load_completion()
25492549
# For loading 3rd party completions wrapped in shopt reset
25502550
local IFS=$' \t\n'
25512551
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
25662571
done
25672572
done
25682573
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-
25852574
# Look up simple "xspec" completions
25862575
[[ -v _xspecs[$cmdname] ]] &&
25872576
complete -F _filedir_xspec "$cmdname" "$backslash$cmdname" && return 0

0 commit comments

Comments
 (0)