Skip to content

Commit

Permalink
fix(make): show unique targets in subdirs
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Sep 3, 2021
1 parent dbb80bf commit 89cfbaf
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion completions/make
Expand Up @@ -46,7 +46,7 @@ _make_target_extract_script()
/^$/ { # end of target block
x; # unhold target
/^$/d; # dont print blanks
s|^${dirname_re-}\(.\{${#basename}\}[^:/]*/\{0,1\}\)[^:]*:.*$|${output}|p;
s|^${dirname_re-}\(.\{${#basename}\}[^:]*\):.*$|${output}|p;
d; # hide any bugs
}
Expand Down Expand Up @@ -164,6 +164,45 @@ _make()
${makef+"${makef[@]}"} "${makef_dir[@]}" .DEFAULT 2>/dev/null |
command sed -ne "$script"))

local prefix=$cur
[[ $mode == -d ]] && prefix=
if ((${#COMPREPLY[@]} > 0)); then
local -A processed paths
local target
for target in "${COMPREPLY[@]}"; do
local path=${target%/}
[[ ${processed[$path]+set} ]] && continue
processed[$path]=$target

while
if [[ ! ${paths[$path]+set} ]]; then
((paths[\$path] = 1))
else
((paths[\$path]++))
fi
[[ $path == "$prefix"*/* ]]
do
path=${path%/*}
done
done

COMPREPLY=()
local nreply=0 target
for target in "${!paths[@]}"; do
local path=$target
while [[ $path == "$prefix"*/* ]]; do
path=${path%/*}
((paths[\$path] != 1)) && continue 2
done

if [[ ${processed[$target]+set} ]]; then
COMPREPLY[nreply++]=${processed[$target]}
elif ((paths[\$target] > 1)); then
COMPREPLY[nreply++]=$target/
fi
done
fi

if [[ $mode != -d ]]; then
# Completion will occur if there is only one suggestion
# so set options for completion based on the first one
Expand Down

0 comments on commit 89cfbaf

Please sign in to comment.