Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Call a function when idle?
- X-seq: zsh-users 26225
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: "A. Wik" <awik32@xxxxxxxxx>
- Subject: Re: Call a function when idle?
- Date: Mon, 14 Dec 2020 15:57:30 +0100
- Archived-at: <https://zsh.org/users/26225>
- Archived-at: <http://www.zsh.org/sympa/arcsearch_id/zsh-users/2020-12/CAHYJk3QNN7yGZspvXyNhn3WVhss-xYZ9dW-kSY1QnLT9ED3gaw%40mail.gmail.com>
- Authentication-results: zsh.org; iprev=pass (mail-io1-f54.google.com) smtp.remote-ip=209.85.166.54; dkim=pass header.d=gmail.com header.s=20161025 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none
- Cc: zsh-users@xxxxxxx
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=vF9Ofoar6/D/IET57Gv13cFVTYutKnEjb6+g+CEd9nE=; b=KAfKOSoNY9X4jItqsXN2EgumhEk2MQU16aNknk6c4rYGhHjDDfJYEwJlKM3hbegHND nCAWj2RndTMS4zxkh5j/n2hsG1E+OFqv2jmIMRcaF9Ool3EPM3wXfmX73HqQr5488Tp5 xVMoQX/hekYVSAcRlEHDdpqRgS+aBQvJlwB2y1iie1mdfuRxYZIgtmC7LjMqMtBsvUY3 uaX4L/wTztORGp9CUMlCQ39N5L3Ts/okp7qy2vOKu9VcxmMjqh2QcE9ZJTmscyhxKt/m m50sW5Q9XlLzrGHjwJasNiirdyMwz+GUIAEQiiYNwoWF2dBfw6KCR+AjTe23x28lzxZk W4OA==
- In-reply-to: <CALPW7mQjh9-5USvtdcmW=Z=bSFT7qmXN8bM0VXhrJtYzSzJ-ag@mail.gmail.com>
- List-archive: <http://www.zsh.org/sympa/arc/zsh-users>
- List-help: <mailto:sympa@zsh.org?subject=help>
- List-id: <zsh-users.zsh.org>
- List-owner: <mailto:zsh-users-request@zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- List-subscribe: <mailto:sympa@zsh.org?subject=subscribe%20zsh-users>
- List-unsubscribe: <mailto:sympa@zsh.org?subject=unsubscribe%20zsh-users>
- References: <CALPW7mQjh9-5USvtdcmW=Z=bSFT7qmXN8bM0VXhrJtYzSzJ-ag@mail.gmail.com>
- Sender: zsh-users-request@xxxxxxx
On 12/14/20, A. Wik <awik32@xxxxxxxxx> wrote:
> Hi all,
>
> For the most part, when I get started working at a terminal, I can do
> just fine with a simple and short prompt like "% ". A prompt that
> includes the current directory often gets annoyingly long so that you
> can rarely type a command line that doesn't scroll onto another line,
> which is harder to read.
>
> However, when I've been away from a terminal (window or tab) for some
> time, I would like to know where in the file system I am, to remind me
> (hopefully) of what I was doing. If the current working directory is
> not in the prompt, I have to type "pwd" manually.
>
> To solve the problem, I was thinking of getting a function to run
> after a specified period of idle time. This function could then run
> "print -P" to print useful pieces of data, such as the hostname, the
> tty name, etc., and of course the current directory.
>
> 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).
TMOUT If this parameter is nonzero, the shell will receive an ALRM
signal if a command is not entered within the specified number
of seconds after issuing a prompt. If there is a trap on
SIGALRM, it will be executed and a new alarm is scheduled using
the value of the TMOUT parameter after executing the trap. If
no trap is set, and the idle time of the terminal is not less
than the value of the TMOUT parameter, zsh terminates. Other‐
wise a new alarm is scheduled to TMOUT seconds after the last
keypress.
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. And/or use zle -M to print the information, it will
be printed below the prompt (replacing any previous such message), it
will then be lost when overwritten by further commands/prompts. eg,
zle -N zle-line-init _zle_line_init
function _zle_line_init() {
TMOUT=3
}
TMOUT=3
TRAPALRM() { zle -M "hi there, you're in $PWD"; unset TMOUT }
--
Mikael Magnusson
Messages sorted by:
Reverse Date,
Date,
Thread,
Author