47c47
<    -a     Automatically start and affirm all Cleanings
---
>    -y     Assume yes to all prompts (non-interactive)
1425a1426
>     --yes) set -- -y ;;
1431a1433,1434
> elif [[ "$#" -eq 1 && "${1:-}" == "-y" ]]; then
>     set -- -bcdp -y
1434c1437
< ## Process Options ##
---
> ## Process Options (collect flags, run actions after parsing)
1436c1439
< while getopts ":abcdjpvh" option; do
---
> while getopts ":bcdjpyh" option; do
1438,1480c1441,1449
<         a) # automatic mode
<             _mc_sudo_wrap -k
<             printf "\nPerforming all cleanings automatically.\n"
<             printf "\nThis is the final warning.\n\n"
<             if _mc_sudo_wrap -p "To continue enter the password for %p (ctrl+c to cancel): " true; then
<                 exec 4< <(timeout 600 yes)
<                 trap '{ [[ -e /proc/$$/fd/4 ]] && exec 4<&-; }' RETURN EXIT
<                 printf "\n"
<                 _mc_auto=1 exec -- "$_mc_scr_path" -bcdp <&4
<                 exec 4<&-
<             fi
<             exit ;;
<         b) # clean basics
<             _mc_junker
<             _mc_homecache
<             _mc_journlogs
<             _mc_coredumps
<             ;;
<         c) # clean containers
<             _mc_confuncts
<             ;;
<         d) # clean devs
<             _mc_devfuncts
<             ;;
<         j) # clean junk
<             _mc_junker
<             ;;
<         p) # clean pkg-related
<             _mc_pkgfiledata
<             _mc_packagekitdata
<             _mc_pamacdata
<             _mc_pacmanfuncts
<             ;;
<         v) # display version
<             printf '\nmaclean %s\n\n' "$_mc_vers"
<             exit ;;
<         h) # display Help
<             _mc_help
<             exit ;;
<         *) # invalid option
<             printf "Error: Invalid option: %s\n" "$1"
<             _mc_help
<             exit 1 ;;
---
>         b) _do_b=1 ;;
>         c) _do_c=1 ;;
>         d) _do_d=1 ;;
>         j) _do_j=1 ;;
>         p) _do_p=1 ;;
>         y) _mc_auto=1 ;;
>         v) printf '\nmaclean %s\n\n' "$_mc_vers"; exit ;;
>         h) _mc_help; exit ;;
>         *) printf "Error: Invalid option: %s\n" "${OPTARG:-$1}"; _mc_help; exit 1 ;;
1483a1453,1489
> # Shift off processed options
> shift $((OPTIND - 1))
> 
> # Validate no unexpected positional arguments
> if (($# > 0)); then
>     printf "Error: Unexpected argument: %s\n" "$1"
>     _mc_help
>     exit 1
> fi
> 
> # Execute actions in a deterministic order so flags like -y can be set beforehand
> if [[ ${_do_b:-0} -eq 1 ]]; then
>     _mc_junker
>     _mc_homecache
>     _mc_journlogs
>     _mc_coredumps
> fi
> 
> if [[ ${_do_c:-0} -eq 1 ]]; then
>     _mc_confuncts
> fi
> 
> if [[ ${_do_d:-0} -eq 1 ]]; then
>     _mc_devfuncts
> fi
> 
> if [[ ${_do_j:-0} -eq 1 ]]; then
>     _mc_junker
> fi
> 
> if [[ ${_do_p:-0} -eq 1 ]]; then
>     _mc_pkgfiledata
>     _mc_packagekitdata
>     _mc_pamacdata
>     _mc_pacmanfuncts
> fi
> 
1499,1501c1505,1511
< printf "\nPress any key to exit. "
< read -r -t60 -s -n1
< printf "\n\n"
---
> if [[ ${_mc_auto:-0} -eq 1 ]]; then
>     printf "\n\n"
> else
>     printf "\nPress any key to exit. "
>     read -r -t60 -s -n1 || true
>     printf "\n\n"
> fi