about summary refs log tree commit diff
diff options
context:
space:
mode:
authorWayne Davison <wayned@users.sourceforge.net>2005-03-02 19:09:09 +0000
committerWayne Davison <wayned@users.sourceforge.net>2005-03-02 19:09:09 +0000
commitd00043ba40426fbbadfe5d11cd75fbaff3b96bd6 (patch)
treea4fb9fd3d4d267a48f1d429e47170dfbb3575a52
parent6e19bbdf94f9e85b3fb7d502686dfd467f75ce88 (diff)
downloadzsh-d00043ba40426fbbadfe5d11cd75fbaff3b96bd6.tar.gz
zsh-d00043ba40426fbbadfe5d11cd75fbaff3b96bd6.tar.xz
zsh-d00043ba40426fbbadfe5d11cd75fbaff3b96bd6.zip
Don't try to expand a single-character Makefile variable if
it is a digit.
-rw-r--r--Completion/Unix/Command/_make129
1 files changed, 129 insertions, 0 deletions
diff --git a/Completion/Unix/Command/_make b/Completion/Unix/Command/_make
new file mode 100644
index 000000000..3b0bc2476
--- /dev/null
+++ b/Completion/Unix/Command/_make
@@ -0,0 +1,129 @@
+#compdef make gmake pmake dmake
+
+local prev="$words[CURRENT-1]" file expl tmp is_gnu dir incl
+
+expandVars() {
+    local open close var val tmp=$1 ret=$1
+    while :; do
+	var=${tmp#*\$}
+	if [[ $var != $tmp ]]; then
+	    tmp=$var
+	    case $var in
+	    (\(*)
+		open='('
+		close=')'
+		;;
+	    ({*)
+		open='{'
+		close='}'
+		;;
+	    ([[:alpha:]]*)
+		open=''
+		close=''
+		var=${(s::)var[1]}
+		;;
+	    (\$*)
+		# avoid parsing second $ in $$
+		tmp=${tmp#\$}
+		;&
+	    (*)
+		continue
+		;;
+	    esac
+	    if [[ $open != '' ]]; then
+		var=${var#$open}
+		var=${var%%$close*}
+	    fi
+	    case $var in
+	    ([[:alnum:]_]#)
+		val=${(P)var}
+		val=$(expandVars $val)
+		ret=${ret//\$$open$var$close/$val}
+		;;
+	    esac
+	else
+	    print -- ${ret//\$\$/\$}
+	    return
+	fi
+    done
+}
+
+parseMakefile() {
+    local input var val TAB=$'\t' dir=$1
+
+    while read input; do
+	case "$input " in
+	([[:alnum:]][[:alnum:]_]#[ $TAB]#=*)
+	    var=${input%%[ $TAB]#=*}
+	    val=${input#*=}
+	    val=${val##[ $TAB]#}
+	    eval $var=\$val
+	    ;;
+	([[:alnum:]][[:alnum:]_]#[ $TAB]#:=*)
+	    var=${input%%[ $TAB]#:=*}
+	    val=${input#*=}
+	    val=${val##[ $TAB]#}
+	    val=$(expandVars $val)
+	    eval $var=\$val
+	    ;;
+	([[:alnum:]][^$TAB:=]#:[^=]*)
+	    input=${input%%:*}
+	    print $(expandVars $input)
+	    ;;
+	($incl *)
+	    local f=${input##$incl ##}
+	    if [[ $incl = '.include' ]]; then
+		f=${f#[\"<]}
+		f=${f%[\">]}
+	    fi
+	    f=$(expandVars $f)
+	    case $f in
+	    (/*) ;;
+	    (*)  f=$dir/$f ;;
+	    esac
+	    if [ -r $f ]; then
+		parseMakefile ${f%%/[^/]##} < $f
+	    fi
+	    ;;
+	esac
+    done
+}
+
+_pick_variant -r is_gnu gnu=GNU unix -v -f
+
+if [[ $is_gnu = gnu ]]; then
+    incl=include
+else
+    incl=.include
+fi
+if [[ "$prev" = -[CI] ]]; then
+  _files -/
+elif [[ "$prev" = -[foW] ]]; then
+  _files
+else
+  file="$words[(I)-f]"
+  if (( file )); then
+    file="$words[file+1]"
+  elif [[ -e Makefile ]]; then
+    file=Makefile
+  elif [[ -e makefile ]]; then
+    file=makefile
+  elif [[ $is_gnu = gnu && -e GNUmakefile ]]; then
+    file=GNUmakefile
+  else
+    file=''
+  fi
+
+  if [[ -n "$file" ]] && _tags targets; then
+    if [[ $is_gnu = gnu ]] &&
+       zstyle -t ":completion:${curcontext}:targets" call-command; then
+       tmp=( $(_call_program targets "$words[1]" -nsp --no-print-directory -f "$file" .PHONY 2> /dev/null | parseMakefile $PWD) )
+    else
+       tmp=( $(parseMakefile $PWD < $file) )
+    fi
+    _wanted targets expl 'make target' compadd -a tmp && return 0
+  fi
+  compstate[parameter]="${PREFIX%%\=*}"
+  compset -P 1 '*='
+  _value "$@"
+fi