zsh-workers
 help / color / mirror / code / Atom feed
* Re: Bug#340065: zsh: Using -C arguments to make for completion
       [not found] <87d5kvkd4s.fsf@moonface.iitm.ac.in>
@ 2006-02-09 14:47 ` Clint Adams
  0 siblings, 0 replies; only message in thread
From: Clint Adams @ 2006-02-09 14:47 UTC (permalink / raw)
  To: zsh-workers

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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2006-02-09 14:48 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <87d5kvkd4s.fsf@moonface.iitm.ac.in>
2006-02-09 14:47 ` Bug#340065: zsh: Using -C arguments to make for completion Clint Adams

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).