diff --git a/tools/erase-toolkit-traces.sh b/tools/erase-toolkit-traces.sh index 09d5682..03c8522 100755 --- a/tools/erase-toolkit-traces.sh +++ b/tools/erase-toolkit-traces.sh @@ -151,9 +151,27 @@ if [ "$CLEAN_HISTORY" = true ] && [ -f ~/.bash_history ]; then # Build single grep pattern for efficiency (single-pass filtering) GREP_PATTERN="git\.mull\.lol|linux-server-management-toolkit|server-toolkit|launcher\.sh|erase-toolkit-traces" - # Backup and clean in one efficient pass + # Backup and clean - handle HISTTIMEFORMAT timestamps cp ~/.bash_history ~/.bash_history.bak.$$ - grep -Ev "$GREP_PATTERN" ~/.bash_history.bak.$$ > ~/.bash_history.cleaned.$$ 2>/dev/null || true + + # Use awk to remove matching lines AND their preceding timestamp lines + awk -v pattern="$GREP_PATTERN" ' + /^#[0-9]+$/ { + # This is a timestamp line, store it + timestamp = $0 + next + } + { + # This is a command line + if ($0 !~ pattern) { + # Keep this command - print timestamp (if exists) and command + if (timestamp != "") print timestamp + print $0 + } + # Reset timestamp for next iteration + timestamp = "" + } + ' ~/.bash_history.bak.$$ > ~/.bash_history.cleaned.$$ 2>/dev/null || true # Calculate lines removed lines_before=$(wc -l < ~/.bash_history.bak.$$ 2>/dev/null || echo 0)