diff --git a/GUIDE.md b/GUIDE.md index 5c970aa..460e6b9 100644 --- a/GUIDE.md +++ b/GUIDE.md @@ -155,17 +155,20 @@ mole analyze ### 使用建议 **推荐:** + - 第一次使用先 `--dry-run` 预览 - 定期清理(每月一次或磁盘快满时) - 有大型缓存可用 `--whitelist` 保护 **避免:** + - 频繁清理(一周一次就够了) - 运行重要程序时清理 ### 安全保障 **Mole 只删除可重新生成的缓存和日志,不会删除:** + - 应用配置文件(.plist)- 你的设置会保留 - 应用数据(Application Support)- 重要文档不受影响 - 系统关键文件、IDE 数据、数据库等 @@ -216,6 +219,23 @@ mole update brew upgrade mole ``` +### 如何卸载 Mole? + +如果你想要卸载 Mole(不管是一键安装还是 Homebrew 安装): + +```bash +mole remove +``` + +这个命令会: + +- 自动识别安装方式(Homebrew 或手动安装) +- 删除 Mole 可执行文件 +- 清理配置文件(`~/.config/mole/`) +- 清理缓存文件(`~/.cache/mole/`) + +**注意:** 卸载前会要求确认,请仔细阅读提示。 + --- ## 需要更多帮助? diff --git a/README.md b/README.md index cdeeac8..18dd263 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,7 @@ mole clean --whitelist # Manage protected caches mole uninstall # Uninstall apps mole analyze # Disk analyzer mole update # Update Mole +mole remove # Remove Mole from system mole --help # Show help ``` diff --git a/mole b/mole index 46df9fa..2db1697 100755 --- a/mole +++ b/mole @@ -134,6 +134,7 @@ show_help() { printf " %s%-28s%s %s\n" "$GREEN" "mole uninstall" "$NC" "Remove applications completely" printf " %s%-28s%s %s\n" "$GREEN" "mole analyze" "$NC" "Interactive disk space explorer" printf " %s%-28s%s %s\n" "$GREEN" "mole update" "$NC" "Update Mole to the latest version" + printf " %s%-28s%s %s\n" "$GREEN" "mole remove" "$NC" "Remove Mole from the system" printf " %s%-28s%s %s\n" "$GREEN" "mole --version" "$NC" "Show installed version" printf " %s%-28s%s %s\n" "$GREEN" "mole --help" "$NC" "Show this help message" @@ -201,6 +202,126 @@ update_mole() { rm -f "$HOME/.cache/mole/version_check" "$HOME/.cache/mole/update_message" } +# Remove Mole from system +remove_mole() { + clear + echo "" + echo -e "${YELLOW}⚠️ Remove Mole${NC}" + echo "" + + # Detect all installations + local is_homebrew=false + local -a manual_installs=() + + # Check Homebrew + if command -v brew >/dev/null 2>&1 && brew list mole >/dev/null 2>&1; then + is_homebrew=true + fi + + # Check common manual install locations + local -a common_paths=( + "/usr/local/bin/mole" + "$HOME/.local/bin/mole" + "/opt/local/bin/mole" + ) + + for path in "${common_paths[@]}"; do + if [[ -f "$path" ]]; then + # Check if it's not a Homebrew symlink + if [[ ! -L "$path" ]] || ! readlink "$path" | grep -q "Cellar/mole"; then + manual_installs+=("$path") + fi + fi + done + + # Show what will be removed + echo "This will remove:" + echo "" + + if [[ "$is_homebrew" == "true" ]]; then + echo -e " ${GREEN}✓${NC} Mole (via Homebrew)" + fi + + for install in "${manual_installs[@]}"; do + echo -e " ${GREEN}✓${NC} $install" + local install_dir="$(dirname "$install")" + local install_root="$(dirname "$install_dir")" + if [[ -d "$install_root/lib" ]]; then + echo -e " ${GREEN}✓${NC} $install_root/lib/" + fi + done + + echo -e " ${GREEN}✓${NC} ~/.config/mole/ (configuration)" + echo -e " ${GREEN}✓${NC} ~/.cache/mole/ (cache)" + + if [[ "$is_homebrew" == "false" && ${#manual_installs[@]} -eq 0 ]]; then + echo "" + echo -e "${YELLOW}No Mole installation detected${NC}" + exit 0 + fi + + echo "" + + # Confirm removal + read -p "Are you sure you want to remove Mole? (y/N): " -n 1 -r + echo "" + + if [[ ! $REPLY =~ ^[Yy]$ ]]; then + echo "Cancelled." + exit 0 + fi + + echo "" + log_info "Removing Mole..." + + # Remove Homebrew installation + if [[ "$is_homebrew" == "true" ]]; then + if brew uninstall mole 2>&1 | grep -q "Uninstalling"; then + log_success "Uninstalled via Homebrew" + else + log_error "Failed to uninstall via Homebrew" + echo "Try manually: brew uninstall mole" + fi + fi + + # Remove manual installations + for install in "${manual_installs[@]}"; do + if [[ -f "$install" ]]; then + if rm -f "$install" 2>/dev/null; then + log_success "Removed: $install" + else + log_error "Failed to remove $install (try with sudo)" + fi + fi + + # Remove lib directory if it exists + local install_dir="$(dirname "$install")" + local install_root="$(dirname "$install_dir")" + if [[ -d "$install_root/lib" ]]; then + if rm -rf "$install_root/lib" 2>/dev/null; then + log_success "Removed library files from $install_root" + else + log_warning "Could not remove $install_root/lib (may need sudo)" + fi + fi + done + + # Clean up configuration and cache (both methods) + if [[ -d "$HOME/.config/mole" ]]; then + rm -rf "$HOME/.config/mole" 2>/dev/null && log_success "Removed configuration" + fi + if [[ -d "$HOME/.cache/mole" ]]; then + rm -rf "$HOME/.cache/mole" 2>/dev/null && log_success "Removed cache" + fi + + echo "" + echo -e "${GREEN}✨ Mole has been removed successfully${NC}" + echo "" + echo "Thank you for using Mole!" + + exit 0 +} + # Display main menu options show_main_menu() { local selected="${1:-1}" @@ -310,6 +431,10 @@ main() { update_mole exit 0 ;; + "remove") + remove_mole + exit 0 + ;; "help"|"--help"|"-h") show_help exit 0