a8cd5a2fe9
Sure hope I didn't miss any super secret crap :-P
101 lines
2.5 KiB
Bash
101 lines
2.5 KiB
Bash
# GNU make(1) completion
|
|
# have make || have gmake || have gnumake || have pmake &&
|
|
_make()
|
|
{
|
|
local file makef makef_dir="." makef_inc cur prev i
|
|
|
|
COMPREPLY=()
|
|
cur=`_get_cword`
|
|
prev=${COMP_WORDS[COMP_CWORD-1]}
|
|
|
|
# --name value style option
|
|
case $prev in
|
|
-@(f|o|W))
|
|
_filedir
|
|
return 0
|
|
;;
|
|
-@(I|C))
|
|
_filedir -d
|
|
return 0
|
|
;;
|
|
esac
|
|
|
|
# --name=value style option
|
|
if [[ "$cur" == *=* ]]; then
|
|
prev=${cur/=*/}
|
|
cur=${cur/*=/}
|
|
case "$prev" in
|
|
--@(file|makefile))
|
|
_filedir
|
|
return 0
|
|
;;
|
|
--@(directory|include-dir))
|
|
_filedir -d
|
|
return 0
|
|
;;
|
|
esac
|
|
fi
|
|
|
|
if [[ "$cur" == -* ]]; then
|
|
COMPREPLY=( $( compgen -W '-b -m -B -C -d -e -f -h -i -I\
|
|
-j -l -k -n -o -p -q -r -R - s -S -t -v -w -W \
|
|
--always-make --directory= --debug \
|
|
--environment-overrides --file= --makefile= --help \
|
|
--ignore-errors --include-dir= --jobs --load-average \
|
|
--max-load --keep-going --just-print --dry-run \
|
|
--recon --old-file= --assume-old= --print-data-base \
|
|
--question --no-builtin-rules --no-builtin-variables \
|
|
--silent --quiet --no-keep-goind --stop --touch \
|
|
--version --print-directory --no-print-directory \
|
|
--what-if= --new-file= --assume-new= \
|
|
--warn-undefined-variables' -- $cur ) )
|
|
else
|
|
# before we check for makefiles, see if a path was specified
|
|
# with -C
|
|
for (( i=0; i < ${#COMP_WORDS[@]}; i++ )); do
|
|
if [[ ${COMP_WORDS[i]} == -C ]]; then
|
|
# eval for tilde expansion
|
|
eval makef_dir=${COMP_WORDS[i+1]}
|
|
break
|
|
fi
|
|
done
|
|
|
|
# make reads `GNUmakefile', then `makefile', then `Makefile'
|
|
if [ -f ${makef_dir}/GNUmakefile ]; then
|
|
makef=${makef_dir}/GNUmakefile
|
|
elif [ -f ${makef_dir}/makefile ]; then
|
|
makef=${makef_dir}/makefile
|
|
elif [ -f ${makef_dir}/Makefile ]; then
|
|
makef=${makef_dir}/Makefile
|
|
else
|
|
makef=${makef_dir}/*.mk # local convention
|
|
fi
|
|
|
|
# before we scan for targets, see if a Makefile name was
|
|
# specified with -f
|
|
for (( i=0; i < ${#COMP_WORDS[@]}; i++ )); do
|
|
if [[ ${COMP_WORDS[i]} == -f ]]; then
|
|
# eval for tilde expansion
|
|
eval makef=${COMP_WORDS[i+1]}
|
|
break
|
|
fi
|
|
done
|
|
|
|
[ ! -f $makef ] && return 0
|
|
|
|
# deal with included Makefiles
|
|
makef_inc=$( grep -E '^-?include' $makef | sed -e "s,^.* ,"$makef_dir"/," )
|
|
|
|
for file in $makef_inc; do
|
|
[ -f $file ] && makef="$makef $file"
|
|
done
|
|
|
|
COMPREPLY=( $( awk -F':' '/^[a-zA-Z0-9][^$#\/\t=]*:([^=]|$)/ \
|
|
{split($1,A,/ /);for(i in A)print A[i]}' \
|
|
$makef 2>/dev/null | command grep "^$cur" ))
|
|
fi
|
|
} &&
|
|
complete -f -F _make $filenames make gmake gnumake pmake
|
|
|
|
# vim:filetype=sh
|