From c19a0276b8752664bd33aef5596d87dc905f4cb8 Mon Sep 17 00:00:00 2001 From: tw93 Date: Sat, 28 Feb 2026 11:10:18 +0800 Subject: [PATCH] refactor: Update shell arithmetic increment syntax from `((var++)) || true` to `var=$((var + 1))` across various scripts. --- lib/clean/apps.sh | 36 ++++++++--------- lib/clean/caches.sh | 2 +- lib/clean/dev.sh | 8 ++-- lib/clean/hints.sh | 16 ++++---- lib/clean/project.sh | 10 ++--- lib/clean/system.sh | 26 ++++++------- lib/clean/user.sh | 78 ++++++++++++++++++------------------- lib/core/base.sh | 8 ++-- lib/core/common.sh | 4 +- lib/core/file_ops.sh | 2 +- lib/core/sudo.sh | 8 ++-- lib/core/ui.sh | 10 ++--- lib/manage/autofix.sh | 6 +-- lib/manage/purge_paths.sh | 2 +- lib/manage/update.sh | 2 +- lib/manage/whitelist.sh | 2 +- lib/optimize/maintenance.sh | 4 +- lib/optimize/tasks.sh | 16 ++++---- lib/ui/app_selector.sh | 2 +- lib/ui/menu_paginated.sh | 14 +++---- lib/ui/menu_simple.sh | 6 +-- lib/uninstall/batch.sh | 20 +++++----- 22 files changed, 141 insertions(+), 141 deletions(-) diff --git a/lib/clean/apps.sh b/lib/clean/apps.sh index 1f67ab2..ccdea20 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++)) || true + file_count=$((file_count + 1)) 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)) || true - ((total_size_cleaned += size_kb)) || true - ((total_items++)) || true + files_cleaned=$((files_cleaned + file_count)) + total_size_cleaned=$((total_size_cleaned + size_kb)) + total_items=$((total_items + 1)) 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++)) || true + count=$((count + 1)) fi done ) > "$scan_tmp_dir/apps_${dir_idx}.txt" & pids+=($!) - ((dir_idx++)) || true + dir_idx=$((dir_idx + 1)) 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++)) || true + iteration_count=$((iteration_count + 1)) 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++)) || true - ((total_orphaned_kb += size_kb)) || true + orphaned_count=$((orphaned_count + 1)) + total_orphaned_kb=$((total_orphaned_kb + size_kb)) 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)) || true - ((orphaned_count++)) || true + total_orphaned_kb=$((total_orphaned_kb + size_kb)) + orphaned_count=$((orphaned_count + 1)) 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)) || true - ((orphaned_count++)) || true + total_orphaned_kb=$((total_orphaned_kb + size_kb)) + orphaned_count=$((orphaned_count + 1)) 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)) || true - ((orphaned_count++)) || true + total_orphaned_kb=$((total_orphaned_kb + size_kb)) + orphaned_count=$((orphaned_count + 1)) 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)) || true + total_orphaned_kb=$((total_orphaned_kb + size_kb)) 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++)) || true + dry_run_count=$((dry_run_count + 1)) 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++)) || true + removed_count=$((removed_count + 1)) 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 8918789..f9361b4 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++)) || true + grace_period=$((grace_period + 1)) 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 770e424..c52a11b 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++)) || true + idx=$((idx + 1)) continue fi stale_entries+=("$entry") - ((idx++)) || true + idx=$((idx + 1)) 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++)) || true + idx=$((idx + 1)) continue fi safe_clean "$dir_path" "JetBrains Toolbox old IDE version" note_activity - ((idx++)) || true + idx=$((idx + 1)) 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 6b41bed..f6538bf 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++)) || true + PROJECT_ARTIFACT_HINT_COUNT=$((PROJECT_ARTIFACT_HINT_COUNT + 1)) 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)) || true - ((PROJECT_ARTIFACT_HINT_ESTIMATE_SAMPLES++)) || true + PROJECT_ARTIFACT_HINT_ESTIMATED_KB=$((PROJECT_ARTIFACT_HINT_ESTIMATED_KB + size_kb)) + PROJECT_ARTIFACT_HINT_ESTIMATE_SAMPLES=$((PROJECT_ARTIFACT_HINT_ESTIMATE_SAMPLES + 1)) 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++)) || true - ((root_projects_scanned++)) || true + scanned_projects=$((scanned_projects + 1)) + root_projects_scanned=$((root_projects_scanned + 1)) 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++)) || true - ((root_projects_scanned++)) || true + scanned_projects=$((scanned_projects + 1)) + root_projects_scanned=$((root_projects_scanned + 1)) 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++)) || true + nested_count=$((nested_count + 1)) if [[ $nested_count -gt $max_nested_per_project ]]; then break fi diff --git a/lib/clean/project.sh b/lib/clean/project.sh index 0539ccd..67e117b 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++)) || true + selected_count=$((selected_count + 1)) 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++)) || true + cursor_pos=$((cursor_pos + 1)) elif [[ $((top_index + visible_count)) -lt $total_items ]]; then - ((top_index++)) || true + top_index=$((top_index + 1)) 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++)) || true + selected_unknown_count=$((selected_unknown_count + 1)) 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++)) || true + cleaned_count=$((cleaned_count + 1)) fi fi if [[ -t 1 ]]; then diff --git a/lib/clean/system.sh b/lib/clean/system.sh index 51c8862..817964e 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++)) || true + updates_cleaned=$((updates_cleaned + 1)) 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++)) || true + installer_cleaned=$((installer_cleaned + 1)) 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++)) || true + code_sign_cleaned=$((code_sign_cleaned + 1)) 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++)) || true + tm_cleaned=$((tm_cleaned + 1)) 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++)) || true - ((files_cleaned++)) || true - ((total_size_cleaned += size_kb)) || true - ((total_items++)) || true + tm_cleaned=$((tm_cleaned + 1)) + files_cleaned=$((files_cleaned + 1)) + total_size_cleaned=$((total_size_cleaned + size_kb)) + total_items=$((total_items + 1)) 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++)) || true + tm_cleaned=$((tm_cleaned + 1)) 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++)) || true - ((files_cleaned++)) || true - ((total_size_cleaned += size_kb)) || true - ((total_items++)) || true + tm_cleaned=$((tm_cleaned + 1)) + files_cleaned=$((files_cleaned + 1)) + total_size_cleaned=$((total_size_cleaned + size_kb)) + total_items=$((total_items + 1)) 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 d7865de..c111bd5 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++)) || true + cleaned_count=$((cleaned_count + 1)) 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++)) || true - ((cleaned_kb += file_size_kb)) || true + count=$((count + 1)) + cleaned_kb=$((cleaned_kb + file_size_kb)) 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++)) || true + cleaned_count=$((cleaned_count + 1)) 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)) || true - ((total_size_cleaned += total_size)) || true - ((total_items++)) || true + files_cleaned=$((files_cleaned + cleaned_count)) + total_size_cleaned=$((total_size_cleaned + total_size)) + total_items=$((total_items + 1)) 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++)) || true + cleaned_count=$((cleaned_count + 1)) 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)) || true - ((total_size_cleaned += total_size)) || true - ((total_items++)) || true + files_cleaned=$((files_cleaned + cleaned_count)) + total_size_cleaned=$((total_size_cleaned + total_size)) + total_items=$((total_items + 1)) 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++)) || true + cleaned_count=$((cleaned_count + 1)) 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)) || true - ((total_size_cleaned += total_size)) || true - ((total_items++)) || true + files_cleaned=$((files_cleaned + cleaned_count)) + total_size_cleaned=$((total_size_cleaned + total_size)) + total_items=$((total_items + 1)) 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)) || true - ((total_size_cleaned += total_size)) || true - ((total_items++)) || true + files_cleaned=$((files_cleaned + cleaned_count)) + total_size_cleaned=$((total_size_cleaned + total_size)) + total_items=$((total_items + 1)) 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)) || true + total_size=$((total_size + size)) found_any=true - ((cleaned_count++)) || true + cleaned_count=$((cleaned_count + 1)) 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)) || true + candidate_size_kb=$((candidate_size_kb + item_size)) 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)) || true + candidate_size_kb=$((candidate_size_kb + item_size)) fi done fi if [[ "$candidate_changed" == "true" ]]; then - ((total_size += candidate_size_kb)) || true - ((cleaned_count++)) || true + total_size=$((total_size + candidate_size_kb)) + cleaned_count=$((cleaned_count + 1)) 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)) || true - ((total_size_cleaned += total_size)) || true - ((total_items++)) || true + files_cleaned=$((files_cleaned + cleaned_count)) + total_size_cleaned=$((total_size_cleaned + total_size)) + total_items=$((total_items + 1)) note_activity fi } @@ -808,7 +808,7 @@ clean_application_support_logs() { [[ -d "$app_dir" ]] || continue local app_name app_name=$(basename "$app_dir") - ((app_count++)) || true + app_count=$((app_count + 1)) update_progress_if_needed "$app_count" "$total_apps" last_progress_update 1 || true local app_name_lower app_name_lower=$(echo "$app_name" | LC_ALL=C tr '[:upper:]' '[:lower:]') @@ -834,12 +834,12 @@ clean_application_support_logs() { while IFS= read -r -d '' item; do [[ -e "$item" ]] || continue item_found=true - ((candidate_item_count++)) || true + candidate_item_count=$((candidate_item_count + 1)) if [[ ! -L "$item" && (-f "$item" || -d "$item") ]]; then local item_size_bytes="" if item_size_bytes=$(app_support_item_size_bytes "$item" "$size_timeout_seconds"); then if [[ "$item_size_bytes" =~ ^[0-9]+$ ]]; then - ((candidate_size_bytes += item_size_bytes)) || true + candidate_size_bytes=$((candidate_size_bytes + item_size_bytes)) else candidate_size_partial=true fi @@ -865,9 +865,9 @@ clean_application_support_logs() { fi done < <(command find "$candidate" -mindepth 1 -maxdepth 1 -print0 2> /dev/null || true) if [[ "$item_found" == "true" ]]; then - ((total_size_bytes += candidate_size_bytes)) || true + total_size_bytes=$((total_size_bytes + candidate_size_bytes)) [[ "$candidate_size_partial" == "true" ]] && total_size_partial=true - ((cleaned_count++)) || true + cleaned_count=$((cleaned_count + 1)) found_any=true fi fi @@ -889,12 +889,12 @@ clean_application_support_logs() { while IFS= read -r -d '' item; do [[ -e "$item" ]] || continue item_found=true - ((candidate_item_count++)) || true + candidate_item_count=$((candidate_item_count + 1)) if [[ ! -L "$item" && (-f "$item" || -d "$item") ]]; then local item_size_bytes="" if item_size_bytes=$(app_support_item_size_bytes "$item" "$size_timeout_seconds"); then if [[ "$item_size_bytes" =~ ^[0-9]+$ ]]; then - ((candidate_size_bytes += item_size_bytes)) || true + candidate_size_bytes=$((candidate_size_bytes + item_size_bytes)) else candidate_size_partial=true fi @@ -920,9 +920,9 @@ clean_application_support_logs() { fi done < <(command find "$candidate" -mindepth 1 -maxdepth 1 -print0 2> /dev/null || true) if [[ "$item_found" == "true" ]]; then - ((total_size_bytes += candidate_size_bytes)) || true + total_size_bytes=$((total_size_bytes + candidate_size_bytes)) [[ "$candidate_size_partial" == "true" ]] && total_size_partial=true - ((cleaned_count++)) || true + cleaned_count=$((cleaned_count + 1)) found_any=true fi 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)) || true - ((total_size_cleaned += total_size_kb)) || true - ((total_items++)) || true + files_cleaned=$((files_cleaned + cleaned_count)) + total_size_cleaned=$((total_size_cleaned + total_size_kb)) + total_items=$((total_items + 1)) note_activity fi } diff --git a/lib/core/base.sh b/lib/core/base.sh index 805f29a..16e9860 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++)) || true + warnings=$((warnings + 1)) fi # Check if running in a known problematic terminal case "${TERM:-}" in dumb) log_warning "Running in 'dumb' terminal, limited functionality" - ((warnings++)) || true + warnings=$((warnings + 1)) ;; unknown) log_warning "Terminal type unknown, may have display issues" - ((warnings++)) || true + warnings=$((warnings + 1)) ;; 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++)) || true + warnings=$((warnings + 1)) fi fi diff --git a/lib/core/common.sh b/lib/core/common.sh index e39c2df..38f7640 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++)) || true + i=$((i + 1)) continue } @@ -175,7 +175,7 @@ remove_apps_from_dock() { continue fi fi - ((i++)) || true + i=$((i + 1)) done done diff --git a/lib/core/file_ops.sh b/lib/core/file_ops.sh index dbe259b..9821fd5 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)) || true + total_kb=$((total_kb + size_kb)) fi done <<< "$files" diff --git a/lib/core/sudo.sh b/lib/core/sudo.sh index e27240f..fe1fb16 100644 --- a/lib/core/sudo.sh +++ b/lib/core/sudo.sh @@ -76,7 +76,7 @@ _request_password() { if [[ -z "$password" ]]; then unset password - ((attempts++)) || true + attempts=$((attempts + 1)) 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++)) || true + attempts=$((attempts + 1)) 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++)) || true + elapsed=$((elapsed + 1)) 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++)) || true + retry_count=$((retry_count + 1)) if [[ $retry_count -ge 3 ]]; then exit 1 fi diff --git a/lib/core/ui.sh b/lib/core/ui.sh index c5ba761..83d35eb 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)) || true - ((i++)) || true + width=$((width + char_width)) + i=$((i + 1)) 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++)) || true + drained=$((drained + 1)) [[ $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++)) || true + i=$((i + 1)) 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++)) || true + wait_count=$((wait_count + 1)) done # Only use SIGKILL as last resort if process is stuck diff --git a/lib/manage/autofix.sh b/lib/manage/autofix.sh index b3aea66..eb76fb4 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++)) || true + fixed_count=$((fixed_count + 1)) 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++)) || true + fixed_count=$((fixed_count + 1)) 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++)) || true + fixed_count=$((fixed_count + 1)) 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 473b229..aa34819 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++)) || true + custom_count=$((custom_count + 1)) done < "$PURGE_PATHS_CONFIG" fi diff --git a/lib/manage/update.sh b/lib/manage/update.sh index 8f417e8..5ab9863 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++)) || true + updated_count=$((updated_count + 1)) else echo -e "${RED}✗${NC} Mole update failed" fi diff --git a/lib/manage/whitelist.sh b/lib/manage/whitelist.sh index e322b6f..3424df7 100755 --- a/lib/manage/whitelist.sh +++ b/lib/manage/whitelist.sh @@ -302,7 +302,7 @@ ${GRAY}Edit: ${display_config}${NC}" cache_patterns+=("$pattern") menu_options+=("$display_name") - ((index++)) || true + index=$((index + 1)) done <<< "$items_source" # Identify custom patterns (not in predefined list) diff --git a/lib/optimize/maintenance.sh b/lib/optimize/maintenance.sh index c1f004c..a81c9cf 100644 --- a/lib/optimize/maintenance.sh +++ b/lib/optimize/maintenance.sh @@ -25,7 +25,7 @@ fix_broken_preferences() { plutil -lint "$plist_file" > /dev/null 2>&1 && continue safe_remove "$plist_file" true > /dev/null 2>&1 || true - ((broken_count++)) || true + broken_count=$((broken_count + 1)) done < <(command find "$prefs_dir" -maxdepth 1 -name "*.plist" -type f 2> /dev/null || true) # Check ByHost preferences. @@ -45,7 +45,7 @@ fix_broken_preferences() { plutil -lint "$plist_file" > /dev/null 2>&1 && continue safe_remove "$plist_file" true > /dev/null 2>&1 || true - ((broken_count++)) || true + broken_count=$((broken_count + 1)) done < <(command find "$byhost_dir" -name "*.plist" -type f 2> /dev/null || true) fi diff --git a/lib/optimize/tasks.sh b/lib/optimize/tasks.sh index 738cd87..87f7758 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++)) || true + skipped=$((skipped + 1)) 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++)) || true + skipped=$((skipped + 1)) 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++)) || true + skipped=$((skipped + 1)) continue fi fi @@ -354,14 +354,14 @@ opt_sqlite_vacuum() { set -e if [[ $exit_code -eq 0 ]]; then - ((vacuumed++)) || true + vacuumed=$((vacuumed + 1)) elif [[ $exit_code -eq 124 ]]; then - ((timed_out++)) || true + timed_out=$((timed_out + 1)) else - ((failed++)) || true + failed=$((failed + 1)) fi else - ((vacuumed++)) || true + vacuumed=$((vacuumed + 1)) 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++)) || true + slow_count=$((slow_count + 1)) fi sleep 1 done diff --git a/lib/ui/app_selector.sh b/lib/ui/app_selector.sh index a5e4fbc..add9015 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++)) || true + idx=$((idx + 1)) 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 982a7e8..c241fc1 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++)) || true + selected_count=$((selected_count + 1)) 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++)) || true + cursor_pos=$((cursor_pos + 1)) 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++)) || true + top_index=$((top_index + 1)) 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++)) || true + selected_count=$((selected_count + 1)) 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++)) || true + cursor_pos=$((cursor_pos + 1)) elif [[ $((top_index + visible_count)) -lt ${#view_indices[@]} ]]; then - ((top_index++)) || true + top_index=$((top_index + 1)) 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++)) || true + selected_count=$((selected_count + 1)) fi fi diff --git a/lib/ui/menu_simple.sh b/lib/ui/menu_simple.sh index 09f503a..0dd4607 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++)) || true + [[ ${selected[i]} == true ]] && selected_count=$((selected_count + 1)) 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++)) || true + cursor_pos=$((cursor_pos + 1)) elif [[ $((top_index + visible_count)) -lt $total_items ]]; then - ((top_index++)) || true + top_index=$((top_index + 1)) 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 4cc185d..953b9ee 100755 --- a/lib/uninstall/batch.sh +++ b/lib/uninstall/batch.sh @@ -317,7 +317,7 @@ batch_uninstall_applications() { local system_size_kb=$(calculate_total_size "$system_files" || echo "0") local diag_system_size_kb=$(calculate_total_size "$diag_system" || echo "0") local total_kb=$((app_size_kb + related_size_kb + system_size_kb + diag_system_size_kb)) - ((total_estimated_size += total_kb)) || true + total_estimated_size=$((total_estimated_size + total_kb)) # shellcheck disable=SC2128 if [[ -n "$system_files" || -n "$diag_system" ]]; then @@ -465,7 +465,7 @@ batch_uninstall_applications() { local -a success_items=() local current_index=0 for detail in "${app_details[@]}"; do - ((current_index++)) || true + current_index=$((current_index + 1)) 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)) || true - ((success_count++)) || true - [[ "$used_brew_successfully" == "true" ]] && ((brew_apps_removed++)) || true - ((files_cleaned++)) || true - ((total_items++)) || true + total_size_freed=$((total_size_freed + total_kb)) + success_count=$((success_count + 1)) + [[ "$used_brew_successfully" == "true" ]] && brew_apps_removed=$((brew_apps_removed + 1)) + files_cleaned=$((files_cleaned + 1)) + total_items=$((total_items + 1)) success_items+=("$app_path") else if [[ -t 1 ]]; then @@ -628,7 +628,7 @@ batch_uninstall_applications() { fi fi - ((failed_count++)) || true + failed_count=$((failed_count + 1)) failed_items+=("$app_name:$reason:${suggestion:-}") fi done @@ -672,7 +672,7 @@ batch_uninstall_applications() { else current_line="$current_line, $display_item" fi - ((idx++)) || true + idx=$((idx + 1)) 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)) || true + total_size_cleaned=$((total_size_cleaned + total_size_freed)) unset failed_items }