zsh-users
 help / color / mirror / code / Atom feed
From: Kurtis Rader <krader@skepticism.us>
To: Ray Andrews <rayandrews@eastlink.ca>
Cc: Zsh Users <zsh-users@zsh.org>
Subject: Re: can we detect the closing of a terminal?
Date: Fri, 4 Sep 2015 14:37:59 -0700	[thread overview]
Message-ID: <CABx2=D-tdE62Fz9s8T0yWpcutVtF_O4S2ErrZfYMam5gSbPTKQ@mail.gmail.com> (raw)
In-Reply-To: <55E9C085.2090301@eastlink.ca>

[-- Attachment #1: Type: text/plain, Size: 1725 bytes --]

On Fri, Sep 4, 2015 at 9:02 AM, Ray Andrews <rayandrews@eastlink.ca> wrote:

> Whenever I open a terminal I have a mechanism for passing to it knowledge
> of the current $PWD of any other open terminals.  It's cumbersome but it
> works.  Problem is that it's a one way thing in that when a terminal
> closes, that information is not passed, so there is orphan information.  Is
> there some 'pre-close()' function for terminals?  Sort of a suicide note?
> Or it might be about the same thing to have a function that's called before
> a shell exits 'zsh-pre-close()' , tho of course there can be several layers
> of shells in one terminal, but I guess that one can test for the 'zero'
> level shell in any given terminal.  I'll bet there is one for the shell,
> but for the terminal that might be wishing upon a star.
>

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.

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.

-- 
Kurtis Rader
Caretaker of the exceptional canines Junior and Hank

  parent reply	other threads:[~2015-09-04 21:38 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-30 19:13 zsh 5.1 released [user] Peter Stephenson
2015-09-04 16:02 ` can we detect the closing of a terminal? Ray Andrews
2015-09-04 17:09   ` ZyX
2015-09-04 21:37   ` Kurtis Rader [this message]
2015-09-05  3:07     ` Ray Andrews
2015-09-05  4:31       ` Kurtis Rader
2015-09-05 14:27         ` Ray Andrews
2015-09-06 16:43 ` zsh 5.1 released [user] Ray Andrews
2015-09-06 16:55   ` Axel Beckert
2015-09-06 16:57     ` Axel Beckert
2015-09-06 17:13       ` Ray Andrews
2015-09-06 19:37         ` Axel Beckert
2015-09-06 19:58           ` Ray Andrews
2015-09-08  1:55             ` Ray Andrews
2015-09-06 17:08     ` Ray Andrews
2015-09-06 16:50 ` syntax question Ray Andrews

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='CABx2=D-tdE62Fz9s8T0yWpcutVtF_O4S2ErrZfYMam5gSbPTKQ@mail.gmail.com' \
    --to=krader@skepticism.us \
    --cc=rayandrews@eastlink.ca \
    --cc=zsh-users@zsh.org \
    /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).