@@ -1021,11 +1021,28 @@ perform_cleanup() {
10211021 local -a summary_details=()
10221022
10231023 if [[ $total_size_cleaned -gt 0 ]]; then
1024- local freed_gb
1025- freed_gb=$( echo " $total_size_cleaned " | awk ' {printf "%.2f", $1/1024/1024}' )
1024+ local freed_size_human
1025+ local freed_value
1026+ local freed_unit
1027+
1028+ # ============================================
1029+ # Dynamic size formatting (KB → MB → GB)
1030+ # ============================================
1031+ if (( total_size_cleaned < 1024 )) ; then
1032+ freed_value=" $total_size_cleaned "
1033+ freed_unit=" KB"
1034+ elif (( total_size_cleaned < 1024 * 1024 )) ; then
1035+ freed_value=$( printf " %.2f" " $( echo " scale=4; $total_size_cleaned /1024" | bc) " )
1036+ freed_unit=" MB"
1037+ else
1038+ freed_value=$( printf " %.2f" " $( echo " scale=4; $total_size_cleaned /1024/1024" | bc) " )
1039+ freed_unit=" GB"
1040+ fi
1041+
1042+ freed_size_human=" ${freed_value}${freed_unit} "
10261043
10271044 if [[ " $DRY_RUN " == " true" ]]; then
1028- local stats=" Potential space: ${GREEN}${freed_gb} GB $ {NC}"
1045+ local stats=" Potential space: ${GREEN}${freed_size_human} {NC}"
10291046 [[ $files_cleaned -gt 0 ]] && stats+=" | Items: $files_cleaned "
10301047 [[ $total_items -gt 0 ]] && stats+=" | Categories: $total_items "
10311048 summary_details+=(" $stats " )
@@ -1035,15 +1052,15 @@ perform_cleanup() {
10351052 echo " # ============================================"
10361053 echo " # Summary"
10371054 echo " # ============================================"
1038- echo " # Potential cleanup: ${freed_gb} GB "
1055+ echo " # Potential cleanup: ${freed_size_human} "
10391056 echo " # Items: $files_cleaned "
10401057 echo " # Categories: $total_items "
10411058 } >> " $EXPORT_LIST_FILE "
10421059
10431060 summary_details+=(" Detailed file list: ${GRAY} $EXPORT_LIST_FILE ${NC} " )
10441061 summary_details+=(" Use ${GRAY} mo clean --whitelist${NC} to add protection rules" )
10451062 else
1046- local summary_line=" Space freed: ${GREEN}${freed_gb} GB ${NC} "
1063+ local summary_line=" Space freed: ${GREEN}${freed_size_human} ${NC} "
10471064
10481065 if [[ $files_cleaned -gt 0 && $total_items -gt 0 ]]; then
10491066 summary_line+=" | Items cleaned: $files_cleaned | Categories: $total_items "
@@ -1055,9 +1072,13 @@ perform_cleanup() {
10551072
10561073 summary_details+=(" $summary_line " )
10571074
1058- if [[ $( echo " $freed_gb " | awk ' {print ($1 >= 1) ? 1 : 0}' ) -eq 1 ]]; then
1075+ # Movie comparison only if unit is GB and >= 1GB
1076+ if [[ " $freed_unit " == " GB" ]] && \
1077+ [[ $( echo " $freed_value >= 1" | bc) -eq 1 ]]; then
1078+
10591079 local movies
1060- movies=$( echo " $freed_gb " | awk ' {printf "%.0f", $1/4.5}' )
1080+ movies=$( printf " %.0f" " $( echo " scale=2; $freed_value /4.5" | bc) " )
1081+
10611082 if [[ $movies -gt 0 ]]; then
10621083 if [[ $movies -eq 1 ]]; then
10631084 summary_details+=(" Equivalent to ~$movies 4K movie of storage." )
0 commit comments