zsh-workers
 help / color / mirror / code / Atom feed
* vared/zle silently discards non-utf8 bytes
@ 2009-12-23 10:44 Mikael Magnusson
  2010-01-06 11:37 ` Peter Stephenson
  0 siblings, 1 reply; 3+ messages in thread
From: Mikael Magnusson @ 2009-12-23 10:44 UTC (permalink / raw)
  To: zsh workers

I have this function

function name() {
  [[ $#@ -eq 1 ]] || { echo Give exactly one argument ; return 1 }
  test -e "$1" || { echo No such file or directory: "$1" ; return 1 }
  local newname=$1
  if vared -c -p 'rename to: ' newname &&
    [[ -n $newname && $newname != $1 ]]
  then
    command mv -i -- $1 $newname
  else
    echo Some error occured; return 1
  fi
}

which I use to rename files interactively if they just need small
adjustments. It would also be useful for files in wrong encodings
where there's a ü here or there. Unfortunately it seems vared discards
anything after an invalid byte. To reproduce, just do

% a=hi$'\374'nothing
% vared a

It actually seems main zle does this too (I thought it would do the
<0374> thing, but then realized those are unicode code points so that
wouldn't work), but it's much harder to hit since completion inserts
the $'\374' sequence for you and there's really no simple way to
insert the string. If you start a terminal in latin1 and run a command
with some upper byte, then press up-arrow in a utf8 terminal,
everything after that byte is silently discarded too. I care less
about this case personally.

-- 
Mikael Magnusson


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

end of thread, other threads:[~2010-01-06 11:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-12-23 10:44 vared/zle silently discards non-utf8 bytes Mikael Magnusson
2010-01-06 11:37 ` Peter Stephenson
2010-01-06 11:42   ` Peter Stephenson

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