zsh-workers
 help / color / mirror / code / Atom feed
* Umount completion fails when mount point or dev node contains spaces
@ 2005-02-01  1:05 Philippe Troin
  2005-02-01 10:57 ` Stephane Chazelas
  0 siblings, 1 reply; 2+ messages in thread
From: Philippe Troin @ 2005-02-01  1:05 UTC (permalink / raw)
  To: zsh-workers

[-- Attachment #1: Type: text/plain, Size: 835 bytes --]

On Linux at least, non-straightforward characters are encoded with the
\NNN notation in /etc/mtab, with NNN being the octal ASCII code of the
character.

Our current umount completer does not handle it.

  # mkdir /mnt/mount\ point\[\\
  # mount --bind /tmp /mnt/mount\ point\[\\
  # umount /mnt/mount<TAB>

yields

  # umount /mnt/mount\\040point\[\\134

The enclosed patch takes care of the problem by unescaping octal
sequences.

Please note that I've assumed that all unices escape spaces and other
unprintable characters this way.  If it's not the case, then the
mp_tmp and dev_tmp assignments should be moved to the Linux branch of
the case.

Can anyone confirm other unices behavior?

Phil.

Changelog entry:

2005-01-31  Philippe Troin  <phil@fifi.org>

       * Completion/Unix/Command/_mount: Unescape mtab octal sequences.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: zsh-mount-completion.patch --]
[-- Type: text/x-patch, Size: 783 bytes --]

Index: Completion/Unix/Command/_mount
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Unix/Command/_mount,v
retrieving revision 1.18
diff -b -u -r1.18 _mount
--- Completion/Unix/Command/_mount	20 Feb 2004 10:57:11 -0000	1.18
+++ Completion/Unix/Command/_mount	1 Feb 2005 01:01:32 -0000
@@ -794,7 +794,7 @@
   esac
   ;;
 udevordir)
-  local dev_tmp mp_tmp mline
+  local dev_tmp mp_tmp mline match
 
   case "$OSTYPE" in
   linux*|irix*)
@@ -810,6 +810,9 @@
     ;;
   esac
 
+  mp_tmp=(${mp_tmp//(#b)(\\([0-7]##|\\))/$(print $match[1])})
+  dev_tmp=(${dev_tmp//(#b)(\\([0-7]##|\\))/$(print $match[1])})
+
   _alternative \
     'devices:device:compadd -a dev_tmp' \
     'directories:mount point:compadd -a mp_tmp' && ret=0

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

* Re: Umount completion fails when mount point or dev node contains spaces
  2005-02-01  1:05 Umount completion fails when mount point or dev node contains spaces Philippe Troin
@ 2005-02-01 10:57 ` Stephane Chazelas
  0 siblings, 0 replies; 2+ messages in thread
From: Stephane Chazelas @ 2005-02-01 10:57 UTC (permalink / raw)
  To: zsh-workers

On Mon, Jan 31, 2005 at 05:05:06PM -0800, Philippe Troin wrote:
[...]
>   # umount /mnt/mount\\040point\[\\134
> 
> The enclosed patch takes care of the problem by unescaping octal
> sequences.
> 
[...]
> +  dev_tmp=(${dev_tmp//(#b)(\\([0-7]##|\\))/$(print $match[1])})

Note that this would fail for foo\012bar

for ((i = 1; i <= $#dev_tmp; i++)); do
  eval "dev_tmp[i]=\$'${dev_tmp[i]}'"
done

should work and avoid the forks for $(print ...)

$ sudo mkdir '/mnt/f\n\1oo
quote> bar'
~$ sudo mount --bind /tmp $_
~$ tail -1 /etc/mtab
/tmp /mnt/f\134n\1341oo\012bar none rw,bind 0 0
~$ dev_tmp=('/mnt/f\134n\1341oo\012bar')
~$ print -rl -- ${dev_tmp//(#b)(\\([0-7]##|\\))/$(print $match[1])}
/mnt/f\n\1oobar

~$ dev_tmp=('/mnt/f\134n\1341oo\012bar')
~$ for ((i = 1; i <= $#dev_tmp; i++)); do
for>   eval "dev_tmp[i]=\$'${dev_tmp[i]}'"
for> done
~$ print -rl "${(@)dev_tmp}"
/mnt/f\n\1oo
bar

-- 
Stéphane


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

end of thread, other threads:[~2005-02-01 13:32 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-02-01  1:05 Umount completion fails when mount point or dev node contains spaces Philippe Troin
2005-02-01 10:57 ` Stephane Chazelas

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).