From 7b14a3abd8b592517da804a755265edf3be6f5e0 Mon Sep 17 00:00:00 2001 From: Tw93 Date: Thu, 15 Jan 2026 14:31:36 +0800 Subject: [PATCH] feat(uninstall): enhance brew UX and auto-cleanup dependencies - Auto-run 'brew autoremove' after uninstalling casks - Fix spinner interference during brew operations - Add safety check for cask token detection --- lib/uninstall/batch.sh | 14 +++++++++++--- lib/uninstall/brew.sh | 3 +++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/uninstall/batch.sh b/lib/uninstall/batch.sh index 55555ad..bca31ea 100755 --- a/lib/uninstall/batch.sh +++ b/lib/uninstall/batch.sh @@ -395,6 +395,8 @@ batch_uninstall_applications() { local used_brew_successfully=false if [[ -z "$reason" ]]; then if [[ "$is_brew_cask" == "true" && -n "$cask_name" ]]; then + # Stop spinner before brew output + [[ -t 1 ]] && stop_inline_spinner # Use brew_uninstall_cask helper (handles env vars, timeout, verification) if brew_uninstall_cask "$cask_name" "$app_path"; then used_brew_successfully=true @@ -562,10 +564,16 @@ batch_uninstall_applications() { print_summary_block "$title" "${summary_details[@]}" printf '\n' - # Suggest brew autoremove if Homebrew casks were successfully uninstalled + # Auto-run brew autoremove if Homebrew casks were uninstalled if [[ $brew_apps_removed -gt 0 ]]; then - echo -e " ${GRAY}Tip: Run ${NC}brew autoremove${GRAY} to clean up orphaned dependencies${NC}" - echo "" + local autoremove_output removed_count + autoremove_output=$(HOMEBREW_NO_ENV_HINTS=1 brew autoremove 2>/dev/null) || true + removed_count=$(printf '%s\n' "$autoremove_output" | grep -c "^Uninstalling" || true) + removed_count=${removed_count:-0} + if [[ $removed_count -gt 0 ]]; then + echo -e "${GREEN}${ICON_SUCCESS}${NC} Cleaned $removed_count orphaned brew dependencies" + echo "" + fi fi # Clean up Dock entries for uninstalled apps. diff --git a/lib/uninstall/brew.sh b/lib/uninstall/brew.sh index d526e05..1cecdbf 100644 --- a/lib/uninstall/brew.sh +++ b/lib/uninstall/brew.sh @@ -92,6 +92,9 @@ _detect_cask_via_caskroom_search() { done < <(find "$room" -maxdepth 3 -name "$app_bundle_name" 2>/dev/null) done + # Need at least one token + ((${#tokens[@]} > 0)) || return 1 + # Deduplicate and check count local -a uniq IFS=$'\n' read -r -d '' -a uniq < <(printf '%s\n' "${tokens[@]}" | sort -u && printf '\0') || true