summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorSoniEx2 <endermoneymod@gmail.com>2024-04-21 11:50:22 -0300
committerSoniEx2 <endermoneymod@gmail.com>2024-04-21 11:50:22 -0300
commit66930d79eaf21d32124b10ecc396d9d629ffbd47 (patch)
tree0d8b53e0f5664a82c63c72153c90f8555e365d1a
parentfe4452e7b622610c335229e8eac5f8937a192350 (diff)
Add session flags, history suppression
-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