enhance makefile completion to support multiple files and gnumake
This commit is contained in:
@@ -1,3 +1,24 @@
|
|||||||
# Add completion for Makefile
|
#!/usr/bin/env bash
|
||||||
# see http://stackoverflow.com/a/38415982/1472048
|
# Bash completion for Makefile
|
||||||
complete -W "\`grep -oE '^[a-zA-Z0-9_-]+:([^=]|$)' Makefile | sed 's/[^a-zA-Z0-9_-]*$//'\`" make
|
|
||||||
|
# Loosely adapted from http://stackoverflow.com/a/38415982/1472048
|
||||||
|
|
||||||
|
_makecomplete() {
|
||||||
|
# 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 ') )
|
||||||
|
|
||||||
|
# collect all targets
|
||||||
|
local targets=''
|
||||||
|
for f in ${files[@]} ; do
|
||||||
|
for t in $(grep -oE '^[a-zA-Z0-9_-]+:([^=]|$)' $f | cut -d':' -f1) ; do
|
||||||
|
targets+="$t\n"
|
||||||
|
done
|
||||||
|
done
|
||||||
|
|
||||||
|
# flatten the array for completion
|
||||||
|
COMPREPLY=($(compgen -W "$(echo -e "$targets" | head -c -1 | 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