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

vared/zle silently discards non-utf8 bytes



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



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