enhance makefile completion and make shellcheck happy
parent
b70c02c4ae
commit
9d97532f8e
|
|
@ -5,18 +5,24 @@
|
||||||
|
|
||||||
_makecomplete() {
|
_makecomplete() {
|
||||||
# https://www.gnu.org/software/make/manual/html_node/Makefile-Names.html
|
# https://www.gnu.org/software/make/manual/html_node/Makefile-Names.html
|
||||||
local files=( $(find . -maxdepth 1 -regextype posix-extended -regex '.*(GNU)?[Mm]akefile$' -printf '%f ') )
|
local files=()
|
||||||
|
while IFS='' read -r line; do
|
||||||
|
files+=("$line")
|
||||||
|
done < <(find . -maxdepth 1 -regextype posix-extended -regex '.*(GNU)?[Mm]akefile$' -printf '%f\n')
|
||||||
|
|
||||||
# collect all targets
|
# collect all targets
|
||||||
local targets=''
|
local targets=()
|
||||||
for f in ${files[@]} ; do
|
for f in "${files[@]}" ; do
|
||||||
for t in $(grep -oE '^[a-zA-Z0-9_-]+:([^=]|$)' $f | cut -d':' -f1) ; do
|
while IFS='' read -r line ; do
|
||||||
targets+="$t\n"
|
targets+=("$line")
|
||||||
done
|
done < <(grep -oE '^[a-zA-Z0-9_-]+:([^=]|$)' "$f" | cut -d':' -f1)
|
||||||
done
|
done
|
||||||
|
|
||||||
# flatten the array for completion
|
# flatten the array for completion
|
||||||
COMPREPLY=($(compgen -W "$(echo -e "$targets" | head -c -1 | sort -u)" -- ${COMP_WORDS[COMP_CWORD]}))
|
COMPREPLY=()
|
||||||
|
while IFS='' read -r line ; do
|
||||||
|
COMPREPLY+=("$line")
|
||||||
|
done < <(compgen -W "$(tr ' ' '\n' <<<"${targets[@]}" | sort -u)" -- "${COMP_WORDS[COMP_CWORD]}")
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue