mirror of
https://github.com/tw93/Mole.git
synced 2026-02-04 18:34:46 +00:00
178 lines
5.2 KiB
Bash
Executable File
178 lines
5.2 KiB
Bash
Executable File
#!/bin/bash
|
|
# Mole - Main Entry Point
|
|
# A comprehensive macOS maintenance tool
|
|
#
|
|
# 🧹 Clean - Remove junk files and optimize system
|
|
# 🗑️ Uninstall - Remove applications completely
|
|
#
|
|
# Usage:
|
|
# ./mole # Interactive main menu
|
|
# ./mole clean # Direct clean mode
|
|
# ./mole uninstall # Direct uninstall mode
|
|
# ./mole --help # Show help
|
|
|
|
set -euo pipefail
|
|
|
|
# Get script directory
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
|
|
# Source common functions
|
|
source "$SCRIPT_DIR/lib/common.sh"
|
|
|
|
# Version info
|
|
VERSION="1.0.0"
|
|
MOLE_TAGLINE="Dig deep like a mole to clean your Mac."
|
|
|
|
show_brand_banner() {
|
|
printf '%b🦡 %bMOLE%b — %b%s%b\n' \
|
|
"$PURPLE" "$BLUE" "$NC" "$GREEN" "$MOLE_TAGLINE" "$NC"
|
|
}
|
|
|
|
show_help() {
|
|
show_brand_banner
|
|
echo
|
|
printf "%s%s%s\n" "$BLUE" "USAGE" "$NC"
|
|
printf " %s%s%s [command]\n\n" "$GREEN" "mole" "$NC"
|
|
|
|
printf "%s%s%s\n" "$BLUE" "COMMANDS" "$NC"
|
|
printf " %s%-16s%s %s\n" "$GREEN" "mole" "$NC" "Interactive main menu"
|
|
printf " %s%-16s%s %s\n" "$GREEN" "mole clean" "$NC" "Deeper system cleanup"
|
|
printf " %s%-16s%s %s\n" "$GREEN" "mole uninstall" "$NC" "Remove applications completely"
|
|
printf " %s%-16s%s %s\n" "$GREEN" "mole --help" "$NC" "Show this help message"
|
|
|
|
printf "\n%s%s%s\n" "$BLUE" "MORE" "$NC"
|
|
printf " https://github.com/tw93/mole\n"
|
|
}
|
|
|
|
show_main_menu() {
|
|
local selected="${1:-1}"
|
|
local redraw_full="${2:-true}"
|
|
|
|
if [[ "$redraw_full" == "true" ]]; then
|
|
echo ""
|
|
show_brand_banner
|
|
echo ""
|
|
fi
|
|
|
|
# Save cursor position before printing menu items
|
|
printf '\033[s'
|
|
|
|
show_menu_option 1 "Clean System - Remove junk files and optimize" "$([[ $selected -eq 1 ]] && echo true || echo false)"
|
|
show_menu_option 2 "Uninstall Apps - Remove applications completely" "$([[ $selected -eq 2 ]] && echo true || echo false)"
|
|
show_menu_option 3 "Help & Information - Usage guide and tips" "$([[ $selected -eq 3 ]] && echo true || echo false)"
|
|
show_menu_option 4 "Exit - Close Mole" "$([[ $selected -eq 4 ]] && echo true || echo false)"
|
|
|
|
if [[ "$redraw_full" == "true" ]]; then
|
|
echo ""
|
|
echo -e "${BLUE}Use ↑/↓ arrows to navigate, ENTER to select, ESC/q to quit${NC}"
|
|
fi
|
|
}
|
|
|
|
interactive_main_menu() {
|
|
local current_option=1
|
|
local total_options=4
|
|
local first_draw=true
|
|
|
|
# Set up signal trapping to handle Ctrl+C gracefully
|
|
trap 'echo ""; echo "Thank you for using Mole!"; exit 0' INT
|
|
|
|
cleanup_menu_display() {
|
|
printf '\033[u\033[J'
|
|
}
|
|
|
|
while true; do
|
|
if [[ "$first_draw" == "true" ]]; then
|
|
show_main_menu $current_option true
|
|
first_draw=false
|
|
else
|
|
# Restore cursor to saved position and only redraw menu items
|
|
printf '\033[u'
|
|
show_main_menu $current_option false
|
|
fi
|
|
|
|
# Use a more robust way to capture key input
|
|
local key
|
|
key=$(read_key)
|
|
|
|
# Check if read_key failed
|
|
if [[ $? -ne 0 ]]; then
|
|
continue
|
|
fi
|
|
|
|
case "$key" in
|
|
"UP")
|
|
((current_option > 1)) && ((current_option--))
|
|
;;
|
|
"DOWN")
|
|
((current_option < total_options)) && ((current_option++))
|
|
;;
|
|
"ENTER")
|
|
cleanup_menu_display
|
|
case $current_option in
|
|
1)
|
|
exec "$SCRIPT_DIR/bin/clean.sh"
|
|
;;
|
|
2)
|
|
exec "$SCRIPT_DIR/bin/uninstall.sh"
|
|
;;
|
|
3)
|
|
clear_screen
|
|
show_help
|
|
exit 0
|
|
;;
|
|
4)
|
|
clear_screen
|
|
echo ""
|
|
echo "Thank you for using Mole!"
|
|
exit 0
|
|
;;
|
|
esac
|
|
;;
|
|
"QUIT"|"ESC")
|
|
cleanup_menu_display
|
|
clear_screen
|
|
echo ""
|
|
echo "Thank you for using Mole!"
|
|
exit 0
|
|
;;
|
|
"1"|"2"|"3"|"4")
|
|
cleanup_menu_display
|
|
case $key in
|
|
1) exec "$SCRIPT_DIR/bin/clean.sh" ;;
|
|
2) exec "$SCRIPT_DIR/bin/uninstall.sh" ;;
|
|
3) clear_screen; show_help; exit 0 ;;
|
|
4) clear_screen; echo ""; echo "Thank you for using Mole!"; exit 0 ;;
|
|
esac
|
|
;;
|
|
*)
|
|
# Ignore unrecognized keys
|
|
;;
|
|
esac
|
|
done
|
|
}
|
|
|
|
main() {
|
|
case "${1:-""}" in
|
|
"clean")
|
|
exec "$SCRIPT_DIR/bin/clean.sh"
|
|
;;
|
|
"uninstall")
|
|
exec "$SCRIPT_DIR/bin/uninstall.sh"
|
|
;;
|
|
"help"|"--help"|"-h")
|
|
show_help
|
|
exit 0
|
|
;;
|
|
"")
|
|
interactive_main_menu
|
|
;;
|
|
*)
|
|
echo "Unknown command: $1"
|
|
echo "Use 'mole --help' for usage information."
|
|
exit 1
|
|
;;
|
|
esac
|
|
}
|
|
|
|
main "$@"
|