Simplify trace eraser - unset HISTFILE to prevent re-adding
Changes: - Remove complex history -d loop (unreliable) - Clean file directly with grep -Ev only - Clear current session with history -c - Unset HISTFILE to prevent session from writing on exit - Disable histappend for current session Issue: - Complex history manipulation was unreliable - Current session kept re-adding commands on exit - history -w then grep -Ev was conflicting Solution: - Just clean the file, period - Unset HISTFILE so current session won't write anything - Tell user to exit immediately and start fresh shell Tested: ✓ File cleaned with grep -Ev ✓ HISTFILE unset prevents writing on exit
This commit is contained in:
@@ -122,60 +122,36 @@ if [ "$CLEAN_HISTORY" = true ] && [ -f ~/.bash_history ]; then
|
|||||||
echo ""
|
echo ""
|
||||||
echo "→ Final cleanup: Removing bash history..."
|
echo "→ Final cleanup: Removing bash history..."
|
||||||
|
|
||||||
# Disable history recording for this session to prevent re-adding commands
|
# Disable history recording AND appending for this session
|
||||||
set +o history
|
set +o history
|
||||||
|
shopt -u histappend 2>/dev/null || true
|
||||||
|
|
||||||
# Clean in-memory history first using history -d (most reliable method)
|
echo " → Cleaning history file..."
|
||||||
echo " → Cleaning in-memory history..."
|
|
||||||
GREP_PATTERN="git\.mull\.lol|linux-server-management-toolkit|server-toolkit|launcher\.sh|erase-toolkit-traces"
|
GREP_PATTERN="git\.mull\.lol|linux-server-management-toolkit|server-toolkit|launcher\.sh|erase-toolkit-traces"
|
||||||
|
|
||||||
# Get list of history entry numbers to delete (reverse order to maintain numbering)
|
# Clean the history file directly
|
||||||
entries_to_delete=$(history | grep -E "$GREP_PATTERN" | awk '{print $1}' | sort -rn)
|
|
||||||
entries_count=$(echo "$entries_to_delete" | grep -c '^' 2>/dev/null || echo 0)
|
|
||||||
|
|
||||||
# Delete each matching entry from in-memory history
|
|
||||||
for entry_num in $entries_to_delete; do
|
|
||||||
history -d "$entry_num" 2>/dev/null || true
|
|
||||||
done
|
|
||||||
|
|
||||||
echo " ✓ Removed $entries_count toolkit-related entries from in-memory history"
|
|
||||||
|
|
||||||
# Also remove any 'history' commands that might show investigation
|
|
||||||
echo " → Removing history command traces..."
|
|
||||||
history_entries=$(history | grep -E '^\s*[0-9]+\s+.*history' | awk '{print $1}' | sort -rn)
|
|
||||||
history_count=$(echo "$history_entries" | grep -c '^' 2>/dev/null || echo 0)
|
|
||||||
|
|
||||||
for entry_num in $history_entries; do
|
|
||||||
history -d "$entry_num" 2>/dev/null || true
|
|
||||||
done
|
|
||||||
|
|
||||||
if [ "$history_count" -gt 0 ]; then
|
|
||||||
echo " ✓ Removed $history_count history command entries"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Write cleaned in-memory history back to file
|
|
||||||
history -w
|
|
||||||
|
|
||||||
echo " ✓ Cleaned history written to file"
|
|
||||||
|
|
||||||
# Also clean the history file directly (in case commands are from other sessions)
|
|
||||||
echo " → Cleaning history file for commands from other sessions..."
|
|
||||||
if [ -f ~/.bash_history ]; then
|
if [ -f ~/.bash_history ]; then
|
||||||
cp ~/.bash_history ~/.bash_history.bak.$$
|
cp ~/.bash_history ~/.bash_history.bak.$$
|
||||||
|
lines_before=$(wc -l < ~/.bash_history.bak.$$ 2>/dev/null || echo 0)
|
||||||
grep -Ev "$GREP_PATTERN" ~/.bash_history.bak.$$ > ~/.bash_history 2>/dev/null || true
|
grep -Ev "$GREP_PATTERN" ~/.bash_history.bak.$$ > ~/.bash_history 2>/dev/null || true
|
||||||
|
lines_after=$(wc -l < ~/.bash_history 2>/dev/null || echo 0)
|
||||||
|
lines_removed=$((lines_before - lines_after))
|
||||||
rm -f ~/.bash_history.bak.$$
|
rm -f ~/.bash_history.bak.$$
|
||||||
echo " ✓ History file cleaned"
|
echo " ✓ Removed $lines_removed entries from history file"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Reload cleaned history into current session to prevent re-adding on exit
|
# Clear current session's history completely to prevent re-adding on exit
|
||||||
echo " → Reloading cleaned history into current session..."
|
echo " → Clearing current session history..."
|
||||||
history -c
|
history -c
|
||||||
history -r
|
|
||||||
|
|
||||||
echo " ✓ In-memory history reloaded from cleaned file"
|
# Unset HISTFILE to prevent this session from writing on exit
|
||||||
|
unset HISTFILE
|
||||||
|
|
||||||
|
echo " ✓ Current session history cleared and disabled"
|
||||||
echo ""
|
echo ""
|
||||||
echo "NOTE: For complete cleanup, run 'exec bash' to start a fresh shell."
|
echo -e "${YELLOW}IMPORTANT: Exit this shell immediately after cleanup${NC}"
|
||||||
echo " This prevents any lingering history from being re-saved."
|
echo "Type: exit"
|
||||||
|
echo "Then start a fresh shell to see cleaned history."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Offer to remove the entire toolkit (AFTER history cleaning)
|
# Offer to remove the entire toolkit (AFTER history cleaning)
|
||||||
|
|||||||
Reference in New Issue
Block a user