2009-05-21 01:37:14 +02:00
|
|
|
# bash completion for GNU make
|
|
|
|
|
|
|
|
_make()
|
|
|
|
{
|
2011-05-01 22:18:40 +03:00
|
|
|
local cur prev words cword split
|
|
|
|
_init_completion -s || return
|
2009-05-21 01:37:14 +02:00
|
|
|
|
2011-05-01 22:18:40 +03:00
|
|
|
local file makef makef_dir="." makef_inc i
|
2009-05-21 01:37:14 +02:00
|
|
|
|
2009-10-04 19:42:50 +02:00
|
|
|
case $prev in
|
2011-05-11 19:31:13 +03:00
|
|
|
-f|--file|--makefile|-o|--old-file|--assume-old|-W|--what-if|\
|
|
|
|
--new-file|--assume-new)
|
2009-10-04 19:42:50 +02:00
|
|
|
_filedir
|
|
|
|
return 0
|
|
|
|
;;
|
2011-05-11 19:31:13 +03:00
|
|
|
-I|--include-dir|-C|--directory|-m)
|
2009-10-04 19:42:50 +02:00
|
|
|
_filedir -d
|
|
|
|
return 0
|
|
|
|
;;
|
2011-05-11 19:31:13 +03:00
|
|
|
-E)
|
|
|
|
COMPREPLY=( $( compgen -v -- "$cur" ) )
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
--eval|-D|-V|-x)
|
|
|
|
return 0
|
|
|
|
;;
|
2009-10-04 19:42:50 +02:00
|
|
|
esac
|
2009-05-21 01:37:14 +02:00
|
|
|
|
2009-10-04 19:42:50 +02:00
|
|
|
$split && return 0
|
2009-05-21 01:37:14 +02:00
|
|
|
|
2009-10-04 19:42:50 +02:00
|
|
|
if [[ "$cur" == -* ]]; then
|
2011-05-11 19:30:16 +03:00
|
|
|
local opts="$( _parse_help "$1" )"
|
|
|
|
[[ $opts ]] || opts="$( _parse_usage "$1" )"
|
|
|
|
COMPREPLY=( $( compgen -W "$opts" -- "$cur" ) )
|
|
|
|
[[ $COMPREPLY == *= ]] && compopt -o nospace
|
2009-10-04 19:42:50 +02:00
|
|
|
else
|
|
|
|
# before we check for makefiles, see if a path was specified
|
2010-01-19 23:14:46 +02:00
|
|
|
# with -C/--directory
|
2011-04-20 22:42:55 +03:00
|
|
|
for (( i=0; i < ${#words[@]}; i++ )); do
|
|
|
|
if [[ ${words[i]} == -@(C|-directory) ]]; then
|
2009-10-04 19:42:50 +02:00
|
|
|
# eval for tilde expansion
|
2011-04-20 22:42:55 +03:00
|
|
|
eval makef_dir=${words[i+1]}
|
2009-10-04 19:42:50 +02:00
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
2009-05-21 01:37:14 +02:00
|
|
|
|
2009-10-04 19:42:50 +02:00
|
|
|
# before we scan for targets, see if a Makefile name was
|
2010-01-19 23:14:46 +02:00
|
|
|
# specified with -f/--file/--makefile
|
2011-04-20 22:42:55 +03:00
|
|
|
for (( i=0; i < ${#words[@]}; i++ )); do
|
|
|
|
if [[ ${words[i]} == -@(f|-?(make)file) ]]; then
|
2009-10-04 19:42:50 +02:00
|
|
|
# eval for tilde expansion
|
2011-04-20 22:42:55 +03:00
|
|
|
eval makef=${words[i+1]}
|
2009-10-04 19:42:50 +02:00
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
2009-05-21 01:37:14 +02:00
|
|
|
|
2009-10-04 19:42:50 +02:00
|
|
|
[ -n "$makef" ] && makef="-f ${makef}"
|
|
|
|
[ -n "$makef_dir" ] && makef_dir="-C ${makef_dir}"
|
2009-07-25 13:38:42 +03:00
|
|
|
|
2009-10-04 19:42:50 +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
|
|
|
|
2009-10-04 19:42:50 +02:00
|
|
|
fi
|
2009-05-21 01:37:14 +02:00
|
|
|
} &&
|
2010-11-01 19:26:53 +02:00
|
|
|
complete -F _make make gmake gnumake pmake
|
2009-10-01 20:54:51 +03:00
|
|
|
|
|
|
|
# Local variables:
|
|
|
|
# mode: shell-script
|
2009-10-04 19:42:50 +02:00
|
|
|
# sh-basic-offset: 4
|
2009-10-01 20:54:51 +03:00
|
|
|
# sh-indent-comment: t
|
2009-10-04 19:42:50 +02:00
|
|
|
# indent-tabs-mode: nil
|
2009-10-01 20:54:51 +03:00
|
|
|
# End:
|
2009-10-04 19:42:50 +02:00
|
|
|
# ex: ts=4 sw=4 et filetype=sh
|