diff options
Diffstat (limited to 'sh')
-rw-r--r-- | sh/logout | 2 | ||||
-rw-r--r-- | sh/profile | 15 |
2 files changed, 17 insertions, 0 deletions
diff --git a/sh/logout b/sh/logout new file mode 100644 index 00000000..4da61192 --- /dev/null +++ b/sh/logout @@ -0,0 +1,2 @@ +# Write PWD to a file if set +printf '%s\n' "$PWD" >"${OLDPWD_FILE:-"$HOME"/.oldpwd}" @@ -9,6 +9,21 @@ for sh in "$HOME"/.profile.d/*.sh ; do done unset -v sh +# Trap on exit to run ~/.logout if it exists +logout_trap() { + if [ -f "$HOME"/.logout ] ; then + . "$HOME"/.logout + fi + if [ "$1" != EXIT ] ; then + trap - "$1" + kill "-$1" "$$" + fi +} +for sig in EXIT HUP INT TERM ; do + trap "logout_trap $sig" "$sig" +done +unset -v sig + # If ENV is unset after running those scripts and ~/.shrc exists, set it as ENV if [ -z "$ENV" ] && [ -f "$HOME"/.shrc ] ; then ENV=$HOME/.shrc |