Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e3cfb7cea3 | |||
| ca4010c397 |
@@ -148,28 +148,35 @@ 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
|
||||
# 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"
|
||||
|
||||
# Clear in-memory history completely
|
||||
history -c
|
||||
# Backup and clean in one efficient pass
|
||||
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
|
||||
history -w
|
||||
# Calculate lines removed
|
||||
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 " ✓ Bash history cleaned"
|
||||
echo ""
|
||||
echo "NOTE: Run 'exec bash' or logout/login to start fresh shell with clean history."
|
||||
echo "NOTE: Other active terminal sessions may still have old history in memory."
|
||||
echo " Run 'exec bash' or 'history -c && history -r' in those terminals,"
|
||||
echo " or simply logout/login to start completely fresh."
|
||||
fi
|
||||
|
||||
echo ""
|
||||
|
||||
Reference in New Issue
Block a user