Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: can we detect the closing of a terminal?

04.09.2015, 19:03, "Ray Andrews" <rayandrews@xxxxxxxxxxx>:
> Gentlemen:
> 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.

You can use `trap` command for this: trap 'command' EXIT (alternative: define TRAPEXIT() function), needs to be defined outside of functions. `man zshbuiltins`, documentation for `trap` built-in also references `zshexit` hook, so it is probably better to use

    function my-zshexit-hook()
        your code here
    zshexit_functions+=( my-zshexit-hook )

. But documentation for this hook says that this hook is “Executed at the point where the main shell is about to exit normally.”: note “normally”. When trying to use this do some tests, maybe you need this trap *and* some trap like TRAPHUP() function, I have not ever needed this.

Messages sorted by: Reverse Date, Date, Thread, Author