Skip to content

Commit e4ede51

Browse files
committed
fix(__load_completion): don't resolve symlinks to invoked command
This might make the path we install completions for different from the invoked path so that the completion would fail to actually load after setup. The final path segment might also have a different name in the resolved symlink, and we should not install it for the resolved name, because the target's functionality might vary based on the invocation name. Simply replacing the final path segment with the original basename could yield a path that does not exist, even though the original invoked one does. #924 (comment)
1 parent 28b587a commit e4ede51

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

bash_completion

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2518,14 +2518,11 @@ __load_completion()
25182518
backslash=\\
25192519
fi
25202520
2521-
# Try to resolve real path to $cmd, and make it absolute
2522-
local ret realcmd="" origcmd=$cmd
2523-
if _comp_realcommand "$cmd"; then
2524-
realcmd=$ret
2525-
# Retain original basename, target $realcmd might behave differently
2526-
# depending on what it gets invoked as, so we should not install
2527-
# a completion for a different one for it. For example `busybox`.
2528-
cmd=${realcmd%/*}/$cmdname
2521+
# Resolve absolute path to $cmd
2522+
local ret pathcmd origcmd=$cmd
2523+
if pathcmd=$(type -P "$cmd"); then
2524+
_comp_abspath "$pathcmd"
2525+
cmd=$ret
25292526
fi
25302527
25312528
local -a dirs=()
@@ -2552,7 +2549,7 @@ __load_completion()
25522549
fi
25532550
25542551
# 3) From bin directories extracted from path to command, and $PATH
2555-
[[ $realcmd ]] && paths=("${realcmd%/*}") || paths=()
2552+
[[ $cmd == */* ]] && paths=("${cmd%/*}") || paths=()
25562553
_comp_split -aF : paths "$PATH"
25572554
for dir in "${paths[@]%/}"; do
25582555
[[ $dir == ?*/@(bin|sbin) ]] &&

0 commit comments

Comments
 (0)