Zsh Mailing List Archive
Messages sorted by:
Re: can we detect the closing of a terminal?
- X-seq: zsh-users 20510
- From: ZyX <kp-pav@xxxxxxxxx>
- To: Ray Andrews <rayandrews@xxxxxxxxxxx>, "zsh-users@xxxxxxx" <zsh-users@xxxxxxx>
- Subject: Re: can we detect the closing of a terminal?
- Date: Fri, 04 Sep 2015 20:09:33 +0300
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1441386574; bh=Nw3jCM8KDM9TM9yvR8Tpd/CpI2anMXpP49V0obUB8Xo=; h=From:To:In-Reply-To:References:Subject:Date; b=HEFfBck8yFIsVkLq+smsCF3rdsNZbvS0UYJdXLQElBejBSjAZq3r1Ol8rUaznrqn9 jrt331EiP8sgpU3CuxpeZlSfmr6YO3xehQix5uLk6NR+TDt77w31P7QPTtdz0qjweC I5CZwBs2aW4I/+yz0aKP0ULajeKuNWD4ac08YI3U=
- In-reply-to: <55E9C085.email@example.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>
04.09.2015, 19:03, "Ray Andrews" <rayandrews@xxxxxxxxxxx>:
> 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
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: