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

Re: completion & read, vared



On Jul 13,  1:10pm, Heinz Deinhart wrote:
} Subject: completion & read, vared
}
}  is there a way to use completion with any realine-like function ?

Not directly; "read" inputs characters one at a time, for some reason,
even when not in raw mode.

} vared uses completion, but i cant figure out how to change its behaviour.

Change its behavior how?

Try the following; it should work exactly like the "read" builtin, except
that when reading in the "ordinary" way from a terminal, it uses vared to
provide access to completion and history.

Note that this means you can't end the loop with an EOF character (ctrl-D)
because vared doesn't interpret EOFs (it attempts completion instead).  So
you have to end the loop with an interrupt (ctrl-C), which in turn means
it's not possible to interrupt any surrounding script or function when the
vared is in progress.  (There's probably some bindkey foolery that would
fix this up.)

The cryptic "${${(M)1%%\?*}#\?}" is peeling off the ?PROMPT part of the
first NAME?PROMPT parameter (see the zsh doc for the "read" builtin).

    function zleread {
      emulate zsh
      setopt localoptions
      local input opt ropt n=0
      ropt=()
      while getopts :AEe opt
      do
	case $opt in
	[?]) read $*; return $?;;
	*) ropt=($ropt -$opt); ((++n));
	esac
      done
      if [[ -t 0 ]]
      then
        shift $n
        vared -hp "${${(M)1%%\?*}#\?}" input
        print -r $input | read $ropt ${1%%\?*} $*[2,-1]
	return $?
      fi
      read $*
    }

I did notice one oddity while playing with this.  From the PS1 prompt,

	read -eu0k1

reads a line from the terminal and echoes back the first character.
However, if instead I redirect input to read like so:

	repeat 3 print x y z | read -eu0k1

then nothing is read.  I have to use

	repeat 3 print x y z | read -eu0k 1

to get the desired behavior.  Why does the source of the input affect
the option parsing?

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com



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