summary refs log tree commit diff stats
path: root/session.bash
diff options
context:
space:
mode:
Diffstat (limited to 'session.bash')
-rw-r--r--session.bash12
1 files changed, 11 insertions, 1 deletions
diff --git a/session.bash b/session.bash
index 423ad85..990966b 100644
--- a/session.bash
+++ b/session.bash
@@ -25,9 +25,19 @@ fi
 # usage: session <name>
 # switches HISTFILE to ~/.bash_history.<name>
 session() {
+	local session sessioncwd sessionflags
 	if [[ "$1" =~ ^[a-z][a-z0-9]*$ ]]; then
+		if [[ "${HISTFILE#~/.bash_history.}" != "$HISTFILE" ]]; then
+			session="${HISTFILE#~/.bash_history.}"
+			sessioncwd="$(grep -s ' # '"$session"'$' ~/.bash_session_cwd | tail -n 1)"
+			sessionflags="${sessioncwd% # *}"
+			sessionflags="${sessionflags##* # }"
+			if (eval "$sessionflags" && test -v NOHIST); then
+				history -c
+			fi
+		fi
 		# remove session switch from history
-		history -d -1
+		history -d -1 >/dev/null 2>/dev/null || true
 		# write/append history
 		if shopt -q histappend; then history -a; else history -w; fi
 		# clear history