zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: Apply spell correction to autocd
@ 2005-02-27 20:44 Bart Schaefer
  2005-02-28  6:54 ` Bart Schaefer
  0 siblings, 1 reply; 5+ messages in thread
From: Bart Schaefer @ 2005-02-27 20:44 UTC (permalink / raw)
  To: zsh-workers

I don't know whether this is going to require tweaking for wide-char file
names, but it's at least as good as the current bin_cd() implementation.

Index: Src/utils.c
===================================================================
RCS file: /extra/cvsroot/zsh/zsh-4.0/Src/utils.c,v
retrieving revision 1.21
diff -c -r1.21 utils.c
--- Src/utils.c	18 Feb 2005 17:05:17 -0000	1.21
+++ Src/utils.c	27 Feb 2005 20:35:06 -0000
@@ -1652,6 +1664,7 @@
     char ic = '\0';
     int ne;
     int preflen = 0;
+    int autocd = cmd && isset(AUTOCD) && strcmp(*s, ".") && strcmp(*s, "..");
 
     if ((histdone & HISTFLAG_NOEXEC) || **s == '-' || **s == '%')
 	return;
@@ -1720,6 +1733,19 @@
 	if (!*t && cmd) {
 	    if (hashcmd(guess, pathchecked))
 		return;
+	    if (autocd) {
+		char **pp, *g = guess;
+		for (pp = cdpath; *pp; pp++) {
+		    char *buf = zhtricat(*pp, "/", *s);
+		    spckword(&buf, 0, 0, 0);
+		    if (best && strcmp(best, guess)) {
+			best = buf + strlen(*pp) + 1;
+			break;
+		    } else if (u != g)
+			best = u;
+		}
+		guess = g;
+	    }
 	    d = 100;
 	    scanhashtable(reswdtab, 1, 0, 0, spscan, 0);
 	    scanhashtable(aliastab, 1, 0, 0, spscan, 0);

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2005-02-28 18:17 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-02-27 20:44 PATCH: Apply spell correction to autocd Bart Schaefer
2005-02-28  6:54 ` Bart Schaefer
2005-02-28 10:44   ` Peter Stephenson
2005-02-28 18:14     ` Bart Schaefer
2005-02-28 18:17       ` 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).