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

Re: Call a function when idle?



On Mon, Dec 14, 2020 at 6:57 AM Mikael Magnusson <mikachu@xxxxxxxxx> wrote:
>
> On 12/14/20, A. Wik <awik32@xxxxxxxxx> wrote:
> >
> > So, the question is how to set up an idle timer to call the function.
> > I figured someone had already done something like that before (perhaps
> > to log out automatically).
>
> You may want to unset TMOUT in your handler and then arrange for it to
> be set when you enter a new command line and/or any relevant
> information has changed, otherwise you will come back to a lot of the
> same information.

I've been using the following for years to maintain the title bars in
my xterm-compatible shell windows:

typeset top=$'\C-[]0;'
typeset back=$'\C-G'
title () {
    setopt localoptions promptpercent
    print -nP "%{$top${*:-%m.%l:%2c - %t}$back%}"
}
TRAPALRM () {
    TMOUT=60
    title
}
precmd () {
    TMOUT=600
    title
}

This updates the title bar on every prompt, and then after 10 minutes
of idle time it updates it again every minute.




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