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

PATCH: Apply spell correction to autocd



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   



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