Skip to content

Commit 2d0f691

Browse files
committed
fix(make): show unique targets in subdirs
1 parent a133ba8 commit 2d0f691

1 file changed

Lines changed: 40 additions & 1 deletion

File tree

completions/make

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ _make_target_extract_script()
4646
/^$/ { # end of target block
4747
x; # unhold target
4848
/^$/d; # dont print blanks
49-
s|^${dirname_re-}\(.\{${#basename}\}[^:/]*/\{0,1\}\)[^:]*:.*$|${output}|p;
49+
s|^${dirname_re-}\(.\{${#basename}\}[^:]*\):.*$|${output}|p;
5050
d; # hide any bugs
5151
}
5252
@@ -164,6 +164,45 @@ _make()
164164
${makef+"${makef[@]}"} "${makef_dir[@]}" .DEFAULT 2>/dev/null |
165165
command sed -ne "$script"))
166166

167+
local prefix=$cur
168+
[[ $mode == -d ]] && prefix=
169+
if ((${#COMPREPLY[@]} > 0)); then
170+
local -A processed paths
171+
local target
172+
for target in "${COMPREPLY[@]}"; do
173+
local path=${target%/}
174+
[[ ${processed[$path]+set} ]] && continue
175+
processed[$path]=$target
176+
177+
while
178+
if [[ ! ${paths[$path]+set} ]]; then
179+
((paths[\$path] = 1))
180+
else
181+
((paths[\$path]++))
182+
fi
183+
[[ $path == "$prefix"*/* ]]
184+
do
185+
path=${path%/*}
186+
done
187+
done
188+
189+
COMPREPLY=()
190+
local nreply=0 target
191+
for target in "${!paths[@]}"; do
192+
local path=$target
193+
while [[ $path == "$prefix"*/* ]]; do
194+
path=${path%/*}
195+
((paths[\$path] != 1)) && continue 2
196+
done
197+
198+
if [[ ${processed[$target]+set} ]]; then
199+
COMPREPLY[nreply++]=${processed[$target]}
200+
elif ((paths[\$target] > 1)); then
201+
COMPREPLY[nreply++]=$target/
202+
fi
203+
done
204+
fi
205+
167206
if [[ $mode != -d ]]; then
168207
# Completion will occur if there is only one suggestion
169208
# so set options for completion based on the first one

0 commit comments

Comments
 (0)