zsh-users
 help / color / mirror / code / Atom feed
From: "Bart Schaefer" <schaefer@brasslantern.com>
To: zsh-users@sunsite.auc.dk
Subject: Re: Idle function?
Date: Sun, 28 Mar 1999 23:16:26 -0800	[thread overview]
Message-ID: <990328231626.ZM9717@candle.brasslantern.com> (raw)
In-Reply-To: <19990329133756.A505@tertius.net.au>

On Mar 29,  1:37pm, Bek Oberin wrote:
} Subject: Idle function?
}
} Is it possible for a console to auto-execute a command

What is "a console"?

} when it has been idle for x number of minutes?

Like Sweth, I remember you asking a similar question some while ago.
It was the reverse last time, though, wasn't it?  How to do something
when the tty had NOT been idle for some length of time?

Zsh has the $TTYIDLE variable and $TMOUT ... I personally have this in
my init files:

 # Update title bar periodically if it has been idle a long time (10 min).
 # Otherwise let precmd() do it, so we don't cause unwanted scroll-to-bot.
 precmd() { TMOUT=600 ; title }
 TRAPALRM() { TMOUT=60 ; title }

The `title` function puts the current time and current directory on the
screen somewhere -- in the status bar if the terminal has one, or in the
title bar of an xterm (whence the name), or wherever.  Normally this is
updated every time a prompt is printed, in precmd(), which is often more
than once a minute.

If I'm away from my terminal for 10 minutes, however, TMOUT kicks in and
the title starts updating every 60 seconds from TRAPALRM.  As soon as I
get back and start running commands again, the delay goes back to 10
minutes.

You'll probably find almost exactly that description in the archives a
few previous times, if you look.

If you want something that works even when a command (say, an editor) is
in the foreground, then you have to do something like background a loop
that alternately sleeps for a while and checks $TTYIDLE.  Unfortunately,
you can't do this with a subshell because TTYIDLE is always -1 in a job
backgrounded that way; so something like:

   zsh -fc "sleep 10; ((TTYIDLE > x * 60)) && echo Do Something 1>&2"

That still doesn't get the "topmost" zsh (assuming that's what you mean
by "a console") to do anything; it makes itself pretty unreachable when
a child process is in the foreground.  So you might be just as well off
with the TMOUT hack.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com


      parent reply	other threads:[~1999-03-29  7:17 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-03-29  3:37 Bek Oberin
1999-03-29  4:23 ` Sweth Chandramouli
1999-03-29  7:16 ` Bart Schaefer [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=990328231626.ZM9717@candle.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=zsh-users@sunsite.auc.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).