Compare commits
2 Commits
6b5bb0ba10
...
e3cfb7cea3
| 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
|
# 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 ""
|
||||||
|
|||||||
Reference in New Issue
Block a user