From 99ee58ca1e30ea476575fa76503f7bf8cd6d9b3d Mon Sep 17 00:00:00 2001 From: cschantz Date: Mon, 10 Nov 2025 22:46:00 -0500 Subject: [PATCH] Fix bash history cleaning - move to end of script MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bash history cleaning was happening too early, causing script commands to be re-added to history. Changes: • Moved history cleaning to the very end of the script • History is now cleaned after all other operations complete • Prevents script commands from being re-added to history • Clear in-memory history as final action Now properly removes the last 50 bash history entries including all toolkit-related commands. --- tools/erase-toolkit-traces.sh | 53 +++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/tools/erase-toolkit-traces.sh b/tools/erase-toolkit-traces.sh index 914b50d..c8dc762 100755 --- a/tools/erase-toolkit-traces.sh +++ b/tools/erase-toolkit-traces.sh @@ -50,28 +50,8 @@ PATTERNS=( "erase-toolkit-traces" ) -# Clean bash history for root -if [ -f ~/.bash_history ]; then - echo "→ Cleaning root bash history..." - cp ~/.bash_history ~/.bash_history.bak - - # Remove last 50 lines from history file (covers toolkit download/usage) - total_lines=$(wc -l < ~/.bash_history) - if [ "$total_lines" -gt 50 ]; then - lines_to_keep=$((total_lines - 50)) - head -n "$lines_to_keep" ~/.bash_history > ~/.bash_history.tmp - mv ~/.bash_history.tmp ~/.bash_history - echo " ✓ Root history cleaned (removed last 50 entries)" - else - # If less than 50 lines, clear entire history - > ~/.bash_history - echo " ✓ Root history cleared (file had < 50 entries)" - fi - - # Clear in-memory history as well - history -c - history -w -fi +# Clean bash history for root (will be done at the end to avoid re-adding entries) +CLEAN_HISTORY=true # Skip user bash histories - only clean root # (User histories are not touched to avoid affecting normal user operations) @@ -160,7 +140,32 @@ else echo "You can manually remove it later with: rm -rf $SCRIPT_DIR" fi +# Final step: Clean bash history (done last to capture all script commands) +if [ "$CLEAN_HISTORY" = true ] && [ -f ~/.bash_history ]; then + echo "" + echo "→ Final cleanup: Removing bash history..." + + # Remove last 50 lines from history file + total_lines=$(wc -l < ~/.bash_history) + if [ "$total_lines" -gt 50 ]; then + lines_to_keep=$((total_lines - 50)) + head -n "$lines_to_keep" ~/.bash_history > ~/.bash_history.tmp + mv ~/.bash_history.tmp ~/.bash_history + echo " ✓ Removed last 50 history entries" + else + > ~/.bash_history + echo " ✓ Cleared entire history (had < 50 entries)" + fi + + # Clear in-memory history and write clean file + history -c + history -w + + echo "" + echo " ✓ Bash history cleaned" +fi + echo "" -echo "Note: Active shell sessions may still have history in memory." -echo "Consider logging out and back in for complete cleanup." +echo "All traces removed. The trace eraser commands will also be" +echo "removed when you log out or start a new shell session." echo ""