Make '-C' and '-f' option work together.
--- a/.bashrc Mon Nov 07 11:06:34 2011 +0200
+++ b/.bashrc Mon Nov 07 20:32:07 2011 +0200
@@ -244,24 +244,30 @@
_make() {
local i mk
+ local dir=.
local cur=${COMP_WORDS[COMP_CWORD]}
- [[ $COMP_CWORD > 0 ]] && prev=${COMP_WORDS[COMP_CWORD-1]}
- if [[ $prev = -f ]]; then
- COMPREPLY=( $(compgen -f -- "$cur") )
+ if [[ $cur = -* ]]; then
+ COMPREPLY=( $(compgen -W "-C -f" -- "$cur") )
return 0
fi
+ [[ $COMP_CWORD > 0 ]] && prev=${COMP_WORDS[COMP_CWORD-1]}
+ for (( i=1; i < ${#COMP_WORDS[@]}-1; i++ )); do
+ case ${COMP_WORDS[i]} in
+ -f) mk=${COMP_WORDS[i+1]} ;;
+ -C) dir=${COMP_WORDS[i+1]} ;;
+ esac
+ done
if [[ $prev = -C ]]; then
COMPREPLY=( $(compgen -d -- "$cur") )
return 0
fi
- for (( i=1; i < ${#COMP_WORDS[@]}-1; i++ )); do
- if [[ ${COMP_WORDS[i]} == -f ]]; then
- mk=${COMP_WORDS[i+1]}
- break
- fi
- done
- [[ ! -f $mk ]] && mk=$(eval echo [Mm]akefile)
- [[ -f $mk ]] || return 0
+ if [[ $prev = -f ]]; then
+ COMPREPLY=( $(cd $dir >/dev/null 2>&1; compgen -f -- "$cur") )
+ return 0
+ fi
+ mk=$dir/$mk
+ [[ -f $mk ]] || mk=$(eval echo $dir/[Mm]akefile)
+ [[ -f $mk ]] || return 1
COMPREPLY=( $(compgen -W "$(sed -n -e '/^[[:alnum:]_-]*:/{s=^\([^:]*\):.*=\1=;p;}' $mk)" -- $cur) )
return 0
}