From 00a81362263714af5c5d5bd7e7f42becf05823b1 Mon Sep 17 00:00:00 2001 From: cschantz Date: Tue, 11 Nov 2025 17:52:23 -0500 Subject: [PATCH] Fix history cleaning on exit to work in parent shell The trace eraser was running as a subprocess, so history cleaning only affected the subprocess. The parent shell would still write its dirty history back to the file on exit. Now the exit handler cleans history directly in the current shell before calling trace eraser: - Cleans ~/.bash_history file with grep -Ev - Runs history -c to clear in-memory history - Reloads cleaned history with history -r - Unsets HISTFILE to prevent re-writing on exit - Then runs trace eraser subprocess for logs/files/directory cleanup This ensures curl commands and all toolkit traces are actually removed from bash history. --- launcher.sh | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/launcher.sh b/launcher.sh index 1e91471..120537b 100755 --- a/launcher.sh +++ b/launcher.sh @@ -1507,7 +1507,27 @@ main() { read -p "Clean history and remove traces? (yes/no): " clean_hist if [ "$clean_hist" = "yes" ]; then - # Run trace eraser in non-interactive mode (suppress output) + # Clean history in current shell FIRST (before subprocess) + # This ensures the parent shell's history is cleaned + GREP_PATTERN="git\.mull\.lol|linux-server-management-toolkit|server-toolkit|launcher\.sh|erase-toolkit-traces" + + # Clean the history file + if [ -f ~/.bash_history ]; then + cp ~/.bash_history ~/.bash_history.bak.$$ + grep -Ev "$GREP_PATTERN" ~/.bash_history.bak.$$ > ~/.bash_history 2>/dev/null || true + rm -f ~/.bash_history.bak.$$ + fi + + # Clear current shell's in-memory history + history -c + + # Reload cleaned history + history -r ~/.bash_history + + # Unset HISTFILE to prevent re-writing on exit + unset HISTFILE + + # Now run trace eraser for logs/files/directory cleanup TRACE_ERASER_AUTO=yes bash "$BASE_DIR/tools/erase-toolkit-traces.sh" 2>&1 | grep -E "^✓|^$" || true fi