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

Re: How to do completion with read?



On Nov 3,  8:52am, Paul Lew wrote:
} Subject: How to do completion with read?
}
} Is there a way to use completion mechanism when prompt user for input
} in zsh function/scripts?

Here's my "zleread" function again.  Insert some commands to fiddle with
the completion context just before the call to "vared" and you can get it
to complete any way you like.

--- 8< --- cut here --- 8< ---
emulate -L zsh
local input opt ropt n=0
ropt=()
while getopts :AEe opt
do
    case $opt in
    [?]) read $*; return $?;;
    +*) break;;
    *) 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 $*
--- 8< --- cut here --- 8< ---

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



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