From ca4010c397bba02d95c2d49e8945b5bd0e26e066 Mon Sep 17 00:00:00 2001 From: cschantz Date: Mon, 10 Nov 2025 23:01:13 -0500 Subject: [PATCH] Fix trace eraser temp file bug MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Changes: - Calculate lines removed before deleting temp files - Add error handling to line count calculations - Prevent 'No such file or directory' error on line 163 Tested: ✓ Pattern-based removal works correctly ✓ Removes toolkit entries regardless of position ✓ No temp file access errors --- tools/erase-toolkit-traces.sh | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/tools/erase-toolkit-traces.sh b/tools/erase-toolkit-traces.sh index ee4a2ad..6240f99 100755 --- a/tools/erase-toolkit-traces.sh +++ b/tools/erase-toolkit-traces.sh @@ -148,17 +148,25 @@ if [ "$CLEAN_HISTORY" = true ] && [ -f ~/.bash_history ]; then # Disable history recording for this session to prevent re-adding commands set +o history - # Remove last 10 lines from history file (covers toolkit download/usage) - total_lines=$(wc -l < ~/.bash_history) - if [ "$total_lines" -gt 10 ]; then - lines_to_keep=$((total_lines - 10)) - head -n "$lines_to_keep" ~/.bash_history > ~/.bash_history.tmp - mv ~/.bash_history.tmp ~/.bash_history - echo " ✓ Removed last 10 history entries" - else - > ~/.bash_history - echo " ✓ Cleared entire history (had < 10 entries)" - fi + # Remove toolkit-related entries from history file + cp ~/.bash_history ~/.bash_history.tmp + + # Remove lines containing toolkit-related patterns + grep -v "git.mull.lol" ~/.bash_history.tmp > ~/.bash_history.tmp2 2>/dev/null || true + grep -v "linux-server-management-toolkit" ~/.bash_history.tmp2 > ~/.bash_history.tmp3 2>/dev/null || true + grep -v "server-toolkit" ~/.bash_history.tmp3 > ~/.bash_history.tmp4 2>/dev/null || true + grep -v "launcher.sh" ~/.bash_history.tmp4 > ~/.bash_history.tmp5 2>/dev/null || true + grep -v "erase-toolkit-traces" ~/.bash_history.tmp5 > ~/.bash_history 2>/dev/null || true + + # Calculate lines removed before deleting temp files + lines_before=$(wc -l < ~/.bash_history.tmp 2>/dev/null || echo 0) + lines_after=$(wc -l < ~/.bash_history 2>/dev/null || echo 0) + lines_removed=$((lines_before - lines_after)) + + # Clean up temp files + rm -f ~/.bash_history.tmp* + + echo " ✓ Removed $lines_removed toolkit-related history entries" # Clear in-memory history completely history -c