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

PATCH: 3.1.4: autocd to directory in $PATH



Here's the bare bones patch for the bug that if a directory is both in
$cdpath and $path you can't autocd to a subdirectory of it because
that's hashed as a command.

It turns out that there's no major problem if a command to be executed
is in the $path first as a directory, then as a command: the command
is hashed incorrectly (as `hash' shows), but the exec is retried and
works.  Also, which/whence does a more sophisticated search and finds
the true command.

(What's happening is zsh tries to exec the hashed command, and if the
exec fails, only then does the command get searched for.  I toyed for
a moment with the idea of doing without command hashing, but there are
almost certainly too many ramifications.)

Anyway, at the moment it looks to me like nothing other than the full
stat() horror would be a really worthwhile improvement on the
following.

*** Src/exec.c.hc	Mon Sep 28 10:37:43 1998
--- Src/exec.c	Mon Sep 28 11:37:19 1998
***************
*** 524,529 ****
--- 524,542 ----
  
  /**/
  int
+ isreallycom(Cmdnam cn)
+ {
+     char fullnam[MAXCMDLEN];
+     struct stat statbuf;
+ 
+     strcpy(fullnam, cn->u.name ? *(cn->u.name) : "");
+     strcat(fullnam, "/");
+     strcat(fullnam, cn->nam);
+     return iscom(fullnam);
+ }
+ 
+ /**/
+ int
  isrelative(char *s)
  {
      if (*s != '/')
***************
*** 1489,1494 ****
--- 1502,1509 ----
  	    char *cmdarg = (char *) peekfirst(args);
  
  	    hn = cmdnamtab->getnode(cmdnamtab, cmdarg);
+ 	    if (hn && !isreallycom((Cmdnam)hn))
+ 		hn = NULL;
  	    if (!hn && isset(HASHCMDS) && strcmp(cmdarg, "..")) {
  		for (s = cmdarg; *s && *s != '/'; s++);
  		if (!*s)

-- 
Peter Stephenson <pws@xxxxxxxxxxxxxxxxx>       Tel: +39 050 844536
WWW:  http://www.ifh.de/~pws/
Gruppo Teorico, Dipartimento di Fisica
Piazza Torricelli 2, 56100 Pisa, Italy



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