- 'make' completion rewrite by Guillaume Rousse <rousse@ccr.jussieu.fr>

This commit is contained in:
ianmacd 2003-08-03 01:19:30 +00:00
parent 1a542a6164
commit 1fdddc3d64

View File

@ -1,6 +1,6 @@
# bash_completion - some programmable completion functions for bash 2.05b # bash_completion - some programmable completion functions for bash 2.05b
# #
# $Id: bash_completion,v 1.600 2003/08/03 03:07:38 ianmacd Exp $ # $Id: bash_completion,v 1.601 2003/08/03 03:19:30 ianmacd Exp $
# #
# Copyright (C) Ian Macdonald <ian@caliban.org> # Copyright (C) Ian Macdonald <ian@caliban.org>
# #
@ -2213,69 +2213,77 @@ _route()
have make && have make &&
_make() _make()
{ {
local mdef makef gcmd cur prev i local makef cur prev i
COMPREPLY=() COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]} cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]} prev=${COMP_WORDS[COMP_CWORD-1]}
# if prev argument is -f, return possible filename completions. case $prev in
# we could be a little smarter here and return matches against -@(f|o|W))
# `makefile Makefile *.mk', whatever exists
if [[ "$prev" == -*f ]]; then
_filedir _filedir
return 0 return 0
fi ;;
-@(I|C))
# check for a long option _filedir -d
if [[ "$cur" == --* ]]; then
_longopt $1
return 0 return 0
fi ;;
esac
case $cur in
--@(file=|makefile=))
_filedir
return 0
;;
--@(directory=|include-dir=))
_filedir -d
return 0
;;
esac
# if we want an option, return the possible posix options
if [[ "$cur" == -* ]]; then if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '-e -f -i -k -n -p -q -r -S -s -t' \ COMPREPLY=( $( compgen -W '-b -m -B -C -d -e -f -h -i -I\
-- $cur ) ) -j -l -k -n -o -p -q -r -R - s -S -t -v -w -W \
return 0 --always-make --directory= --debug \
fi --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
# make reads `GNUmakefile', then `makefile', then `Makefile' # make reads `GNUmakefile', then `makefile', then `Makefile'
if [ -f GNUmakefile ]; then if [ -f GNUmakefile ]; then
mdef=GNUmakefile makef=GNUmakefile
elif [ -f makefile ]; then elif [ -f makefile ]; then
mdef=makefile makef=makefile
elif [ -f Makefile ]; then elif [ -f Makefile ]; then
mdef=Makefile makef=Makefile
else else
mdef=*.mk # local convention makef=*.mk # local convention
fi fi
# before we scan for targets, see if a makefile name was specified # before we scan for targets, see if a makefile name was specified
# with -f # with -f
for (( i=0; i < ${#COMP_WORDS[@]}; i++ )); do for (( i=0; i < ${#COMP_WORDS[@]}; i++ )); do
if [[ ${COMP_WORDS[i]} == -*f ]]; then if [[ ${COMP_WORDS[i]} == -f ]]; then
eval makef=${COMP_WORDS[i+1]} # eval for tilde expansion # eval for tilde expansion
eval makef=${COMP_WORDS[i+1]}
break break
fi fi
done done
[ -z "$makef" ] && makef=$mdef [ ! -f $makef ] && return 0
# if we have a partial word to complete, restrict completions to COMPREPLY=( $( awk -F':' '/^[^\t ]*:/ {print $1}' $makef \
# matches of that word 2>/dev/null | grep -v "^[.%#]" | grep "^$cur" ))
[ -n "$2" ] && gcmd='grep "^$2"' || gcmd=cat
COMPREPLY=( $( grep -v '^\w\w*[[:space:]]*:=' $makef 2>/dev/null | \ fi
awk 'BEGIN {FS=":"} /^[^.#'$'\t''][^=]*:/ {print $1}' | \
eval $gcmd ) )
# default to filename completion if all else failed
[ ${#COMPREPLY[@]} -eq 0 ] && _filedir
return 0
} }
[ -n "${have:-}" ] && complete -F _make -X '+($*|*.[ch])' $default $filenames make gmake pmake [ -n "${have:-}" ] && complete -F _make $default $filenames make gmake pmake
# GNU tar(1) completion # GNU tar(1) completion
# #