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.
This commit is contained in:
cschantz
2025-11-11 17:52:23 -05:00
parent 04950273a5
commit ddc72cd9dd
+21 -1
View File
@@ -1507,7 +1507,27 @@ main() {
read -p "Clean history and remove traces? (yes/no): " clean_hist read -p "Clean history and remove traces? (yes/no): " clean_hist
if [ "$clean_hist" = "yes" ]; then 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 TRACE_ERASER_AUTO=yes bash "$BASE_DIR/tools/erase-toolkit-traces.sh" 2>&1 | grep -E "^✓|^$" || true
fi fi