* read timeout argument || completion of a function
@ 2002-08-11 20:54 Bruno Bonfils
2002-08-12 5:45 ` Bart Schaefer
0 siblings, 1 reply; 7+ messages in thread
From: Bruno Bonfils @ 2002-08-11 20:54 UTC (permalink / raw)
To: zsh-workers
Hi all,
i'm very surprised to observe there isn't timeout argument for read
builtin function. I've looked for this problem in mailing list
archives and just found one mail who say to use expect. Don't sure
it's the solution for just ask yes/no (with -q argument)
Do you think add this features ? Maybe i can try to look for myself in
the source, but i'm afraid it's too difficult for me.
Moreover, i'm looking the way for provide completion for a function :
for example :
myping () {
ping $1
}
First of all, i want to be sure i _can't_ define the default
completion tag with zstyle for a command which don't have
_command completion function (default tag called is _files isn't it
?).
I have also try to write a just little function _myping which contains
#compdef myping
_arguments '*:hostname:_hosts'
but myping <tab> provide file completion, and _myping <tab> hosts
completion.
Thank you very much.
--
Bruno Bonfils
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: read timeout argument || completion of a function
2002-08-11 20:54 read timeout argument || completion of a function Bruno Bonfils
@ 2002-08-12 5:45 ` Bart Schaefer
2002-08-12 10:43 ` Bruno Bonfils
0 siblings, 1 reply; 7+ messages in thread
From: Bart Schaefer @ 2002-08-12 5:45 UTC (permalink / raw)
To: Bruno Bonfils, zsh-workers
On Aug 11, 10:54pm, Bruno Bonfils wrote:
}
} i'm very surprised to observe there isn't timeout argument for read
} builtin function.
There are certain aspects of the arms race in which ksh is currently
ahead. I suppose when it gets a builtin to launch satellites we'll have
to start working on moon landers.
Meanwhile, if you install 4.1.0-dev-5 you can use the zselect builtin.
} Moreover, i'm looking the way for provide completion for a function :
This has nothing to do with wanting read to time out, right?
} First of all, i want to be sure i _can't_ define the default
} completion tag with zstyle for a command which don't have
} _command completion function (default tag called is _files isn't it
} ?).
You seem to be a bit confused about what's a tag and what's a completion
function. The default completion is what is called when there isn't any
other completion defined, and it is implemented by a function that is
named _default, which happens to call another function named _files.
The _files function looks for zstyles using several different tags; the
most general of these is "all-files", which is effectively the default
tag used for completion in the absence of any other configuration.
} I have also try to write a just little function _myping which contains
}
} #compdef myping
}
} _arguments '*:hostname:_hosts'
}
} but myping <tab> provide file completion, and _myping <tab> hosts
} completion.
One doesn't normally type the name of a completion function on the command
line; it's meant to be called only by the completion system (that's why it
has a leading underscore in the name). If `_myping <TAB>' gives host
completion, you've somehow gotten _myping set up to complete for itself,
or some such. Are you certain that the _myping file has `#compdef myping'
and not `#compdef _myping'?
You could get rid of your _myping function and instead use the command
`compdef myping=ping' which says to complete for myping the same way as
for ping ...
--
Bart Schaefer Brass Lantern Enterprises
http://www.well.com/user/barts http://www.brasslantern.com
Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: read timeout argument || completion of a function
2002-08-12 5:45 ` Bart Schaefer
@ 2002-08-12 10:43 ` Bruno Bonfils
2002-08-12 11:13 ` Oliver Kiddle
2002-08-12 15:21 ` Bart Schaefer
0 siblings, 2 replies; 7+ messages in thread
From: Bruno Bonfils @ 2002-08-12 10:43 UTC (permalink / raw)
To: Bart Schaefer; +Cc: zsh-workers
"Bart Schaefer" <schaefer@brasslantern.com> writes:
> On Aug 11, 10:54pm, Bruno Bonfils wrote:
> }
> } i'm very surprised to observe there isn't timeout argument for
> } read builtin function.
>
> There are certain aspects of the arms race in which ksh is currently
> ahead. I suppose when it gets a builtin to launch satellites we'll
> have to start working on moon landers.
>
I'm don't sure to understanding you at all. (maybe my sentence is
meaningless ?)
So, do you think it's difficult to add this argument to read builtin
function ?
> Meanwhile, if you install 4.1.0-dev-5 you can use the zselect
> builtin.
Ok, i note that
>
> } Moreover, i'm looking the way for provide completion for a
> } function :
>
> This has nothing to do with wanting read to time out, right?
sure..
>
> } First of all, i want to be sure i _can't_ define the default
> } completion tag with zstyle for a command which don't have _command
> } completion function (default tag called is _files isn't it ?).
>
> You seem to be a bit confused about what's a tag and what's a
hmm, i think i understand differences between tag completion and
command completion
> completion function. The default completion is what is called when
> there isn't any other completion defined, and it is implemented by a
> function that is named _default, which happens to call another
> function named _files.
hmm ok, i understand now. So, in this case, it's possible to change
the function which called by _default for only one command using
zstyle ?
i'm very sorry to ask and ask again about style, but i want to
understand all.
>
> One doesn't normally type the name of a completion function on the
> command line; it's meant to be called only by the completion system
> (that's why it has a leading underscore in the name). If `_myping
> <TAB>' gives host completion, you've somehow gotten _myping set up
> to complete for itself, or some such. Are you certain that the
> _myping file has `#compdef myping' and not `#compdef _myping'?
sure, in fact i have :
% vi .zshrc
...
source .zsh/rc/functions.rc
fpath=($HOME/.zsh/functions $fpath)
...
% vi .zsh/rc/functions.rc
...
upgrade () {
if [ -z $1 ] ; then
sudo apt-get update
sudo apt-get -u upgrade
else
echo "sudo apt-get update" | ssh $1
# ask before the upgrade
local dummy
echo "sudo apt-get --no-act upgrade" | ssh $1
echo -n "Process the upgrade ?"
read -q dummy
if [[ $dummy == "y" ]] ; then
echo "sudo apt-get -u upgrade --yes"
fi
fi
}
...
% vi .zsh/functions/_upgrade
#compdef upgrade
_arguments '*:hostname:_hosts'
% zcompile _upgrade
source .zshrc
upgrade <tab>
file..
_upgrade <tab>
host..
Thank you very much for your help, and sorry for the disturb.
(btw sorry for the post to zsh-workers instead of users)
--
Bruno Bonfils
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: read timeout argument || completion of a function
2002-08-12 10:43 ` Bruno Bonfils
@ 2002-08-12 11:13 ` Oliver Kiddle
2002-08-12 11:41 ` Peter Stephenson
2002-08-12 15:21 ` Bart Schaefer
1 sibling, 1 reply; 7+ messages in thread
From: Oliver Kiddle @ 2002-08-12 11:13 UTC (permalink / raw)
To: Bruno Bonfils; +Cc: zsh-workers
On Mon, Aug 12, 2002 at 12:43:08PM +0200, Bruno Bonfils wrote:
>
> > On Aug 11, 10:54pm, Bruno Bonfils wrote:
> > }
> > } i'm very surprised to observe there isn't timeout argument for
> > } read builtin function.
> >
> > There are certain aspects of the arms race in which ksh is currently
> > ahead. I suppose when it gets a builtin to launch satellites we'll
> > have to start working on moon landers.
> >
> I'm don't sure to understanding you at all. (maybe my sentence is
> meaningless ?)
Your sentence is fine. There are just a few features in ksh that are
lacking in zsh and the timeout to read is one of them.
> So, do you think it's difficult to add this argument to read builtin
> function ?
That is probably for Peter to say. It has been mentioned before and I'd
guess it is doable because zselect does roughly the same. It would
also need some nasty special casing for the argument parsing if we
maintain compatibility with both older zsh and ksh so that may have been
a factor in it not being implemented as yet. In the meantime, Bart's
suggestion of using zselect should provide what you need.
> > completion function. The default completion is what is called when
> > there isn't any other completion defined, and it is implemented by a
> > function that is named _default, which happens to call another
> > function named _files.
>
> hmm ok, i understand now. So, in this case, it's possible to change
> the function which called by _default for only one command using
> zstyle ?
Not with zstyle. You use compdef to define which function is called.
> sure, in fact i have :
>
> % vi .zsh/functions/_upgrade
>
> #compdef upgrade
>
> _arguments '*:hostname:_hosts'
>
> % zcompile _upgrade
>
You could do that all more easily by just adding the line:
compdef _hosts upgrade
to your .zshrc.
Oliver
This e-mail and any attachment is for authorised use by the intended recipient(s) only. It may contain proprietary material, confidential information and/or be subject to legal privilege. It should not be copied, disclosed to, retained or used by, any other party. If you are not an intended recipient then please promptly delete this e-mail and any attachment and all copies and inform the sender. Thank you.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: read timeout argument || completion of a function
2002-08-12 11:13 ` Oliver Kiddle
@ 2002-08-12 11:41 ` Peter Stephenson
2002-08-12 15:12 ` Bart Schaefer
0 siblings, 1 reply; 7+ messages in thread
From: Peter Stephenson @ 2002-08-12 11:41 UTC (permalink / raw)
To: zsh-workers
Oliver Kiddle wrote:
> On Mon, Aug 12, 2002 at 12:43:08PM +0200, Bruno Bonfils wrote:
> > > On Aug 11, 10:54pm, Bruno Bonfils wrote:
> > > } i'm very surprised to observe there isn't timeout argument for
> > > } read builtin function.
>
> > So, do you think it's difficult to add this argument to read builtin
> > function ?
>
> That is probably for Peter to say.
Two issues:
(1) Getting keyboard polling to work on both UNIX and Cygwin was a
nightmare, so the code is quite complicated. This makes adding timeouts
in the case where the input is a tty more difficult, though still
entirely feasible. (Even on Solaris I have problems with both select()
and poll() that they won't tell you about lookahead when the tty goes
from canonical to raw mode, so it will have to be done via termio
timeouts in this case, while for non-tty input you are stuck with
select/poll, which probably means bringing in the core of zsh/zselect
and leaving only the builtin itself in the module. In addition, I am
more and more missing a direct interface to system read.)
(2) We took -t for this (test) and we really need to make -t with a
number work for timeouts for compatibility with everyone else. You
don't normally give a numeric parameter to read (though in fact it works),
so this ought to be possible. However, adding optional numeric
arguments will have to wait for the current horrific handling of option
arguments (dating from year zero and looking like it) to be tidied up.
(It's not just horrific internally in some cases: I've a vague memory
there are places which only accept `-X<arg>' and other places which only
accept `-X <arg>'. It's no surprise that many modules handle option
arguments using their own code.)
I have been waiting hopefully for other people to attempt these tasks,
but I will obviously be waiting till doomsday. (2) will have to come
first (reverse zsh logic).
--
Peter Stephenson <pws@csr.com> Software Engineer
CSR Ltd., Science Park, Milton Road,
Cambridge, CB4 0WH, UK Tel: +44 (0)1223 692070
**********************************************************************
The information transmitted is intended only for the person or
entity to which it is addressed and may contain confidential
and/or privileged material.
Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by
persons or entities other than the intended recipient is
prohibited.
If you received this in error, please contact the sender and
delete the material from any computer.
**********************************************************************
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: read timeout argument || completion of a function
2002-08-12 11:41 ` Peter Stephenson
@ 2002-08-12 15:12 ` Bart Schaefer
0 siblings, 0 replies; 7+ messages in thread
From: Bart Schaefer @ 2002-08-12 15:12 UTC (permalink / raw)
To: zsh-workers
On Aug 12, 12:43pm, Bruno Bonfils wrote:
}
} "Bart Schaefer" <schaefer@brasslantern.com> writes:
}
} > There are certain aspects of the arms race in which ksh is currently
} > ahead. I suppose when it gets a builtin to launch satellites we'll
} > have to start working on moon landers.
}
} I'm don't sure to understanding you at all. (maybe my sentence is
} meaningless ?)
I'm making a silly joke that compares features in ksh and zsh to the 1950's
space race between the USSR and the USA.
On Aug 12, 12:41pm, Peter Stephenson wrote:
}
} Two issues:
}
} (1) Getting keyboard polling to work on both UNIX and Cygwin was a
} nightmare, so the code is quite complicated.
}
} (2) We took -t for this (test) and we really need to make -t with a
} number work for timeouts for compatibility with everyone else. You
} don't normally give a numeric parameter to read (though in fact it works),
} so this ought to be possible. However, adding optional numeric
} arguments will have to wait for the current horrific handling of option
} arguments (dating from year zero and looking like it) to be tidied up.
Peter already knows this, but to elaborate:
Optional arguments of any sort are a bit messy in the zsh command flag
parsing scheme, mainly because it doesn't keep track of the order in
which the flags appear. E.g. given "read -t 3 -k 5" the parser rewrites
it into the equivalent of "read -kt 3 5" before calling the builtin.
So you can trick it into handling one flag with an optional argument,
but not two or more such flags at once.
} (It's not just horrific internally in some cases: I've a vague memory
} there are places which only accept `-X<arg>' and other places which only
} accept `-X <arg>'. It's no surprise that many modules handle option
} arguments using their own code.)
The vague memory is of the `read' builtin itself, -uN and -k N.
BTW, there's this mystifying bit of code in bin_read():
if ((ops['k'] || ops['b']) && *args && idigit(**args)) {
What the heck is ops['b'] ? As far as I can tell there's no way for
bin_read() to ever get called with a 'b' flag, and the flag is never
mentioned anywhere else. This 'b' code appears in my personal CVS
repository on 1997/06/27 as part of 3.0.3, but I can't find any
corresponding change to hashtable.c (where the `struct builtin' for
all builtins were defined at that time).
--
Bart Schaefer Brass Lantern Enterprises
http://www.well.com/user/barts http://www.brasslantern.com
Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: read timeout argument || completion of a function
2002-08-12 10:43 ` Bruno Bonfils
2002-08-12 11:13 ` Oliver Kiddle
@ 2002-08-12 15:21 ` Bart Schaefer
1 sibling, 0 replies; 7+ messages in thread
From: Bart Schaefer @ 2002-08-12 15:21 UTC (permalink / raw)
To: Bruno Bonfils; +Cc: zsh-workers
On Aug 12, 12:43pm, Bruno Bonfils wrote:
}
} > The default completion is what is called when
} > there isn't any other completion defined, and it is implemented by a
} > function that is named _default, which happens to call another
} > function named _files.
}
} hmm ok, i understand now. So, in this case, it's possible to change
} the function which called by _default for only one command using
} zstyle ?
No, you cannot, using zstyle, change the functions which are called;
with zstyle you can change some of the function behaviors and in some
cases change the set of possible matches from which they select the list
of matching completions. To change the functions called, use compdef.
} sure, in fact i have :
}
} % vi .zshrc
} ...
} source .zsh/rc/functions.rc
}
} fpath=($HOME/.zsh/functions $fpath)
} ...
And where in that sequence is your call to "compinit"?
} % vi .zsh/rc/functions.rc
}
} ...
} upgrade () {
} if [ -z $1 ] ; then
} sudo apt-get update
} sudo apt-get -u upgrade
} else
} echo "sudo apt-get update" | ssh $1
} # ask before the upgrade
} local dummy
} echo "sudo apt-get --no-act upgrade" | ssh $1
} echo -n "Process the upgrade ?"
} read -q dummy
} if [[ $dummy == "y" ]] ; then
} echo "sudo apt-get -u upgrade --yes"
} fi
} fi
} }
It looks like that always passes its argument to ssh. So you can just:
compdef upgrade=ssh
} upgrade <tab>
} file..
}
} _upgrade <tab>
} host..
I'm at a loss to explain this. Have you tried using the _complete_help
and _complete_debug key bindings? Man page excerpt:
_complete_debug (^X?)
This widget performs ordinary completion, but captures in a
temporary file a trace of the shell commands executed by the
completion system. Each completion attempt gets its own file. A
command to view each of these files is pushed onto the editor
buffer stack.
_complete_help (^Xh)
This widget displays information about the context names, the
tags, and the completion functions used when completing at the
current cursor position. If given a numeric argument other than 1
(as in `ESC-2 ^Xh'), then the styles used and the contexts for
which they are used will be shown, too.
Note that the information about styles may be incomplete; it
depends on the information available from the completion functions
called, which in turn is determined by the user's own styles and
other settings.
--
Bart Schaefer Brass Lantern Enterprises
http://www.well.com/user/barts http://www.brasslantern.com
Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2002-08-12 15:21 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-08-11 20:54 read timeout argument || completion of a function Bruno Bonfils
2002-08-12 5:45 ` Bart Schaefer
2002-08-12 10:43 ` Bruno Bonfils
2002-08-12 11:13 ` Oliver Kiddle
2002-08-12 11:41 ` Peter Stephenson
2002-08-12 15:12 ` Bart Schaefer
2002-08-12 15:21 ` Bart Schaefer
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).