make: convert make completion to use smarter parser
This commit is contained in:
parent
1c362f4c99
commit
b28d7108d3
@ -1,11 +1,66 @@
|
|||||||
# bash completion for GNU make -*- shell-script -*-
|
# bash completion for GNU make -*- shell-script -*-
|
||||||
|
|
||||||
|
function _make_target_extract_script()
|
||||||
|
{
|
||||||
|
local prefix=$(printf "%s\n" "$1" | sed 's/[][\.*^$(){}?+|/]/\\&/g')
|
||||||
|
|
||||||
|
cat <<EOF
|
||||||
|
/^# Make data base/,/^# Files/d # skip until files section
|
||||||
|
/^# Not a target/,/^$/ d # skip not target blocks
|
||||||
|
/^${prefix}/,/^$/! d # skip anything user dont want
|
||||||
|
|
||||||
|
# The stuff above here describes lines that are not
|
||||||
|
# explicit targets or not targets other than special ones
|
||||||
|
# The stuff below here decides whether an explicit target
|
||||||
|
# should be output.
|
||||||
|
|
||||||
|
/^# File is an intermediate prerequisite/ {
|
||||||
|
s/^.*$//;x # unhold target
|
||||||
|
d # delete line
|
||||||
|
}
|
||||||
|
|
||||||
|
/^$/ { # end of target block
|
||||||
|
x # unhold target
|
||||||
|
s/^(${prefix}[^:/]*\/).*:.*$/\1/p # write targets for subdirs
|
||||||
|
s/:.*$/ /p # write complete targets
|
||||||
|
d # hide any bugs
|
||||||
|
}
|
||||||
|
|
||||||
|
/^[^#\t:%]+:/ { # found target block
|
||||||
|
|
||||||
|
/^\.PHONY:/ d # special target
|
||||||
|
/^\.SUFFIXES:/ d # special target
|
||||||
|
/^\.DEFAULT:/ d # special target
|
||||||
|
/^\.PRECIOUS:/ d # special target
|
||||||
|
/^\.INTERMEDIATE:/ d # special target
|
||||||
|
/^\.SECONDARY:/ d # special target
|
||||||
|
/^\.SECONDEXPANSION:/ d # special target
|
||||||
|
/^\.DELETE_ON_ERROR:/ d # special target
|
||||||
|
/^\.IGNORE:/ d # special target
|
||||||
|
/^\.LOW_RESOLUTION_TIME:/ d # special target
|
||||||
|
/^\.SILENT:/ d # special target
|
||||||
|
/^\.EXPORT_ALL_VARIABLES:/ d # special target
|
||||||
|
/^\.NOTPARALLEL:/ d # special target
|
||||||
|
/^\.ONESHELL:/ d # special target
|
||||||
|
/^\.POSIX:/ d # special target
|
||||||
|
/^\.NOEXPORT:/ d # special target
|
||||||
|
/^\.MAKE:/ d # special target
|
||||||
|
|
||||||
|
/^[^a-zA-Z0-9]/ d # convention for hidden tgt
|
||||||
|
|
||||||
|
h # hold target
|
||||||
|
d # delete line
|
||||||
|
}
|
||||||
|
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
_make()
|
_make()
|
||||||
{
|
{
|
||||||
local cur prev words cword split
|
local cur prev words cword split
|
||||||
_init_completion -s || return
|
_init_completion -s || return
|
||||||
|
|
||||||
local file makef makef_dir="." makef_inc i
|
local file makef makef_dir=( "-C" "." ) makef_inc i
|
||||||
|
|
||||||
case $prev in
|
case $prev in
|
||||||
-f|--file|--makefile|-o|--old-file|--assume-old|-W|--what-if|\
|
-f|--file|--makefile|-o|--old-file|--assume-old|-W|--what-if|\
|
||||||
@ -49,7 +104,7 @@ _make()
|
|||||||
for (( i=0; i < ${#words[@]}; i++ )); do
|
for (( i=0; i < ${#words[@]}; i++ )); do
|
||||||
if [[ ${words[i]} == -@(C|-directory) ]]; then
|
if [[ ${words[i]} == -@(C|-directory) ]]; then
|
||||||
# eval for tilde expansion
|
# eval for tilde expansion
|
||||||
eval makef_dir=${words[i+1]}
|
eval makef_dir=( -C "${words[i+1]}" )
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
@ -59,18 +114,14 @@ _make()
|
|||||||
for (( i=0; i < ${#words[@]}; i++ )); do
|
for (( i=0; i < ${#words[@]}; i++ )); do
|
||||||
if [[ ${words[i]} == -@(f|-?(make)file) ]]; then
|
if [[ ${words[i]} == -@(f|-?(make)file) ]]; then
|
||||||
# eval for tilde expansion
|
# eval for tilde expansion
|
||||||
eval makef=${words[i+1]}
|
eval makef=( -f "${words[i+1]}" )
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
[[ -n $makef ]] && makef="-f ${makef}"
|
COMPREPLY=( $( compgen -W "$( LC_ALL=C \
|
||||||
[[ -n $makef_dir ]] && makef_dir="-C ${makef_dir}"
|
make -npq "${makef[@]}" "${makef_dir[@]}" .DEFAULT 2>/dev/null | \
|
||||||
|
sed -n -r -f <(_make_target_extract_script "$cur") )" -- "$cur" ) )
|
||||||
COMPREPLY=( $( compgen -W "$( make -qp $makef $makef_dir 2>/dev/null | \
|
|
||||||
awk -F':' '/^[a-zA-Z0-9][^$#\/\t=]*:([^=]|$)/ \
|
|
||||||
{split($1,A,/ /);for(i in A)print A[i]}' )" \
|
|
||||||
-- "$cur" ) )
|
|
||||||
|
|
||||||
fi
|
fi
|
||||||
} &&
|
} &&
|
||||||
|
Loading…
x
Reference in New Issue
Block a user