X-Git-Url: https://git.sev.monster/~sev/dotfiles.git/blobdiff_plain/81c3957ebd4867322d8d9e4cb7a95f57253c9738..c7e3e126ca2bfe463d344260b73b8c044e203ea0:/base/.zlogout diff --git a/base/.zlogout b/base/.zlogout index 9e0ed3f..6e7b474 100644 --- a/base/.zlogout +++ b/base/.zlogout @@ -1,7 +1,39 @@ -echo logout -clear +# NOTE: for the cleanups below, even if our shell is not the one that spawned +# the directory, SHLVL == 1 means that it should be safe to clean it up. +# since .zlogout isn't guaranteed to have been run in the same shell as +# our .zprofile was (since we source it in .zshenv) it has to be done +# like this. + +### gpg forward cleanup +if [[ $SHLVL == 1 && $GNUPGHOME =~ '/.ssh_forward/\d+/*$' ]] { + x=$GNUPGHOME + # reset GNUPGHOME + [[ -o GLOB_ASSIGN ]]; y=$? + setopt GLOB_ASSIGN + GNUPGHOME=$GNUPGHOME/../..(:a) + [[ $y != 0 ]] && unsetopt GLOB_ASSIGN + # clean dir if it exists + if [[ -d $x ]] { + find $x -mindepth 1 -maxdepth 1 | while read -r y; do + unlink $y + done + rmdir -p $x 2>/dev/null + } + # clean up any remaining sockets from gpg forwarding + rm -f $_GNUPG_SOCK_DEST_BASE*(N=) +} + +### remove tmp runtime if our shell spawned it +if [[ $SHLVL == 1 && $TMPDIR =~ '/.session.\d+/*$' ]] { + rm -rf $TMPDIR 2>/dev/null +} + +if [[ -o interactive ]] { + echo logout + clear +} ### load site-specific if [[ -f ~/.zlogout.local ]] { source ~/.zlogout.local } -# vim: set et sts=4 sw=4 ts=8 tw=79 : +# vim: et sts=4 sw=4 ts=8 tw=79