* Completion Control (Novice qn)
@ 1996-10-09 18:02 Varadarajan
1996-10-10 8:02 ` Peter Stephenson
0 siblings, 1 reply; 2+ messages in thread
From: Varadarajan @ 1996-10-09 18:02 UTC (permalink / raw)
To: zsh-users
Hi all,
I need some help with completions. Basically what I want is
this. If I want to talk to a person on local network, I want talk to
complete the machine name.
Typically this is what I want.
talk person@`rwho | grep person | cut -d: -f1 | awk '{print $2}' |
head -1`
And this stuff is what I want zsh to complete. So I know that a
function has to be written, but I dont have a good idea as to how to
do this. A naive try that I did was
local from
read -Ac from
from="${from[1]}"
reply=( `rwho | grep $from | cut -d: -f1 | awk '{print $2}' | head -1` )
return
and it did not work. I would like to know what is the solution, and if
there is any ways of debugging such things.. (Like how to know the
value of variables being used).
Thanks a lot,
Regards,
--
------------------------------------------------------------------------
Varadarajan.T.S. E-Mail : tsv@cs.umanitoba.ca
#725, 77, University Crescent, HTTP : http://www.cs.umanitoba.ca/~tsv
Winnipeg, Tel No : 1-(204)269-6036(Residence)
Manitoba - MB R3T 3N8 1-(204)474-8827(Office)
Canada.
------------------------------------------------------------------------
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Completion Control (Novice qn)
1996-10-09 18:02 Completion Control (Novice qn) Varadarajan
@ 1996-10-10 8:02 ` Peter Stephenson
0 siblings, 0 replies; 2+ messages in thread
From: Peter Stephenson @ 1996-10-10 8:02 UTC (permalink / raw)
To: tsv, Zsh users list
Varadarajan wrote:
>
> Hi all,
> I need some help with completions. Basically what I want is
> this. If I want to talk to a person on local network, I want talk to
> complete the machine name.
> Typically this is what I want.
> talk person@`rwho | grep person | cut -d: -f1 | awk '{print $2}' |
> head -1`
The following seems to work. Note you want the second word in the
array: the first is the command. Also, you don't need the `head': zsh
will simply make the results into different possible completions. The
upshot of the compctl command is that you need to type the @ sign
yourself before it is recognised as a candidate for this behaviour.
This allows you to complete users as well if there is no @ (the -u).
talkcomp () {
local line from
read -Ac line
from="${line[2]}"
from=${from%%@*}
reply=( `rwho | grep $from | cut -d: -f1 | awk '{print $2}'` )
# with perl
# reply=( `rwho | perl -ane '/^(\S+)\s*(\S+):/ && ($1 eq '$from')
# && print "$2\n";` )
}
compctl -u -x 'n[1,@]' -K talkcomp -- talk
(Note that with perl you can get away with two processes instead of
four; maybe you can do it in awk too.)
> I would like to know what is the solution, and if
> there is any ways of debugging such things.. (Like how to know the
> value of variables being used).
Miss out the `local' and you can check the values afterwards. You can
put `set -x' inside the function, although that makes the display
harder to see.
--
Peter Stephenson <pws@ifh.de> Tel: +49 33762 77366
WWW: http://www.ifh.de/~pws/ Fax: +49 33762 77413
Deutches Electronen-Synchrotron --- Institut fuer Hochenergiephysik Zeuthen
DESY-IfH, 15735 Zeuthen, Germany.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~1996-10-10 8:14 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-10-09 18:02 Completion Control (Novice qn) Varadarajan
1996-10-10 8:02 ` 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).