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

Re: autoexecuting command after a pause

On Dec 6,  4:50pm, Eric Smith wrote:
} Like why press <enter> all the time? Maybe I set up some
} (say) preexec() function for a certain shell to automatically
} accept any types string on the command line if there has been
} a pause of n milliseconds.
} This is not for normal use but ad hoc.
} Make sense?


By "there has been a pause of ..." you mean "something was typed at the
prompt, but then the typing stopped and it was left unchanged for ...".

What doesn't make sense to me is "not for normal use but ad hoc."  If it
isn't for normal use, what turns it on and off?  And if you have to turn
it on and off, how is that different from pressing enter?

Putting that aside --

The way one would normally do this sort of thing is by setting the TMOUT
parameter and installing a trap for the ALARM signal.  However, that has
only full second granularity, and you can't execute zle widgets from the
trap unless it triggers while you're already in a zle widget, which by
definition can't happen for TMOUT.  (The trap must use `zle accept-line'
to execute the contents of the editor buffer.)

So I think you'd need to get zsh 4.1.0-dev-6 and use `zle -F' to install
an alternate input handler, and then arrange (possibly by some external
process) to write a byte on the handled descriptor.  That wakes up zle
and executes the handler in the appropriate context for calling widgets.

I'm not interested enough to attempt to code it for you, but if you want
to take a stab at it I'll be happy to critique it.

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   

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