* How to do completion with read?
@ 1999-11-03 16:52 Paul Lew
1999-11-03 17:10 ` Francis GALIEGUE
1999-11-03 17:18 ` Bart Schaefer
0 siblings, 2 replies; 5+ messages in thread
From: Paul Lew @ 1999-11-03 16:52 UTC (permalink / raw)
To: zsh-users
Is there a way to use completion mechanism when prompt user for input
in zsh function/scripts? For example,
echo -n "Enter choice: "
read -C '-k "(orange apple banana)"' choice
The example about use imaginary option '-C' which tell zsh to pass the
next argument as compctl argument.
Any help will be appreciated...
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: How to do completion with read?
1999-11-03 16:52 How to do completion with read? Paul Lew
@ 1999-11-03 17:10 ` Francis GALIEGUE
1999-11-03 17:18 ` Bart Schaefer
1 sibling, 0 replies; 5+ messages in thread
From: Francis GALIEGUE @ 1999-11-03 17:10 UTC (permalink / raw)
To: zsh-users
Paul Lew <paullew@cisco.com> writes:
> Is there a way to use completion mechanism when prompt user for input
> in zsh function/scripts? For example,
>
> echo -n "Enter choice: "
> read -C '-k "(orange apple banana)"' choice
>
> The example about use imaginary option '-C' which tell zsh to pass the
> next argument as compctl argument.
>
> Any help will be appreciated...
>
You can use select for this, although it does not do completion.
--
fg
# rm *;o
o: command not found
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: How to do completion with read?
1999-11-03 16:52 How to do completion with read? Paul Lew
1999-11-03 17:10 ` Francis GALIEGUE
@ 1999-11-03 17:18 ` Bart Schaefer
1999-11-03 18:20 ` Paul Lew
1 sibling, 1 reply; 5+ messages in thread
From: Bart Schaefer @ 1999-11-03 17:18 UTC (permalink / raw)
To: Paul Lew, zsh-users
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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: How to do completion with read?
1999-11-03 17:18 ` Bart Schaefer
@ 1999-11-03 18:20 ` Paul Lew
0 siblings, 0 replies; 5+ messages in thread
From: Paul Lew @ 1999-11-03 18:20 UTC (permalink / raw)
To: Bart Schaefer; +Cc: zsh-users
>>>>> "Bart" == Bart Schaefer <schaefer@candle.brasslantern.com> writes:
Bart> Here's my "zleread" function again. Insert some commands to
Bart> fiddle with the completion context just before the call to
Bart> "vared" and you can get it to complete any way you like.
Thanks for the script. I'm guessing what you mean by fiddle with the
completion context is to create a temporary directory and create dummy
files for completion purpose? So there is no mechanism to pass
zcompctl arguments to vared? Seems vared only complete filename?
-- Paul 11/03/99 10:18 AM --
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: How to do completion with read?
@ 1999-11-04 8:21 Sven Wischnowsky
0 siblings, 0 replies; 5+ messages in thread
From: Sven Wischnowsky @ 1999-11-04 8:21 UTC (permalink / raw)
To: zsh-users
Paul Lew wrote:
> >>>>> "Bart" == Bart Schaefer <schaefer@candle.brasslantern.com> writes:
>
> Bart> Here's my "zleread" function again. Insert some commands to
> Bart> fiddle with the completion context just before the call to
> Bart> "vared" and you can get it to complete any way you like.
>
> Thanks for the script. I'm guessing what you mean by fiddle with the
> completion context is to create a temporary directory and create dummy
> files for completion purpose? So there is no mechanism to pass
> zcompctl arguments to vared? Seems vared only complete filename?
Actually, `vared' completes its line in the same way a command line is
completed. I.e. it uses all the `compctl' definitions you have
(including the one for `-C' for the first word on the line).
What Bart probably meant was that with the new completion system in
version 3.1.6 you can set the parameter `compcontext' in such a
function to specify how words in the line read should be completed.
Since you seem to use an older version: if your version already
supports the `-T' flag to `compctl' (which is quite old), you can use
that to say what should be completed in such a function, e.g.:
compctl -Tk '(foo bar baz)'
vared line
compctl -T ... # reset to standard value
Resetting it should be possible by first storing the output of
`compctl -LT' and later `eval'ing it (be careful if that contains
quotes).
If you are using a 3.1.6, you'll have to add a `-tn' to the first
`compctl -T'. But then... if you are using 3.1.6, you probably should
think about moving to the function based completion system anyway.
Bye
Sven
--
Sven Wischnowsky wischnow@informatik.hu-berlin.de
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~1999-11-04 9:34 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-11-03 16:52 How to do completion with read? Paul Lew
1999-11-03 17:10 ` Francis GALIEGUE
1999-11-03 17:18 ` Bart Schaefer
1999-11-03 18:20 ` Paul Lew
1999-11-04 8:21 Sven Wischnowsky
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).