80 lines
2.1 KiB
Plaintext
Raw Normal View History

2009-05-21 01:37:14 +02:00
# bash completion for GNU make
have make || have gmake || have gnumake || have pmake &&
_make()
{
local file makef makef_dir="." makef_inc cur prev i split=false
COMPREPLY=()
cur=`_get_cword`
prev=${COMP_WORDS[COMP_CWORD-1]}
_split_longopt && split=true
case $prev in
-@(f|o|W|-@(?(make|old-|new-)file|assume-@(old|new)|what-if)))
_filedir
return 0
;;
-I|-C|--directory|--include-dir)
_filedir -d
return 0
;;
esac
$split && return 0
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" ) )
2009-05-21 01:37:14 +02:00
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
# 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
[ -n "$makef" ] && makef="-f ${makef}"
[ -n "$makef_dir" ] && makef_dir="-C ${makef_dir}"
2009-05-21 01:37:14 +02:00
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" ) )
2009-05-21 01:37:14 +02:00
fi
} &&
complete -F _make $filenames make gmake gnumake pmake
# Local variables:
# mode: shell-script
# sh-basic-offset: 8
# sh-indent-comment: t
# indent-tabs-mode: t
# End:
# ex: ts=8 sw=8 noet filetype=sh