Consolidate cleanup to use single trace eraser script
Exit menu now: - Calls trace eraser in TRACE_ERASER_AUTO=yes mode (no prompts, removes everything) - Creates minimal helper script only for parent shell history cleanup - Single source of truth: tools/erase-toolkit-traces.sh Removed duplicate cleanup logic from launcher exit handler.
This commit is contained in:
+8
-31
@@ -1507,42 +1507,19 @@ main() {
|
|||||||
read -p "Clean history and remove traces? (yes/no): " clean_hist
|
read -p "Clean history and remove traces? (yes/no): " clean_hist
|
||||||
|
|
||||||
if [ "$clean_hist" = "yes" ]; then
|
if [ "$clean_hist" = "yes" ]; then
|
||||||
# Create a cleanup script for the parent shell to source
|
# Run the trace eraser in auto mode (removes files, logs, directory)
|
||||||
cat > /tmp/.cleanup_history_$$.sh << 'CLEANUP_EOF'
|
|
||||||
# Disable history recording
|
|
||||||
set +o history
|
|
||||||
shopt -u histappend 2>/dev/null || true
|
|
||||||
|
|
||||||
# Clean the history file
|
|
||||||
GREP_PATTERN="git\.mull\.lol|linux-server-management-toolkit|server-toolkit|launcher\.sh|erase-toolkit-traces"
|
|
||||||
if [ -f ~/.bash_history ]; then
|
|
||||||
cp ~/.bash_history ~/.bash_history.bak.$$
|
|
||||||
grep -Ev "$GREP_PATTERN" ~/.bash_history.bak.$$ > ~/.bash_history 2>/dev/null || true
|
|
||||||
rm -f ~/.bash_history.bak.$$
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Clear and reload history
|
|
||||||
history -c
|
|
||||||
history -r ~/.bash_history
|
|
||||||
unset HISTFILE
|
|
||||||
|
|
||||||
# Clean up this temp script
|
|
||||||
rm -f /tmp/.cleanup_history_*.sh 2>/dev/null
|
|
||||||
|
|
||||||
echo ""
|
|
||||||
echo "✓ History cleaned. Exit and start new shell to verify."
|
|
||||||
echo ""
|
|
||||||
CLEANUP_EOF
|
|
||||||
|
|
||||||
# Run trace eraser for logs/files/directory cleanup
|
|
||||||
TRACE_ERASER_AUTO=yes bash "$BASE_DIR/tools/erase-toolkit-traces.sh" 2>&1 | grep -E "^✓|^$" || true
|
TRACE_ERASER_AUTO=yes bash "$BASE_DIR/tools/erase-toolkit-traces.sh" 2>&1 | grep -E "^✓|^$" || true
|
||||||
|
|
||||||
|
# Create a simple helper script for parent shell history cleanup
|
||||||
|
# (Parent shell needs to source this since subprocess can't modify parent's history)
|
||||||
|
cat > /tmp/.cleanup_hist.sh << 'HIST_EOF'
|
||||||
|
set +o history; shopt -u histappend 2>/dev/null; GREP_PATTERN="git\.mull\.lol|linux-server-management-toolkit|server-toolkit|launcher\.sh|erase-toolkit-traces"; [ -f ~/.bash_history ] && cp ~/.bash_history ~/.bash_history.bak.$$ && grep -Ev "$GREP_PATTERN" ~/.bash_history.bak.$$ > ~/.bash_history 2>/dev/null && rm -f ~/.bash_history.bak.$$; history -c; history -r ~/.bash_history; unset HISTFILE; rm -f /tmp/.cleanup_hist.sh; echo ""; echo "✓ History cleaned"; echo ""
|
||||||
|
HIST_EOF
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo -e "${GREEN}✓ All traces removed${NC}"
|
echo -e "${GREEN}✓ All traces removed${NC}"
|
||||||
echo ""
|
echo ""
|
||||||
echo -e "${YELLOW}IMPORTANT: Run this command now to clean your shell's history:${NC}"
|
echo -e "${YELLOW}Run this to finish cleanup:${NC} source /tmp/.cleanup_hist.sh"
|
||||||
echo ""
|
|
||||||
echo "source /tmp/.cleanup_history_$$.sh"
|
|
||||||
echo ""
|
echo ""
|
||||||
else
|
else
|
||||||
echo ""
|
echo ""
|
||||||
|
|||||||
Reference in New Issue
Block a user