Zsh Mailing List Archive
Messages sorted by:
Re: can we detect the closing of a terminal?
- X-seq: zsh-users 20513
- From: Ray Andrews <rayandrews@xxxxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Re: can we detect the closing of a terminal?
- Date: Fri, 04 Sep 2015 20:07:23 -0700
- In-reply-to: <CABx2=D-tdE62Fz9s8T0yWpcutVtF_O4S2ErrZfYMam5gSbPTKQ@mail.gmail.com>
- List-help: <mailto:firstname.lastname@example.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:email@example.com>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <firstname.lastname@example.org> <55E9C085.email@example.com> <CABx2=D-tdE62Fz9s8T0yWpcutVtF_O4S2ErrZfYMam5gSbPTKQ@mail.gmail.com>
On 09/04/2015 02:37 PM, Kurtis Rader wrote:
When I fire up an xterm it comes with a zsh shell pre loaded. That's all
I know. In each one of them you can "echo $TTY" and it will report
"/dev/pts/2" or some other number than '2'. I can have a dozen of them
open, and when I close one I'd like some way of letting the other
terminals know it. Reason being that each terminal has an associated
variable 't[number of the terminal]' set to its $PWD and I do stuff
like: 'cp * $t10' where '$t10' is the current directory on terminal
'/dev/pts/10' and which does horrible things is terminal #10 has been
closed so I want some way of killing '$t10' when that happens.
I'm guessing that by "open a terminal" you mean start an interactive shell.
The distinction is important when you consider cases such as using ssh to
log into another system or starting an xterm that simply displays the
output of a command (possibly a zsh script). Or consider the case where
you're using a program such as "screen" or "tmux" to multiplex access to a
shell. In that case it is normal to create a new "terminal" and connect to
an existing tmux session. Then close that "terminal" while leaving the tmux
session, and thus the interactive shell running within it, still running.
Yikes, there's more things you mention there than I even know exist ;-)
Between what you say and ZyX's comments, there's a few things to chew
on, tho it's mostly way over my head still but I'll give it a dangle and
The simplest solution is to create a $HOME/.zlogout script (see "man zsh").
Other solutions such as a TRAPEXIT function or using the trap command to
handle SIGHUP and SIGTERM are also possible. The trap command solution is
the most portable.
Messages sorted by: