Skip to content

Commit 6b8d4a5

Browse files
committed
feat(__load_completion): pass absolute path when sourcing and available
Mostly for better handling of completions loaded via relative paths, in case the completion registers it for the exact command passed to it.
1 parent 9e07654 commit 6b8d4a5

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

bash_completion

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2508,6 +2508,13 @@ __load_completion()
25082508
backslash=\\
25092509
fi
25102510
2511+
# Try to resolve real path to $cmd, and make it absolute
2512+
local ret realcmd=
2513+
if _comp_realcommand "$cmd"; then
2514+
realcmd=$ret
2515+
cmd=${realcmd%/*}/$cmdname # basename could be an alias
2516+
fi
2517+
25112518
local -a dirs=()
25122519
25132520
# Lookup order:
@@ -2531,9 +2538,8 @@ __load_completion()
25312538
dirs+=(./completions)
25322539
fi
25332540
2534-
# 3) From bin directories extracted from $(realpath "$cmdname") and PATH
2535-
local ret
2536-
_comp_realcommand "$cmd" && paths=("${ret%/*}") || paths=()
2541+
# 3) From bin directories extracted from path to command, and $PATH
2542+
[[ $realcmd ]] && paths=("${realcmd%/*}") || paths=()
25372543
_comp_split -aF : paths "$PATH"
25382544
for dir in "${paths[@]%/}"; do
25392545
if [[ -d $dir && $dir == ?*/@(bin|sbin) ]]; then

0 commit comments

Comments
 (0)