about summary refs log tree commit diff
path: root/Completion/Unix
diff options
context:
space:
mode:
authorClint Adams <clint@users.sourceforge.net>2006-02-09 14:51:24 +0000
committerClint Adams <clint@users.sourceforge.net>2006-02-09 14:51:24 +0000
commit21fb933522cd7509c52acf49bf771cec305d6fe8 (patch)
treedf3d84fc432f87a25a386602683085af9b411530 /Completion/Unix
parentc80682a850c89fcaa6ec172e8e3aef7d11041fef (diff)
downloadzsh-21fb933522cd7509c52acf49bf771cec305d6fe8.tar.gz
zsh-21fb933522cd7509c52acf49bf771cec305d6fe8.tar.xz
zsh-21fb933522cd7509c52acf49bf771cec305d6fe8.zip
22205: patch from R.Ramkumar to use the argument to -C in make completion.
Diffstat (limited to 'Completion/Unix')
-rw-r--r--Completion/Unix/Command/_make48
1 files changed, 38 insertions, 10 deletions
diff --git a/Completion/Unix/Command/_make b/Completion/Unix/Command/_make
index 91dcc1558..76eb43f0a 100644
--- a/Completion/Unix/Command/_make
+++ b/Completion/Unix/Command/_make
@@ -92,6 +92,28 @@ parseMakefile() {
     done
 }
 
+findBasedir () {
+  local file index basedir
+  basedir=$PWD
+  for ((index=0; index<$#@; index++)); do
+    if [[ $@[index] = -C ]]; then
+      file=${~@[index+1]};
+      if [[ -z $file ]]; then
+	# make returns with an error if an empty arg is given
+	# even if the concatenated path is a valid directory
+	return
+      elif [[ $file = /* ]]; then
+	# Absolute path, replace base directory
+	basedir=$file
+      else
+	# Relative, concatenate path
+	basedir=$basedir/$file
+      fi
+    fi
+  done
+  print -- $basedir
+}
+
 _pick_variant -r is_gnu gnu=GNU unix -v -f
 
 if [[ $is_gnu = gnu ]]; then
@@ -100,21 +122,27 @@ else
     incl=.include
 fi
 if [[ "$prev" = -[CI] ]]; then
-  _files -/
+  _files -W ${(q)$(findBasedir ${words[1,CURRENT-1]})} -/
 elif [[ "$prev" = -[foW] ]]; then
-  _files
+  _files -W ${(q)$(findBasedir $words)}
 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
+    file=${~words[file+1]}
+    [[ $file = [^/]* ]] && file=${(q)$(findBasedir $words)}/$file
+    [[ -r $file ]] || file=
   else
-    file=''
+    local basedir
+    basedir=${(q)$(findBasedir $words)}
+    if [[ $is_gnu = gnu && -r $basedir/GNUmakefile ]]; then
+      file=$basedir/GNUmakefile
+    elif [[ -r $basedir/makefile ]]; then
+      file=$basedir/makefile
+    elif [[ -r $basedir/Makefile ]]; then
+      file=$basedir/Makefile
+    else
+      file=''
+    fi
   fi
 
   if [[ -n "$file" ]] && _tags targets; then