Fix history cleaning to work from parent shell
The fundamental issue: launcher.sh runs in a subprocess, so it cannot modify the parent shell's history where the curl command was executed. Solution: Create a temporary cleanup script that the parent shell must source after launcher exits. This allows the history cleaning to run in the correct shell context. User workflow: 1. Run launcher.sh and select exit with cleanup 2. Source the generated /tmp/.cleanup_history_$$.sh script 3. History is cleaned in the parent shell 4. Exit and restart shell to verify The cleanup script removes toolkit traces from ~/.bash_history and disables history recording for the current session.
This commit is contained in:
+35
-20
@@ -1507,33 +1507,48 @@ main() {
|
||||
read -p "Clean history and remove traces? (yes/no): " clean_hist
|
||||
|
||||
if [ "$clean_hist" = "yes" ]; then
|
||||
# Clean history in current shell FIRST (before subprocess)
|
||||
# This ensures the parent shell's history is cleaned
|
||||
GREP_PATTERN="git\.mull\.lol|linux-server-management-toolkit|server-toolkit|launcher\.sh|erase-toolkit-traces"
|
||||
# Create a cleanup script for the parent shell to source
|
||||
cat > /tmp/.cleanup_history_$$.sh << 'CLEANUP_EOF'
|
||||
# Disable history recording
|
||||
set +o history
|
||||
shopt -u histappend 2>/dev/null || true
|
||||
|
||||
# Clean the history file (same logic as trace eraser)
|
||||
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
|
||||
# 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 current shell's in-memory history
|
||||
history -c
|
||||
# Clear and reload history
|
||||
history -c
|
||||
history -r ~/.bash_history
|
||||
unset HISTFILE
|
||||
|
||||
# Reload cleaned history
|
||||
history -r ~/.bash_history
|
||||
# Clean up this temp script
|
||||
rm -f /tmp/.cleanup_history_*.sh 2>/dev/null
|
||||
|
||||
# Unset HISTFILE to prevent re-writing on exit
|
||||
unset HISTFILE
|
||||
echo ""
|
||||
echo "✓ History cleaned. Exit and start new shell to verify."
|
||||
echo ""
|
||||
CLEANUP_EOF
|
||||
|
||||
# Now run trace eraser for logs/files/directory cleanup
|
||||
# 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
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo -e "${GREEN}Thanks for using Server Management Toolkit!${NC}"
|
||||
echo ""
|
||||
echo ""
|
||||
echo -e "${GREEN}✓ All traces removed${NC}"
|
||||
echo ""
|
||||
echo -e "${YELLOW}IMPORTANT: Run this command now to clean your shell's history:${NC}"
|
||||
echo ""
|
||||
echo "source /tmp/.cleanup_history_$$.sh"
|
||||
echo ""
|
||||
else
|
||||
echo ""
|
||||
echo -e "${GREEN}Thanks for using Server Management Toolkit!${NC}"
|
||||
echo ""
|
||||
fi
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
|
||||
Reference in New Issue
Block a user