Compare commits

..

2 Commits

Author SHA1 Message Date
cschantz e3cfb7cea3 Improve trace eraser history cleaning efficiency and reliability
Changes:
- Replace chained grep -v with single grep -Ev for efficiency
- Fix critical bug: history -w was overwriting cleaned file
- Use history -r instead of history -w to reload cleaned history
- Single-pass filtering instead of 5 separate grep processes
- Better user messaging about other terminal sessions

Technical improvements:
- Escaped regex metacharacters in pattern (git\.mull\.lol)
- Use 3988207 for unique temp file names
- More efficient: 1 process vs 5 processes

Tested:
✓ Removes all toolkit commands regardless of position
✓ Preserves normal commands
✓ No temp file errors
✓ History properly reloaded into memory
✓ 7 toolkit entries removed from 20-line test history
2025-11-10 23:05:48 -05:00
cschantz ca4010c397 Fix trace eraser temp file bug
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
2025-11-10 23:01:13 -05:00
+25 -18
View File
@@ -148,28 +148,35 @@ if [ "$CLEAN_HISTORY" = true ] && [ -f ~/.bash_history ]; then
# Disable history recording for this session to prevent re-adding commands # Disable history recording for this session to prevent re-adding commands
set +o history set +o history
# Remove last 10 lines from history file (covers toolkit download/usage) # Build single grep pattern for efficiency (single-pass filtering)
total_lines=$(wc -l < ~/.bash_history) GREP_PATTERN="git\.mull\.lol|linux-server-management-toolkit|server-toolkit|launcher\.sh|erase-toolkit-traces"
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
# Clear in-memory history completely # Backup and clean in one efficient pass
history -c cp ~/.bash_history ~/.bash_history.bak.$$
grep -Ev "$GREP_PATTERN" ~/.bash_history.bak.$$ > ~/.bash_history.cleaned.$$ 2>/dev/null || true
# Write the empty history to file # Calculate lines removed
history -w lines_before=$(wc -l < ~/.bash_history.bak.$$ 2>/dev/null || echo 0)
lines_after=$(wc -l < ~/.bash_history.cleaned.$$ 2>/dev/null || echo 0)
lines_removed=$((lines_before - lines_after))
# Replace history file with cleaned version
mv ~/.bash_history.cleaned.$$ ~/.bash_history
# Clean up backup
rm -f ~/.bash_history.bak.$$
echo " ✓ Removed $lines_removed toolkit-related history entries"
# Reload cleaned history into current session
history -c # Clear in-memory history
history -r # Reload from cleaned file
echo " ✓ In-memory history reloaded from cleaned file"
echo "" echo ""
echo " ✓ Bash history cleaned" echo "NOTE: Other active terminal sessions may still have old history in memory."
echo "" echo " Run 'exec bash' or 'history -c && history -r' in those terminals,"
echo "NOTE: Run 'exec bash' or logout/login to start fresh shell with clean history." echo " or simply logout/login to start completely fresh."
fi fi
echo "" echo ""