Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Bug#340065: zsh: Using -C arguments to make for completion



On Sun, Nov 20, 2005 at 12:40:59PM +0530, R.Ramkumar wrote:
> current command line to decide the completion of -[CfoW] as well as
> to choose the Makefile to use for getting the targets. This patch
> incorporates this behaviour.

Index: Completion/Unix/Command/_make
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Unix/Command/_make,v
retrieving revision 1.16
diff -u -r1.16 _make
--- Completion/Unix/Command/_make	2 Mar 2005 20:31:32 -0000	1.16
+++ Completion/Unix/Command/_make	9 Feb 2006 14:46:19 -0000
@@ -92,6 +92,28 @@
     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 @@
     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



Messages sorted by: Reverse Date, Date, Thread, Author