From e8d9584dcbd37ed67a81fdec7c84c5ddd552aca6 Mon Sep 17 00:00:00 2001 From: cschantz Date: Tue, 11 Nov 2025 17:56:42 -0500 Subject: [PATCH] Fix history cleaning to work from parent shell The fundamental issue: launcher.sh runs in a subprocess, so it cannot modify the parent shell's history where the curl command was executed. Solution: Create a temporary cleanup script that the parent shell must source after launcher exits. This allows the history cleaning to run in the correct shell context. User workflow: 1. Run launcher.sh and select exit with cleanup 2. Source the generated /tmp/.cleanup_history_$$.sh script 3. History is cleaned in the parent shell 4. Exit and restart shell to verify The cleanup script removes toolkit traces from ~/.bash_history and disables history recording for the current session. --- launcher.sh | 55 ++++++++++++++++++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 20 deletions(-) diff --git a/launcher.sh b/launcher.sh index 2ed25d3..19c9ba7 100755 --- a/launcher.sh +++ b/launcher.sh @@ -1507,33 +1507,48 @@ main() { read -p "Clean history and remove traces? (yes/no): " clean_hist if [ "$clean_hist" = "yes" ]; then - # 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" + # Create a cleanup script for the parent shell to source + cat > /tmp/.cleanup_history_$$.sh << 'CLEANUP_EOF' +# Disable history recording +set +o history +shopt -u histappend 2>/dev/null || true - # Clean the history file (same logic as trace eraser) - 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 +# Clean the history file +GREP_PATTERN="git\.mull\.lol|linux-server-management-toolkit|server-toolkit|launcher\.sh|erase-toolkit-traces" +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 +# Clear and reload history +history -c +history -r ~/.bash_history +unset HISTFILE - # Reload cleaned history - history -r ~/.bash_history +# Clean up this temp script +rm -f /tmp/.cleanup_history_*.sh 2>/dev/null - # Unset HISTFILE to prevent re-writing on exit - unset HISTFILE +echo "" +echo "✓ History cleaned. Exit and start new shell to verify." +echo "" +CLEANUP_EOF - # Now run trace eraser for logs/files/directory cleanup + # 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 - echo "" - echo -e "${GREEN}Thanks for using Server Management Toolkit!${NC}" - echo "" + echo "" + echo -e "${GREEN}✓ All traces removed${NC}" + echo "" + echo -e "${YELLOW}IMPORTANT: Run this command now to clean your shell's history:${NC}" + echo "" + echo "source /tmp/.cleanup_history_$$.sh" + echo "" + else + echo "" + echo -e "${GREEN}Thanks for using Server Management Toolkit!${NC}" + echo "" + fi exit 0 ;; *)