1
0
mirror of https://github.com/tw93/Mole.git synced 2026-03-22 20:15:07 +00:00

fix brew uninstall fallback consistency

This commit is contained in:
Tw93
2026-03-17 16:39:42 +08:00
parent e1f427c9aa
commit 6c53906427
3 changed files with 164 additions and 8 deletions

View File

@@ -35,6 +35,21 @@ is_homebrew_available() {
command -v brew > /dev/null 2>&1
}
# Check whether a cask is still recorded as installed in Homebrew.
# Exit codes:
# 0 - cask is installed
# 1 - cask is not installed
# 2 - install state could not be determined
is_brew_cask_installed() {
local cask_name="$1"
[[ -n "$cask_name" ]] || return 2
is_homebrew_available || return 2
local cask_list
cask_list=$(HOMEBREW_NO_ENV_HINTS=1 brew list --cask 2> /dev/null) || return 2
grep -qxF "$cask_name" <<< "$cask_list"
}
# Extract cask token from a Caskroom path
# Args: $1 - path (must be inside Caskroom)
# Prints: cask token to stdout
@@ -211,7 +226,12 @@ brew_uninstall_cask() {
# Verify removal (only if not timed out)
local cask_gone=true app_gone=true
HOMEBREW_NO_ENV_HINTS=1 brew list --cask 2> /dev/null | grep -qxF "$cask_name" && cask_gone=false
if is_brew_cask_installed "$cask_name"; then
cask_gone=false
else
local cask_state=$?
[[ $cask_state -eq 1 ]] || cask_gone=false
fi
[[ -n "$app_path" && -e "$app_path" ]] && app_gone=false
# Success: uninstall worked and both are gone, or already uninstalled