aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile1
-rw-r--r--bash/bash_logout3
-rw-r--r--sh/logout2
-rw-r--r--sh/profile15
4 files changed, 18 insertions, 3 deletions
diff --git a/Makefile b/Makefile
index 5d8369c9..433a9f43 100644
--- a/Makefile
+++ b/Makefile
@@ -267,6 +267,7 @@ install-sh : check-sh
install -m 0755 -d -- \
"$(HOME)"/.profile.d \
"$(HOME)"/.shrc.d
+ install -pm 0644 -- sh/logout "$(HOME)"/.logout
install -pm 0644 -- sh/profile "$(HOME)"/.profile
install -pm 0644 -- sh/profile.d/* "$(HOME)"/.profile.d
install -pm 0644 -- sh/shrc "$(HOME)"/.shrc
diff --git a/bash/bash_logout b/bash/bash_logout
index e8137e55..afb088b8 100644
--- a/bash/bash_logout
+++ b/bash/bash_logout
@@ -12,6 +12,3 @@ fi
if ((SHLVL == 1)) ; then
clear_console -q 2>/dev/null
fi
-
-# Write PWD to a file if set
-printf '%s\n' "$PWD" > "${OLDPWD_FILE:-$HOME/.oldpwd}"
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}"
diff --git a/sh/profile b/sh/profile
index 5dfe0ef3..7fea250b 100644
--- a/sh/profile
+++ b/sh/profile
@@ -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