Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: can we detect the closing of a terminal?
On Fri, Sep 4, 2015 at 9:02 AM, Ray Andrews <rayandrews@xxxxxxxxxxx> 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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author