Merge pull request #1502 from cornfeedhobo/enhance-makefile-completion
Enhance make completion to support multiple files and gnumake
This commit is contained in:
@@ -1,3 +1,34 @@
|
|||||||
# Add completion for Makefile
|
# Bash completion for Makefile
|
||||||
# see http://stackoverflow.com/a/38415982/1472048
|
# Loosely adapted from http://stackoverflow.com/a/38415982/1472048
|
||||||
complete -W "\`grep -oE '^[a-zA-Z0-9_-]+:([^=]|$)' Makefile | sed 's/[^a-zA-Z0-9_-]*$//'\`" make
|
|
||||||
|
_makecomplete() {
|
||||||
|
COMPREPLY=()
|
||||||
|
|
||||||
|
# https://www.gnu.org/software/make/manual/html_node/Makefile-Names.html
|
||||||
|
local files=()
|
||||||
|
for f in 'GNUmakefile' 'makefile' 'Makefile' ; do
|
||||||
|
[ -f "$f" ] && files+=("$f")
|
||||||
|
done
|
||||||
|
|
||||||
|
[ "${#files[@]}" -eq 0 ] && return 0
|
||||||
|
|
||||||
|
# collect all targets
|
||||||
|
local targets=()
|
||||||
|
for f in "${files[@]}" ; do
|
||||||
|
while IFS='' read -r line ; do
|
||||||
|
targets+=("$line")
|
||||||
|
done < <(grep -oE '^[a-zA-Z0-9_-]+:([^=]|$)' "$f" | cut -d':' -f1)
|
||||||
|
done
|
||||||
|
|
||||||
|
[ "${#targets[@]}" -eq 0 ] && return 0
|
||||||
|
|
||||||
|
# use the targets for completion
|
||||||
|
while IFS='' read -r line ; do
|
||||||
|
COMPREPLY+=("$line")
|
||||||
|
done < <(compgen -W "$(tr ' ' '\n' <<<"${targets[@]}" | sort -u)" -- "${COMP_WORDS[COMP_CWORD]}")
|
||||||
|
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
complete -o nospace -F _makecomplete make
|
||||||
|
complete -o nospace -F _makecomplete gnumake
|
||||||
|
|||||||
Reference in New Issue
Block a user