2011-11-09 23:28:11 +02:00

74 lines
2.1 KiB
Bash

# bash completion for GNU make -*- shell-script -*-
_make()
{
local cur prev words cword split
_init_completion -s || return
local file makef makef_dir="." makef_inc i
case $prev in
-f|--file|--makefile|-o|--old-file|--assume-old|-W|--what-if|\
--new-file|--assume-new)
_filedir
return 0
;;
-I|--include-dir|-C|--directory|-m)
_filedir -d
return 0
;;
-E)
COMPREPLY=( $( compgen -v -- "$cur" ) )
return 0
;;
--eval|-D|-V|-x)
return 0
;;
--jobs|-j)
COMPREPLY=( $( compgen -W "{1..$(_ncpus)}" -- "$cur" ) )
return 0
;;
esac
$split && return 0
if [[ "$cur" == -* ]]; then
local opts="$( _parse_help "$1" )"
[[ $opts ]] || opts="$( _parse_usage "$1" )"
COMPREPLY=( $( compgen -W "$opts" -- "$cur" ) )
[[ $COMPREPLY == *= ]] && compopt -o nospace
else
# before we check for makefiles, see if a path was specified
# with -C/--directory
for (( i=0; i < ${#words[@]}; i++ )); do
if [[ ${words[i]} == -@(C|-directory) ]]; then
# eval for tilde expansion
eval makef_dir=${words[i+1]}
break
fi
done
# before we scan for targets, see if a Makefile name was
# specified with -f/--file/--makefile
for (( i=0; i < ${#words[@]}; i++ )); do
if [[ ${words[i]} == -@(f|-?(make)file) ]]; then
# eval for tilde expansion
eval makef=${words[i+1]}
break
fi
done
[[ -n $makef ]] && makef="-f ${makef}"
[[ -n $makef_dir ]] && makef_dir="-C ${makef_dir}"
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
} &&
complete -F _make make gmake gnumake pmake
# ex: ts=4 sw=4 et filetype=sh