80 lines
2.3 KiB
Plaintext
Raw Normal View History

# bash completion for GNU make -*- shell-script -*-
2009-05-21 01:37:14 +02:00
_make()
{
local cur prev words cword split
_init_completion -s || return
2009-05-21 01:37:14 +02: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
-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
;;
-I|--include-dir|-C|--directory|-m)
2009-10-04 19:42:50 +02:00
_filedir -d
return 0
;;
-E)
COMPREPLY=( $( compgen -v -- "$cur" ) )
return 0
;;
--eval|-D|-V|-x)
return 0
;;
2011-11-09 18:36:08 +02:00
--jobs|-j)
COMPREPLY=( $( compgen -W "{1..$(( $(_ncpus)*2 ))}" -- "$cur" ) )
2011-11-09 18:36:08 +02:00
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
local opts="$( _parse_help "$1" )"
[[ $opts ]] || opts="$( _parse_usage "$1" )"
COMPREPLY=( $( compgen -W "$opts" -- "$cur" ) )
[[ $COMPREPLY == *= ]] && compopt -o nospace
2012-05-11 23:28:57 +03:00
elif [[ $cur == *=* ]]; then
prev=${cur%%=*}
cur=${cur#*=}
local diropt
[[ ${prev,,} == *dir?(ectory) ]] && diropt=-d
_filedir $diropt
2009-10-04 19:42:50 +02:00
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
2009-10-04 19:42:50 +02:00
# eval for tilde expansion
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
# specified with -f/--file/--makefile
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
eval makef=${words[i+1]}
2009-10-04 19:42:50 +02:00
break
fi
done
2009-05-21 01:37:14 +02:00
2011-11-09 23:28:11 +02:00
[[ -n $makef ]] && makef="-f ${makef}"
[[ -n $makef_dir ]] && makef_dir="-C ${makef_dir}"
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
} &&
complete -F _make make gmake gnumake pmake colormake
2009-10-04 19:42:50 +02:00
# ex: ts=4 sw=4 et filetype=sh