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

Re: Modifiers, command position, and so forth (Re: Bug#519535: history expansion: modifier completion missing)



On Tue, 17 Mar 2009 11:46:05 -0700
Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> I guess I'm a little skeptical of the utility of this new option in
> general.  All the other modifiers do something "inside" the history
> string, which would otherwise be difficult to do -- change case,
> truncate, substitute, etc.  This one is just prepending something in
> a way that can already easily be done with $PWD/!$ (for example).

If anything, the boot's on the other foot.  Most of the other modifiers
do simple string handling: find a fixed character, strip something off
in front or behind.  This one rationalises internal components and
possibly resolves symbolic links.

> Here's another case where some intelligence could be applied:
> 
> schaefer<549> cd Src/Zle
> schaefer<550> echo ../b*
> ../builtin.c
> schaefer<551> echo !$:a
> echo /usr/local/src/zsh/zsh-4.0/Src//b*
> /usr/local/src/zsh/zsh-4.0/Src//builtin.c
> 
> Double slash?

That's a bug.

The Meta handling didn't seem to be consistent, either.  I presume the
functions should be both taking and returning metafied strings.

I see it uses realpath() for normalising symbolic links.  I'm not sure
how standard that is (or rather used to be), and the Linux manual warns
about possible size problems.  We should probably use an improved
version of zgetdir(), which could also benefit from having PATH_MAX
removed.  However, zgetdir() is completely undocumented, so that's for
later.

Index: Src/hist.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/hist.c,v
retrieving revision 1.90
diff -u -r1.90 hist.c
--- Src/hist.c	15 Mar 2009 01:17:06 -0000	1.90
+++ Src/hist.c	18 Mar 2009 19:34:27 -0000
@@ -1507,7 +1507,7 @@
 	return 1;
 
     if (**junkptr != '/') {
-	*junkptr = zhtricat(zgetcwd(), "/", *junkptr);
+	*junkptr = zhtricat(metafy(zgetcwd(), -1, META_HEAPDUP), "/", *junkptr);
     }
 
     current = *junkptr;
@@ -1556,6 +1556,8 @@
 		    if (dest[-1] != '/')
 			dest--;
 		    current += 2;
+		    if (*current == '/')
+			current++;
 		} else if (dest == *junkptr + 1) {
 		    /* This might break with Cygwin's leading double slashes? */
 		    current += 2;
@@ -1567,7 +1569,7 @@
 	} else {
 	    while (*current != '/' && *current != '\0')
 		if ((*dest++ = *current++) == Meta)
-		    dest[-1] = *current++ ^ 32;
+		    *dest++ = *current++;
 	}
     }
     return 1;
@@ -1593,6 +1595,8 @@
     if (**junkptr != '/')
 	return 0;
 
+    unmetafy(*junkptr, NULL);
+
     lastpos = strend(*junkptr);
     nonreal = lastpos + 1;
 
@@ -1618,7 +1622,7 @@
 	str++;
     }
 
-    *junkptr = bicat(real, nonreal);
+    *junkptr = metafy(bicat(real, nonreal), -1, META_HEAPDUP);
 
     return 1;
 }


-- 
Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/



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