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

Re: remote files completion for scp



=?iso-8859-2?Q?Micha=B3?= Politowski wrote:
> I believe that this completion needs something, maybe dequoting like
> this, to work correctly.

I'm leaving this, it's hard enough decoding your own hieroglyphics in
zsh and I don't use this.

> One other thing. I obviously don't understand something about quoting.
> Why with foo='a\string\with\some\backslashes'
> echo "${foo//'\'/-}"
> and
> echo "${foo//"\\"/-}"
> work but
> echo "${foo//\\/-}"
> doesn't do any substitutions,
> no matter how many backslashes do I actually put in the last one?

This seems to be because I screwed up.  There's some code to allow you
to quote the slash in the middle itself but it's not obvious to the user
how it's supposed to work and any way it doesn't in this case, it
swallows up the wrong number of backslashes.

Here's some alternative code and a test.

Index: Src/subst.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/subst.c,v
retrieving revision 1.31
diff -u -r1.31 subst.c
--- Src/subst.c	6 May 2002 14:46:11 -0000	1.31
+++ Src/subst.c	7 May 2003 09:23:06 -0000
@@ -1437,15 +1437,20 @@
 	     * If there isn't one, we're just going to delete that,
 	     * i.e. replace it with an empty string.
 	     *
-	     * This allows quotation of the slash with '\\/'. Why
-	     * two?  Well, for a non-quoted string we can check for
-	     * Bnull+/, which is what you get from `\/', but inside
-	     * double quotes the Bnull isn't there, so it's not
-	     * consistent.
+	     * We used to use double backslashes to quote slashes,
+	     * but actually that was buggy and using a single backslash
+	     * is easier and more obvious.
 	     */
 	    for (ptr = s; (c = *ptr) && c != '/'; ptr++)
-		if (c == '\\' && ptr[1] == '/')
-		    chuck(ptr);
+	    {
+		if ((c == Bnull || c == '\\') && ptr[1])
+		{
+		    if (ptr[1] == '/')
+			chuck(ptr);
+		    else
+			ptr++;
+		}
+	    }
 	    replstr = (*ptr && ptr[1]) ? ptr+1 : "";
 	    *ptr = '\0';
 	}
Index: Test/D04parameter.ztst
===================================================================
RCS file: /cvsroot/zsh/zsh/Test/D04parameter.ztst,v
retrieving revision 1.7
diff -u -r1.7 D04parameter.ztst
--- Test/D04parameter.ztst	1 Apr 2003 14:04:11 -0000	1.7
+++ Test/D04parameter.ztst	7 May 2003 09:23:06 -0000
@@ -146,6 +146,18 @@
 0:array ${...:/...}
 >expletive deleted boldly claws dogs expletive deleted fight
 
+  str1='a\string\with\backslashes'
+  str2='a/string/with/slashes'
+  print "${str1//\\/-}"
+  print ${str1//\\/-}
+  print "${str2//\//-}"
+  print ${str2//\//-}
+0:use of backslashes in //-substitutions
+>a-string-with-backslashes
+>a-string-with-backslashes
+>a-string-with-slashes
+>a-string-with-slashes
+
   str1='twocubed'
   array=(the number of protons in an oxygen nucleus)
   print $#str1 ${#str1} "$#str1 ${#str1}" $#array ${#array} "$#array ${#array}"


**********************************************************************
The information transmitted is intended only for the person or
entity to which it is addressed and may contain confidential 
and/or privileged material. 
Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by 
persons or entities other than the intended recipient is 
prohibited.  
If you received this in error, please contact the sender and 
delete the material from any computer.
**********************************************************************



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