diff --git a/lib/clean/apps.sh b/lib/clean/apps.sh index 11d064c..1f67ab2 100644 --- a/lib/clean/apps.sh +++ b/lib/clean/apps.sh @@ -33,7 +33,7 @@ clean_ds_store_tree() { local size size=$(get_file_size "$ds_file") total_bytes=$((total_bytes + size)) - ((file_count++)) + ((file_count++)) || true if [[ "$DRY_RUN" != "true" ]]; then rm -f "$ds_file" 2> /dev/null || true fi @@ -53,9 +53,9 @@ clean_ds_store_tree() { echo -e " ${GREEN}${ICON_SUCCESS}${NC} $label${NC}, ${GREEN}$file_count files, $size_human${NC}" fi local size_kb=$(((total_bytes + 1023) / 1024)) - ((files_cleaned += file_count)) - ((total_size_cleaned += size_kb)) - ((total_items++)) + ((files_cleaned += file_count)) || true + ((total_size_cleaned += size_kb)) || true + ((total_items++)) || true note_activity fi } @@ -113,12 +113,12 @@ scan_installed_apps() { local bundle_id=$(/usr/libexec/PlistBuddy -c "Print :CFBundleIdentifier" "$plist_path" 2> /dev/null || echo "") if [[ -n "$bundle_id" ]]; then echo "$bundle_id" - ((count++)) + ((count++)) || true fi done ) > "$scan_tmp_dir/apps_${dir_idx}.txt" & pids+=($!) - ((dir_idx++)) + ((dir_idx++)) || true done # Collect running apps and LaunchAgents to avoid false orphan cleanup. ( @@ -300,7 +300,7 @@ clean_orphaned_app_data() { fi for match in "${matches[@]}"; do [[ -e "$match" ]] || continue - ((iteration_count++)) + ((iteration_count++)) || true if [[ $iteration_count -gt $MOLE_MAX_ORPHAN_ITERATIONS ]]; then break fi @@ -314,8 +314,8 @@ clean_orphaned_app_data() { continue fi if safe_clean "$match" "Orphaned $label: $bundle_id"; then - ((orphaned_count++)) - ((total_orphaned_kb += size_kb)) + ((orphaned_count++)) || true + ((total_orphaned_kb += size_kb)) || true fi fi done @@ -430,8 +430,8 @@ clean_orphaned_system_services() { orphaned_files+=("$plist") local size_kb size_kb=$(sudo du -skP "$plist" 2> /dev/null | awk '{print $1}' || echo "0") - ((total_orphaned_kb += size_kb)) - ((orphaned_count++)) + ((total_orphaned_kb += size_kb)) || true + ((orphaned_count++)) || true break fi done @@ -461,8 +461,8 @@ clean_orphaned_system_services() { orphaned_files+=("$plist") local size_kb size_kb=$(sudo du -skP "$plist" 2> /dev/null | awk '{print $1}' || echo "0") - ((total_orphaned_kb += size_kb)) - ((orphaned_count++)) + ((total_orphaned_kb += size_kb)) || true + ((orphaned_count++)) || true break fi done @@ -491,8 +491,8 @@ clean_orphaned_system_services() { orphaned_files+=("$helper") local size_kb size_kb=$(sudo du -skP "$helper" 2> /dev/null | awk '{print $1}' || echo "0") - ((total_orphaned_kb += size_kb)) - ((orphaned_count++)) + ((total_orphaned_kb += size_kb)) || true + ((orphaned_count++)) || true break fi done @@ -673,7 +673,7 @@ clean_orphaned_launch_agents() { if is_launch_item_orphaned "$plist"; then local size_kb=$(get_path_size_kb "$plist") orphaned_items+=("$bundle_id|$plist") - ((total_orphaned_kb += size_kb)) + ((total_orphaned_kb += size_kb)) || true fi done < <(find "$launch_agents_dir" -maxdepth 1 -name "*.plist" -print0 2> /dev/null) @@ -696,7 +696,7 @@ clean_orphaned_launch_agents() { IFS='|' read -r bundle_id plist_path <<< "$item" if [[ "$is_dry_run" == "true" ]]; then - ((dry_run_count++)) + ((dry_run_count++)) || true log_operation "clean" "DRY_RUN" "$plist_path" "orphaned launch agent" continue fi @@ -706,7 +706,7 @@ clean_orphaned_launch_agents() { # Remove the plist file if safe_remove "$plist_path" false; then - ((removed_count++)) + ((removed_count++)) || true log_operation "clean" "REMOVED" "$plist_path" "orphaned launch agent" else log_operation "clean" "FAILED" "$plist_path" "permission denied" diff --git a/lib/clean/caches.sh b/lib/clean/caches.sh index c0ecdb5..8918789 100644 --- a/lib/clean/caches.sh +++ b/lib/clean/caches.sh @@ -208,7 +208,7 @@ clean_project_caches() { break fi sleep 0.1 - ((grace_period++)) + ((grace_period++)) || true done if kill -0 "$pid" 2> /dev/null; then kill -KILL "$pid" 2> /dev/null || true diff --git a/lib/clean/dev.sh b/lib/clean/dev.sh index 83234e2..770e424 100644 --- a/lib/clean/dev.sh +++ b/lib/clean/dev.sh @@ -259,11 +259,11 @@ clean_xcode_documentation_cache() { local entry for entry in "${sorted_entries[@]}"; do if [[ $idx -eq 0 ]]; then - ((idx++)) + ((idx++)) || true continue fi stale_entries+=("$entry") - ((idx++)) + ((idx++)) || true done if [[ ${#stale_entries[@]} -eq 0 ]]; then @@ -729,12 +729,12 @@ clean_dev_jetbrains_toolbox() { local dir_path for dir_path in "${sorted_dirs[@]}"; do if [[ $idx -lt $keep_previous ]]; then - ((idx++)) + ((idx++)) || true continue fi safe_clean "$dir_path" "JetBrains Toolbox old IDE version" note_activity - ((idx++)) + ((idx++)) || true done done < <(command find "$product_dir" -mindepth 1 -maxdepth 1 -type d -name "ch-*" -print0 2> /dev/null) done diff --git a/lib/clean/hints.sh b/lib/clean/hints.sh index 8f9f265..6b41bed 100644 --- a/lib/clean/hints.sh +++ b/lib/clean/hints.sh @@ -58,7 +58,7 @@ hint_get_path_size_kb_with_timeout() { record_project_artifact_hint() { local path="$1" - ((PROJECT_ARTIFACT_HINT_COUNT++)) + ((PROJECT_ARTIFACT_HINT_COUNT++)) || true if [[ ${#PROJECT_ARTIFACT_HINT_EXAMPLES[@]} -lt 2 ]]; then PROJECT_ARTIFACT_HINT_EXAMPLES+=("${path/#$HOME/~}") @@ -74,8 +74,8 @@ record_project_artifact_hint() { local size_kb="" if size_kb=$(hint_get_path_size_kb_with_timeout "$path" "$timeout_seconds"); then if [[ "$size_kb" =~ ^[0-9]+$ ]]; then - ((PROJECT_ARTIFACT_HINT_ESTIMATED_KB += size_kb)) - ((PROJECT_ARTIFACT_HINT_ESTIMATE_SAMPLES++)) + ((PROJECT_ARTIFACT_HINT_ESTIMATED_KB += size_kb)) || true + ((PROJECT_ARTIFACT_HINT_ESTIMATE_SAMPLES++)) || true else PROJECT_ARTIFACT_HINT_ESTIMATE_PARTIAL=true fi @@ -140,8 +140,8 @@ probe_project_artifact_hints() { local root_projects_scanned=0 if is_quick_purge_project_root "$root"; then - ((scanned_projects++)) - ((root_projects_scanned++)) + ((scanned_projects++)) || true + ((root_projects_scanned++)) || true if [[ $scanned_projects -gt $max_projects ]]; then PROJECT_ARTIFACT_HINT_TRUNCATED=true stop_scan=true @@ -175,8 +175,8 @@ probe_project_artifact_hints() { break fi - ((scanned_projects++)) - ((root_projects_scanned++)) + ((scanned_projects++)) || true + ((root_projects_scanned++)) || true if [[ $scanned_projects -gt $max_projects ]]; then PROJECT_ARTIFACT_HINT_TRUNCATED=true stop_scan=true @@ -206,7 +206,7 @@ probe_project_artifact_hints() { ;; esac - ((nested_count++)) + ((nested_count++)) || true if [[ $nested_count -gt $max_nested_per_project ]]; then break fi diff --git a/lib/clean/project.sh b/lib/clean/project.sh index 2f460cf..0539ccd 100644 --- a/lib/clean/project.sh +++ b/lib/clean/project.sh @@ -640,7 +640,7 @@ select_purge_categories() { for ((i = 0; i < total_items; i++)); do if [[ ${selected[i]} == true ]]; then selected_size=$((selected_size + ${sizes[i]:-0})) - ((selected_count++)) + ((selected_count++)) || true fi done @@ -728,9 +728,9 @@ select_purge_categories() { local visible_count=$((total_items - top_index)) [[ $visible_count -gt $items_per_page ]] && visible_count=$items_per_page if [[ $cursor_pos -lt $((visible_count - 1)) ]]; then - ((cursor_pos++)) + ((cursor_pos++)) || true elif [[ $((top_index + visible_count)) -lt $total_items ]]; then - ((top_index++)) + ((top_index++)) || true fi fi } @@ -1350,7 +1350,7 @@ clean_project_artifacts() { [[ "$selected_size_kb" =~ ^[0-9]+$ ]] || selected_size_kb=0 selected_total_kb=$((selected_total_kb + selected_size_kb)) if [[ "${item_size_unknown_flags[idx]:-false}" == "true" ]]; then - ((selected_unknown_count++)) + ((selected_unknown_count++)) || true fi done @@ -1391,7 +1391,7 @@ clean_project_artifacts() { if [[ ! -e "$item_path" ]]; then local current_total=$(cat "$stats_dir/purge_stats" 2> /dev/null || echo "0") echo "$((current_total + size_kb))" > "$stats_dir/purge_stats" - ((cleaned_count++)) + ((cleaned_count++)) || true fi fi if [[ -t 1 ]]; then diff --git a/lib/clean/system.sh b/lib/clean/system.sh index 9a8d664..51c8862 100644 --- a/lib/clean/system.sh +++ b/lib/clean/system.sh @@ -86,7 +86,7 @@ clean_deep_system() { continue fi if safe_sudo_remove "$item"; then - ((updates_cleaned++)) + ((updates_cleaned++)) || true fi done < <(find /Library/Updates -mindepth 1 -maxdepth 1 -print0 2> /dev/null || true) stop_section_spinner @@ -143,7 +143,7 @@ clean_deep_system() { debug_log "Cleaning macOS installer: $app_name, $size_human, ${age_days} days old" if safe_sudo_remove "$installer_app"; then log_success "$app_name, $size_human" - ((installer_cleaned++)) + ((installer_cleaned++)) || true fi fi done @@ -153,7 +153,7 @@ clean_deep_system() { local code_sign_cleaned=0 while IFS= read -r -d '' cache_dir; do if safe_sudo_remove "$cache_dir"; then - ((code_sign_cleaned++)) + ((code_sign_cleaned++)) || true fi done < <(run_with_timeout 5 command find /private/var/folders -type d -name "*.code_sign_clone" -path "*/X/*" -print0 2> /dev/null || true) stop_section_spinner @@ -300,7 +300,7 @@ clean_time_machine_failed_backups() { size_human=$(bytes_to_human "$((size_kb * 1024))") if [[ "$DRY_RUN" == "true" ]]; then echo -e " ${YELLOW}${ICON_DRY_RUN}${NC} Incomplete backup: $backup_name${NC}, ${YELLOW}$size_human dry${NC}" - ((tm_cleaned++)) + ((tm_cleaned++)) || true note_activity continue fi @@ -310,10 +310,10 @@ clean_time_machine_failed_backups() { fi if tmutil delete "$inprogress_file" 2> /dev/null; then echo -e " ${GREEN}${ICON_SUCCESS}${NC} Incomplete backup: $backup_name${NC}, ${GREEN}$size_human${NC}" - ((tm_cleaned++)) - ((files_cleaned++)) - ((total_size_cleaned += size_kb)) - ((total_items++)) + ((tm_cleaned++)) || true + ((files_cleaned++)) || true + ((total_size_cleaned += size_kb)) || true + ((total_items++)) || true note_activity else echo -e " ${YELLOW}!${NC} Could not delete: $backup_name · try manually with sudo" @@ -352,7 +352,7 @@ clean_time_machine_failed_backups() { size_human=$(bytes_to_human "$((size_kb * 1024))") if [[ "$DRY_RUN" == "true" ]]; then echo -e " ${YELLOW}${ICON_DRY_RUN}${NC} Incomplete APFS backup in $bundle_name: $backup_name${NC}, ${YELLOW}$size_human dry${NC}" - ((tm_cleaned++)) + ((tm_cleaned++)) || true note_activity continue fi @@ -361,10 +361,10 @@ clean_time_machine_failed_backups() { fi if tmutil delete "$inprogress_file" 2> /dev/null; then echo -e " ${GREEN}${ICON_SUCCESS}${NC} Incomplete APFS backup in $bundle_name: $backup_name${NC}, ${GREEN}$size_human${NC}" - ((tm_cleaned++)) - ((files_cleaned++)) - ((total_size_cleaned += size_kb)) - ((total_items++)) + ((tm_cleaned++)) || true + ((files_cleaned++)) || true + ((total_size_cleaned += size_kb)) || true + ((total_items++)) || true note_activity else echo -e " ${YELLOW}!${NC} Could not delete from bundle: $backup_name" diff --git a/lib/clean/user.sh b/lib/clean/user.sh index 0a66ade..d7865de 100644 --- a/lib/clean/user.sh +++ b/lib/clean/user.sh @@ -23,7 +23,7 @@ clean_user_essentials() { local cleaned_count=0 while IFS= read -r -d '' item; do if safe_remove "$item" true; then - ((cleaned_count++)) + ((cleaned_count++)) || true fi done < <(command find "$HOME/.Trash" -mindepth 1 -maxdepth 1 -print0 2> /dev/null || true) if [[ $cleaned_count -gt 0 ]]; then @@ -100,8 +100,8 @@ _clean_mail_downloads() { local file_size_kb file_size_kb=$(get_path_size_kb "$file_path") if safe_remove "$file_path" true; then - ((count++)) - ((cleaned_kb += file_size_kb)) + ((count++)) || true + ((cleaned_kb += file_size_kb)) || true fi fi done < <(command find "$target_path" -type f -mtime +"$mail_age_days" -print0 2> /dev/null || true) @@ -171,7 +171,7 @@ clean_chrome_old_versions() { size_kb=$(get_path_size_kb "$dir" || echo 0) size_kb="${size_kb:-0}" total_size=$((total_size + size_kb)) - ((cleaned_count++)) + ((cleaned_count++)) || true cleaned_any=true if [[ "$DRY_RUN" != "true" ]]; then if has_sudo_session; then @@ -191,9 +191,9 @@ clean_chrome_old_versions() { else echo -e " ${GREEN}${ICON_SUCCESS}${NC} Chrome old versions${NC}, ${GREEN}${cleaned_count} dirs, $size_human${NC}" fi - ((files_cleaned += cleaned_count)) - ((total_size_cleaned += total_size)) - ((total_items++)) + ((files_cleaned += cleaned_count)) || true + ((total_size_cleaned += total_size)) || true + ((total_items++)) || true note_activity fi } @@ -257,7 +257,7 @@ clean_edge_old_versions() { size_kb=$(get_path_size_kb "$dir" || echo 0) size_kb="${size_kb:-0}" total_size=$((total_size + size_kb)) - ((cleaned_count++)) + ((cleaned_count++)) || true cleaned_any=true if [[ "$DRY_RUN" != "true" ]]; then if has_sudo_session; then @@ -277,9 +277,9 @@ clean_edge_old_versions() { else echo -e " ${GREEN}${ICON_SUCCESS}${NC} Edge old versions${NC}, ${GREEN}${cleaned_count} dirs, $size_human${NC}" fi - ((files_cleaned += cleaned_count)) - ((total_size_cleaned += total_size)) - ((total_items++)) + ((files_cleaned += cleaned_count)) || true + ((total_size_cleaned += total_size)) || true + ((total_items++)) || true note_activity fi } @@ -324,7 +324,7 @@ clean_edge_updater_old_versions() { size_kb=$(get_path_size_kb "$dir" || echo 0) size_kb="${size_kb:-0}" total_size=$((total_size + size_kb)) - ((cleaned_count++)) + ((cleaned_count++)) || true cleaned_any=true if [[ "$DRY_RUN" != "true" ]]; then safe_remove "$dir" true > /dev/null 2>&1 || true @@ -339,9 +339,9 @@ clean_edge_updater_old_versions() { else echo -e " ${GREEN}${ICON_SUCCESS}${NC} Edge updater old versions${NC}, ${GREEN}${cleaned_count} dirs, $size_human${NC}" fi - ((files_cleaned += cleaned_count)) - ((total_size_cleaned += total_size)) - ((total_items++)) + ((files_cleaned += cleaned_count)) || true + ((total_size_cleaned += total_size)) || true + ((total_items++)) || true note_activity fi } @@ -484,9 +484,9 @@ clean_app_caches() { else echo -e " ${GREEN}${ICON_SUCCESS}${NC} Sandboxed app caches${NC}, ${GREEN}$size_human${NC}" fi - ((files_cleaned += cleaned_count)) - ((total_size_cleaned += total_size)) - ((total_items++)) + ((files_cleaned += cleaned_count)) || true + ((total_size_cleaned += total_size)) || true + ((total_items++)) || true note_activity fi @@ -513,9 +513,9 @@ process_container_cache() { if find "$cache_dir" -mindepth 1 -maxdepth 1 -print -quit 2> /dev/null | grep -q .; then local size size=$(get_path_size_kb "$cache_dir") - ((total_size += size)) + ((total_size += size)) || true found_any=true - ((cleaned_count++)) + ((cleaned_count++)) || true if [[ "$DRY_RUN" != "true" ]]; then local item while IFS= read -r -d '' item; do @@ -613,7 +613,7 @@ clean_group_container_caches() { item_size=$(get_path_size_kb "$item" 2> /dev/null) || item_size=0 [[ "$item_size" =~ ^[0-9]+$ ]] || item_size=0 candidate_changed=true - ((candidate_size_kb += item_size)) + ((candidate_size_kb += item_size)) || true done else for item in "${items_to_clean[@]}"; do @@ -622,14 +622,14 @@ clean_group_container_caches() { [[ "$item_size" =~ ^[0-9]+$ ]] || item_size=0 if safe_remove "$item" true 2> /dev/null; then candidate_changed=true - ((candidate_size_kb += item_size)) + ((candidate_size_kb += item_size)) || true fi done fi if [[ "$candidate_changed" == "true" ]]; then - ((total_size += candidate_size_kb)) - ((cleaned_count++)) + ((total_size += candidate_size_kb)) || true + ((cleaned_count++)) || true found_any=true fi done @@ -645,9 +645,9 @@ clean_group_container_caches() { else echo -e " ${GREEN}${ICON_SUCCESS}${NC} Group Containers logs/caches${NC}, ${GREEN}$size_human${NC}" fi - ((files_cleaned += cleaned_count)) - ((total_size_cleaned += total_size)) - ((total_items++)) + ((files_cleaned += cleaned_count)) || true + ((total_size_cleaned += total_size)) || true + ((total_items++)) || true note_activity fi } @@ -951,9 +951,9 @@ clean_application_support_logs() { echo -e " ${GREEN}${ICON_SUCCESS}${NC} Application Support logs/caches${NC}, ${GREEN}$size_human${NC}" fi fi - ((files_cleaned += cleaned_count)) - ((total_size_cleaned += total_size_kb)) - ((total_items++)) + ((files_cleaned += cleaned_count)) || true + ((total_size_cleaned += total_size_kb)) || true + ((total_items++)) || true note_activity fi } diff --git a/lib/core/base.sh b/lib/core/base.sh index e11c7f8..805f29a 100644 --- a/lib/core/base.sh +++ b/lib/core/base.sh @@ -878,18 +878,18 @@ validate_terminal_environment() { # Check if TERM is set if [[ -z "${TERM:-}" ]]; then log_warning "TERM environment variable not set" - ((warnings++)) + ((warnings++)) || true fi # Check if running in a known problematic terminal case "${TERM:-}" in dumb) log_warning "Running in 'dumb' terminal, limited functionality" - ((warnings++)) + ((warnings++)) || true ;; unknown) log_warning "Terminal type unknown, may have display issues" - ((warnings++)) + ((warnings++)) || true ;; esac @@ -898,7 +898,7 @@ validate_terminal_environment() { local cols=$(tput cols 2> /dev/null || echo "80") if [[ "$cols" -lt 60 ]]; then log_warning "Terminal width, $cols cols, is narrow, output may wrap" - ((warnings++)) + ((warnings++)) || true fi fi diff --git a/lib/core/common.sh b/lib/core/common.sh index d89b448..e39c2df 100755 --- a/lib/core/common.sh +++ b/lib/core/common.sh @@ -163,7 +163,7 @@ remove_apps_from_dock() { local url url=$(/usr/libexec/PlistBuddy -c "Print :persistent-apps:$i:tile-data:file-data:_CFURLString" "$plist" 2> /dev/null || echo "") [[ -z "$url" ]] && { - ((i++)) + ((i++)) || true continue } @@ -175,7 +175,7 @@ remove_apps_from_dock() { continue fi fi - ((i++)) + ((i++)) || true done done diff --git a/lib/core/file_ops.sh b/lib/core/file_ops.sh index 4f90cea..dbe259b 100644 --- a/lib/core/file_ops.sh +++ b/lib/core/file_ops.sh @@ -536,7 +536,7 @@ calculate_total_size() { if [[ -n "$file" && -e "$file" ]]; then local size_kb size_kb=$(get_path_size_kb "$file") - ((total_kb += size_kb)) + ((total_kb += size_kb)) || true fi done <<< "$files" diff --git a/lib/core/sudo.sh b/lib/core/sudo.sh index d7de287..e27240f 100644 --- a/lib/core/sudo.sh +++ b/lib/core/sudo.sh @@ -76,7 +76,7 @@ _request_password() { if [[ -z "$password" ]]; then unset password - ((attempts++)) + ((attempts++)) || true if [[ $attempts -lt 3 ]]; then echo -e "${GRAY}${ICON_WARNING}${NC} Password cannot be empty" > "$tty_path" fi @@ -91,7 +91,7 @@ _request_password() { fi unset password - ((attempts++)) + ((attempts++)) || true if [[ $attempts -lt 3 ]]; then echo -e "${GRAY}${ICON_WARNING}${NC} Incorrect password, try again" > "$tty_path" fi @@ -166,7 +166,7 @@ request_sudo_access() { break fi sleep 0.1 - ((elapsed++)) + ((elapsed++)) || true done # Touch ID failed/cancelled - clean up thoroughly before password input @@ -216,7 +216,7 @@ _start_sudo_keepalive() { local retry_count=0 while true; do if ! sudo -n -v 2> /dev/null; then - ((retry_count++)) + ((retry_count++)) || true if [[ $retry_count -ge 3 ]]; then exit 1 fi diff --git a/lib/core/ui.sh b/lib/core/ui.sh index 2834091..c5ba761 100755 --- a/lib/core/ui.sh +++ b/lib/core/ui.sh @@ -138,8 +138,8 @@ truncate_by_display_width() { fi truncated+="$char" - ((width += char_width)) - ((i++)) + ((width += char_width)) || true + ((i++)) || true done # Restore locale @@ -265,7 +265,7 @@ read_key() { drain_pending_input() { local drained=0 while IFS= read -r -s -n 1 -t 0.01 _ 2> /dev/null; do - ((drained++)) + ((drained++)) || true [[ $drained -gt 100 ]] && break done } @@ -341,7 +341,7 @@ start_inline_spinner() { local c="${chars:$((i % ${#chars})):1}" # Output to stderr to avoid interfering with stdout printf "\r${MOLE_SPINNER_PREFIX:-}${BLUE}%s${NC} %s" "$c" "$display_message" >&2 || break - ((i++)) + ((i++)) || true sleep 0.05 done @@ -367,7 +367,7 @@ stop_inline_spinner() { local wait_count=0 while kill -0 "$INLINE_SPINNER_PID" 2> /dev/null && [[ $wait_count -lt 5 ]]; do sleep 0.05 2> /dev/null || true - ((wait_count++)) + ((wait_count++)) || true done # Only use SIGKILL as last resort if process is stuck diff --git a/lib/manage/autofix.sh b/lib/manage/autofix.sh index 4096c00..b3aea66 100644 --- a/lib/manage/autofix.sh +++ b/lib/manage/autofix.sh @@ -138,7 +138,7 @@ perform_auto_fix() { echo -e "${BLUE}Enabling Firewall...${NC}" if sudo /usr/libexec/ApplicationFirewall/socketfilterfw --setglobalstate on > /dev/null 2>&1; then echo -e "${GREEN}✓${NC} Firewall enabled" - ((fixed_count++)) + ((fixed_count++)) || true fixed_items+=("Firewall enabled") else echo -e "${RED}✗${NC} Failed to enable Firewall" @@ -154,7 +154,7 @@ perform_auto_fix() { auth sufficient pam_tid.so ' '$pam_file'" 2> /dev/null; then echo -e "${GREEN}✓${NC} Touch ID configured" - ((fixed_count++)) + ((fixed_count++)) || true fixed_items+=("Touch ID configured for sudo") else echo -e "${RED}✗${NC} Failed to configure Touch ID" @@ -167,7 +167,7 @@ auth sufficient pam_tid.so echo -e "${BLUE}Installing Rosetta 2...${NC}" if sudo softwareupdate --install-rosetta --agree-to-license 2>&1 | grep -qE "(Installing|Installed|already installed)"; then echo -e "${GREEN}✓${NC} Rosetta 2 installed" - ((fixed_count++)) + ((fixed_count++)) || true fixed_items+=("Rosetta 2 installed") else echo -e "${RED}✗${NC} Failed to install Rosetta 2" diff --git a/lib/manage/purge_paths.sh b/lib/manage/purge_paths.sh index 89f8517..473b229 100644 --- a/lib/manage/purge_paths.sh +++ b/lib/manage/purge_paths.sh @@ -70,7 +70,7 @@ manage_purge_paths() { line="${line#"${line%%[![:space:]]*}"}" line="${line%"${line##*[![:space:]]}"}" [[ -z "$line" || "$line" =~ ^# ]] && continue - ((custom_count++)) + ((custom_count++)) || true done < "$PURGE_PATHS_CONFIG" fi diff --git a/lib/manage/update.sh b/lib/manage/update.sh index bab206e..8f417e8 100644 --- a/lib/manage/update.sh +++ b/lib/manage/update.sh @@ -117,7 +117,7 @@ perform_updates() { if "$mole_bin" update 2>&1 | grep -qE "(Updated|latest version)"; then echo -e "${GREEN}${ICON_SUCCESS}${NC} Mole updated" reset_mole_cache - ((updated_count++)) + ((updated_count++)) || true else echo -e "${RED}✗${NC} Mole update failed" fi diff --git a/lib/optimize/tasks.sh b/lib/optimize/tasks.sh index 6260263..738cd87 100644 --- a/lib/optimize/tasks.sh +++ b/lib/optimize/tasks.sh @@ -314,7 +314,7 @@ opt_sqlite_vacuum() { local file_size file_size=$(get_file_size "$db_file") if [[ "$file_size" -gt "$MOLE_SQLITE_MAX_SIZE" ]]; then - ((skipped++)) + ((skipped++)) || true continue fi @@ -327,7 +327,7 @@ opt_sqlite_vacuum() { freelist_count=$(echo "$page_info" | awk 'NR==2 {print $1}' 2> /dev/null || echo "") if [[ "$page_count" =~ ^[0-9]+$ && "$freelist_count" =~ ^[0-9]+$ && "$page_count" -gt 0 ]]; then if ((freelist_count * 100 < page_count * 5)); then - ((skipped++)) + ((skipped++)) || true continue fi fi @@ -341,7 +341,7 @@ opt_sqlite_vacuum() { set -e if [[ $integrity_status -ne 0 ]] || ! echo "$integrity_check" | grep -q "ok"; then - ((skipped++)) + ((skipped++)) || true continue fi fi @@ -354,14 +354,14 @@ opt_sqlite_vacuum() { set -e if [[ $exit_code -eq 0 ]]; then - ((vacuumed++)) + ((vacuumed++)) || true elif [[ $exit_code -eq 124 ]]; then - ((timed_out++)) + ((timed_out++)) || true else - ((failed++)) + ((failed++)) || true fi else - ((vacuumed++)) + ((vacuumed++)) || true fi done < <(compgen -G "$pattern" || true) done @@ -730,7 +730,7 @@ opt_spotlight_index_optimize() { test_end=$(get_epoch_seconds) test_duration=$((test_end - test_start)) if [[ $test_duration -gt 3 ]]; then - ((slow_count++)) + ((slow_count++)) || true fi sleep 1 done diff --git a/lib/ui/app_selector.sh b/lib/ui/app_selector.sh index 35610be..a5e4fbc 100755 --- a/lib/ui/app_selector.sh +++ b/lib/ui/app_selector.sh @@ -133,7 +133,7 @@ select_apps_for_uninstall() { sizekb_csv+=",${size_kb:-0}" fi names_arr+=("$display_name") - ((idx++)) + ((idx++)) || true done # Use newline separator for names (safe for names with commas) local names_newline diff --git a/lib/ui/menu_paginated.sh b/lib/ui/menu_paginated.sh index 3ef9adc..982a7e8 100755 --- a/lib/ui/menu_paginated.sh +++ b/lib/ui/menu_paginated.sh @@ -155,7 +155,7 @@ paginated_multi_select() { # Only count if not already selected (handles duplicates) if [[ ${selected[idx]} != true ]]; then selected[idx]=true - ((selected_count++)) + ((selected_count++)) || true fi fi done @@ -654,7 +654,7 @@ paginated_multi_select() { if [[ $cursor_pos -lt $((visible_count - 1)) ]]; then local old_cursor=$cursor_pos - ((cursor_pos++)) + ((cursor_pos++)) || true local new_cursor=$cursor_pos if [[ -n "$filter_text" || -n "${MOLE_READ_KEY_FORCE_CHAR:-}" ]]; then @@ -674,7 +674,7 @@ paginated_multi_select() { prev_cursor_pos=$cursor_pos continue elif [[ $((top_index + visible_count)) -lt ${#view_indices[@]} ]]; then - ((top_index++)) + ((top_index++)) || true visible_count=$((${#view_indices[@]} - top_index)) [[ $visible_count -gt $items_per_page ]] && visible_count=$items_per_page if [[ $cursor_pos -ge $visible_count ]]; then @@ -716,7 +716,7 @@ paginated_multi_select() { ((selected_count--)) else selected[real]=true - ((selected_count++)) + ((selected_count++)) || true fi # Incremental update: only redraw header (for count) and current row @@ -757,9 +757,9 @@ paginated_multi_select() { local visible_count=$((${#view_indices[@]} - top_index)) [[ $visible_count -gt $items_per_page ]] && visible_count=$items_per_page if [[ $cursor_pos -lt $((visible_count - 1)) ]]; then - ((cursor_pos++)) + ((cursor_pos++)) || true elif [[ $((top_index + visible_count)) -lt ${#view_indices[@]} ]]; then - ((top_index++)) + ((top_index++)) || true fi need_full_redraw=true fi @@ -843,7 +843,7 @@ paginated_multi_select() { if [[ $idx -lt ${#view_indices[@]} ]]; then local real="${view_indices[idx]}" selected[real]=true - ((selected_count++)) + ((selected_count++)) || true fi fi diff --git a/lib/ui/menu_simple.sh b/lib/ui/menu_simple.sh index f384024..09f503a 100755 --- a/lib/ui/menu_simple.sh +++ b/lib/ui/menu_simple.sh @@ -159,7 +159,7 @@ paginated_multi_select() { # Count selections for header display local selected_count=0 for ((i = 0; i < total_items; i++)); do - [[ ${selected[i]} == true ]] && ((selected_count++)) + [[ ${selected[i]} == true ]] && ((selected_count++)) || true done # Header @@ -247,9 +247,9 @@ paginated_multi_select() { [[ $visible_count -gt $items_per_page ]] && visible_count=$items_per_page if [[ $cursor_pos -lt $((visible_count - 1)) ]]; then - ((cursor_pos++)) + ((cursor_pos++)) || true elif [[ $((top_index + visible_count)) -lt $total_items ]]; then - ((top_index++)) + ((top_index++)) || true visible_count=$((total_items - top_index)) [[ $visible_count -gt $items_per_page ]] && visible_count=$items_per_page if [[ $cursor_pos -ge $visible_count ]]; then diff --git a/lib/uninstall/batch.sh b/lib/uninstall/batch.sh index 597b9dc..4cc185d 100755 --- a/lib/uninstall/batch.sh +++ b/lib/uninstall/batch.sh @@ -465,7 +465,7 @@ batch_uninstall_applications() { local -a success_items=() local current_index=0 for detail in "${app_details[@]}"; do - ((current_index++)) + ((current_index++)) || true IFS='|' read -r app_name app_path bundle_id total_kb encoded_files encoded_system_files has_sensitive_data needs_sudo is_brew_cask cask_name encoded_diag_system <<< "$detail" local related_files=$(decode_file_list "$encoded_files" "$app_name") local system_files=$(decode_file_list "$encoded_system_files" "$app_name") @@ -610,11 +610,11 @@ batch_uninstall_applications() { fi fi - ((total_size_freed += total_kb)) - ((success_count++)) - [[ "$used_brew_successfully" == "true" ]] && ((brew_apps_removed++)) - ((files_cleaned++)) - ((total_items++)) + ((total_size_freed += total_kb)) || true + ((success_count++)) || true + [[ "$used_brew_successfully" == "true" ]] && ((brew_apps_removed++)) || true + ((files_cleaned++)) || true + ((total_items++)) || true success_items+=("$app_path") else if [[ -t 1 ]]; then @@ -628,7 +628,7 @@ batch_uninstall_applications() { fi fi - ((failed_count++)) + ((failed_count++)) || true failed_items+=("$app_name:$reason:${suggestion:-}") fi done @@ -672,7 +672,7 @@ batch_uninstall_applications() { else current_line="$current_line, $display_item" fi - ((idx++)) + ((idx++)) || true done if [[ -n "$current_line" ]]; then summary_details+=("$current_line") @@ -765,6 +765,6 @@ batch_uninstall_applications() { _restore_uninstall_traps unset -f _restore_uninstall_traps - ((total_size_cleaned += total_size_freed)) + ((total_size_cleaned += total_size_freed)) || true unset failed_items } diff --git a/test_rounding.sh b/test_rounding.sh new file mode 100755 index 0000000..a52d6ec --- /dev/null +++ b/test_rounding.sh @@ -0,0 +1,17 @@ +bytes_to_human_new() { + local bytes="$1" + if ((bytes >= 1000000000)); then + local scaled=$(( (bytes * 100 + 500000000) / 1000000000 )) + printf "%d.%02dGB\n" $((scaled / 100)) $((scaled % 100)) + elif ((bytes >= 1000000)); then + local scaled=$(( (bytes * 10 + 500000) / 1000000 )) + printf "%d.%01dMB\n" $((scaled / 10)) $((scaled % 10)) + elif ((bytes >= 1000)); then + printf "%dKB\n" $(((bytes + 500) / 1000)) + else + printf "%dB\n" "$bytes" + fi +} +bytes_to_human_new 12187977120 +bytes_to_human_new 12999000000 +bytes_to_human_new 36281810