1
0
mirror of https://github.com/tw93/Mole.git synced 2026-02-10 00:54:15 +00:00

Greatly improve scanning speed

This commit is contained in:
Tw93
2025-10-17 21:19:05 +08:00
parent 43616666db
commit 640499d302
4 changed files with 195 additions and 42 deletions

View File

@@ -217,7 +217,7 @@ read_key() {
case "$key" in
$'\n' | $'\r') echo "ENTER" ;;
' ') echo "SPACE" ;;
'Q') echo "QUIT" ;;
'q' | 'Q') echo "QUIT" ;;
'R') echo "RETRY" ;;
'o' | 'O') echo "OPEN" ;;
'/') echo "FILTER" ;; # Trigger filter mode
@@ -1425,13 +1425,27 @@ readonly DATA_PROTECTED_BUNDLES=(
# Legacy function - preserved for backward compatibility
# Use should_protect_from_uninstall() or should_protect_data() instead
readonly PRESERVED_BUNDLE_PATTERNS=("${SYSTEM_CRITICAL_BUNDLES[@]}" "${DATA_PROTECTED_BUNDLES[@]}")
# Check whether a bundle ID matches a pattern (supports globs)
bundle_matches_pattern() {
local bundle_id="$1"
local pattern="$2"
[[ -z "$pattern" ]] && return 1
# shellcheck disable=SC2254 # allow glob pattern matching for bundle rules
case "$bundle_id" in
$pattern) return 0 ;;
esac
return 1
}
should_preserve_bundle() {
local bundle_id="$1"
for pattern in "${PRESERVED_BUNDLE_PATTERNS[@]}"; do
# Use case for safer glob matching
case "$bundle_id" in
"$pattern") return 0 ;;
esac
if bundle_matches_pattern "$bundle_id" "$pattern"; then
return 0
fi
done
return 1
}
@@ -1440,10 +1454,9 @@ should_preserve_bundle() {
should_protect_from_uninstall() {
local bundle_id="$1"
for pattern in "${SYSTEM_CRITICAL_BUNDLES[@]}"; do
# Use case for safer glob matching
case "$bundle_id" in
"$pattern") return 0 ;;
esac
if bundle_matches_pattern "$bundle_id" "$pattern"; then
return 0
fi
done
return 1
}
@@ -1453,10 +1466,9 @@ should_protect_data() {
local bundle_id="$1"
# Protect both system critical and data protected bundles during cleanup
for pattern in "${SYSTEM_CRITICAL_BUNDLES[@]}" "${DATA_PROTECTED_BUNDLES[@]}"; do
# Use case for safer glob matching
case "$bundle_id" in
"$pattern") return 0 ;;
esac
if bundle_matches_pattern "$bundle_id" "$pattern"; then
return 0
fi
done
return 1
}
@@ -1598,6 +1610,36 @@ find_app_files() {
files_to_clean+=("$framework")
done < <(find ~/Library/PrivateFrameworks \( -name "$app_name*" -o -name "$bundle_id*" \) -print0 2> /dev/null)
# Audio Plug-Ins
while IFS= read -r -d '' plugin; do
files_to_clean+=("$plugin")
done < <(find ~/Library/Audio/Plug-Ins \( -name "$app_name*" -o -name "$bundle_id*" \) -print0 2> /dev/null)
# Components
while IFS= read -r -d '' component; do
files_to_clean+=("$component")
done < <(find ~/Library/Components \( -name "$app_name*" -o -name "$bundle_id*" \) -print0 2> /dev/null)
# Metadata
while IFS= read -r -d '' metadata; do
files_to_clean+=("$metadata")
done < <(find ~/Library/Metadata \( -name "$app_name*" -o -name "$bundle_id*" \) -print0 2> /dev/null)
# Workflows
[[ -d ~/Library/Workflows/"$app_name".workflow ]] && files_to_clean+=("$HOME/Library/Workflows/$app_name.workflow")
while IFS= read -r -d '' workflow; do
files_to_clean+=("$workflow")
done < <(find ~/Library/Workflows \( -name "$app_name*" -o -name "$bundle_id*" \) -print0 2> /dev/null)
# Favorites (excluding Safari)
while IFS= read -r -d '' favorite; do
# Skip Safari favorites
case "$favorite" in
*Safari*) continue ;;
esac
files_to_clean+=("$favorite")
done < <(find ~/Library/Favorites \( -name "$app_name*" -o -name "$bundle_id*" \) -print0 2> /dev/null)
# Only print if array has elements to avoid unbound variable error
if [[ ${#files_to_clean[@]} -gt 0 ]]; then
printf '%s\n' "${files_to_clean[@]}"
@@ -1704,6 +1746,21 @@ find_app_system_files() {
[[ -d /Library/Caches/"$bundle_id" ]] && system_files+=("/Library/Caches/$bundle_id")
[[ -d /Library/Caches/"$app_name" ]] && system_files+=("/Library/Caches/$app_name")
# System Audio Plug-Ins
while IFS= read -r -d '' plugin; do
system_files+=("$plugin")
done < <(find /Library/Audio/Plug-Ins \( -name "$app_name*" -o -name "$bundle_id*" \) -print0 2> /dev/null)
# System Components
while IFS= read -r -d '' component; do
system_files+=("$component")
done < <(find /Library/Components \( -name "$app_name*" -o -name "$bundle_id*" \) -print0 2> /dev/null)
# System Extensions
while IFS= read -r -d '' extension; do
system_files+=("$extension")
done < <(find /Library/Extensions \( -name "$app_name*" -o -name "$bundle_id*" \) -print0 2> /dev/null)
# Only print if array has elements
if [[ ${#system_files[@]} -gt 0 ]]; then
printf '%s\n' "${system_files[@]}"

View File

@@ -7,17 +7,41 @@ set -euo pipefail
format_app_display() {
local display_name="$1" size="$2" last_used="$3"
# Truncate long names
# Compact last-used wording to keep column width tidy
local compact_last_used
case "$last_used" in
"" | "Unknown") compact_last_used="Unknown" ;;
"Never" | "Recent" | "Today" | "Yesterday" | "This year" | "Old") compact_last_used="$last_used" ;;
*)
if [[ $last_used =~ ^([0-9]+)[[:space:]]+days?\ ago$ ]]; then
compact_last_used="${BASH_REMATCH[1]}d ago"
elif [[ $last_used =~ ^([0-9]+)[[:space:]]+weeks?\ ago$ ]]; then
compact_last_used="${BASH_REMATCH[1]}w ago"
elif [[ $last_used =~ ^([0-9]+)[[:space:]]+months?\ ago$ ]]; then
compact_last_used="${BASH_REMATCH[1]}m ago"
elif [[ $last_used =~ ^([0-9]+)[[:space:]]+month\(s\)\ ago$ ]]; then
compact_last_used="${BASH_REMATCH[1]}m ago"
elif [[ $last_used =~ ^([0-9]+)[[:space:]]+years?\ ago$ ]]; then
compact_last_used="${BASH_REMATCH[1]}y ago"
else
compact_last_used="$last_used"
fi
;;
esac
# Truncate long names with consistent width
local truncated_name="$display_name"
if [[ ${#display_name} -gt 24 ]]; then
truncated_name="${display_name:0:21}..."
if [[ ${#display_name} -gt 22 ]]; then
truncated_name="${display_name:0:19}..."
fi
# Format size
local size_str="Unknown"
[[ "$size" != "0" && "$size" != "" && "$size" != "Unknown" ]] && size_str="$size"
printf "%-24s (%s) | %s" "$truncated_name" "$size_str" "$last_used"
# Use consistent column widths for perfect alignment:
# name column (22), right-aligned size column (9), then compact last-used value.
printf "%-22s %9s | %s" "$truncated_name" "$size_str" "$compact_last_used"
}
# Global variable to store selection result (bash 3.2 compatible)