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

Re: Bug in umount completion

On Fri, 18 Jan 2008 23:00:32 +0100
"Richard Hartmann" <richih.mailinglist@xxxxxxxxx> wrote:
> zsh 4.3.4 fails to fully escape mounted directories.
Yes, I suspect there are a lot of places where you don't usually
get special characters in names for which completions aren't quoted

> As an aside, the whitespace is completed as \040 which is also strange.

This is a low-level feature of Linux so that when the "mount" arguments
are split the space doesn't confuse matters.  I've fixed this so that it
handles octal escapes generally; this may well be overkill and it would
have been much simpler and quite possibly good enough just to replace
\040.  I don't know how far the \OOO trick has spread, and I've assumed
it's more useful to handle that everywhere and run the small risk of
real filenames of that form than limit the fix to Linux.

I've added the quoting to devices as well as mount points; it's unlikely
to be needed, but it's at least harmless.  I haven't tried applying the
octal escape hackery to devices.

As you'll see, I've add a simplified explanation of how I fixed the
octal escapes.

Index: Completion/Unix/Command/_mount
RCS file: /cvsroot/zsh/zsh/Completion/Unix/Command/_mount,v
retrieving revision 1.26
diff -u -r1.26 _mount
--- Completion/Unix/Command/_mount	28 Nov 2007 17:28:57 -0000	1.26
+++ Completion/Unix/Command/_mount	19 Jan 2008 19:23:23 -0000
@@ -867,8 +867,27 @@
-  dpath_tmp=( "${(@M)dev_tmp:#/*}" )
-  dev_tmp=( "${(@)dev_tmp:#/*}" )
+  # "Mummy, why is mount point matching full of squiggles?"
+  #
+  # "Well, dear, the clever people who wrote Linux decided that some
+  # funny characters that might confuse programmes looking at the names
+  # would be encoded as octal escapes, like for example \040 for space.
+  # The clever people who wrote zsh decided that nothing would
+  # ever be quite as simple as it should be, so to substitute octal
+  # escapes everywhere in a string, even though the shell understands
+  # them natively in print escapes, needs some hackery where you match
+  # the octal number using the numeric closure syntax introduced after
+  # 4.3.4, then reinput the number in a standard math mode format as 8#OOO,
+  # and turn that into a character using the (#) parameter flag."
+  #
+  # "Mummy, why is nothing ever quite as simple as it should be?"
+  #
+  # "Well, dear, if it was then the clever people who write programmes would
+  # have been replaced by intelligent monkeys and then they'd be out
+  # of working roaming the streets, and we wouldn't want that, would we?"
+  mp_tmp=("${(@q)mp_tmp//(#m)\\[0-7](#c3)/${(#)$(( 8#${MATCH[2,-1]} ))}}")
+  dpath_tmp=( "${(@Mq)dev_tmp:#/*}" )
+  dev_tmp=( "${(@q)dev_tmp:#/*}" )
   _alternative \
     'device-labels:device label:compadd -a dev_tmp' \

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