Skip to content

feat(clean): add --trash option to move cleaned files to Trash instead of deleting#442

Closed
spider-yamet wants to merge 1 commit intotw93:mainfrom
spider-yamet:feat/moving-cleaned-files-to-trash
Closed

feat(clean): add --trash option to move cleaned files to Trash instead of deleting#442
spider-yamet wants to merge 1 commit intotw93:mainfrom
spider-yamet:feat/moving-cleaned-files-to-trash

Conversation

@spider-yamet
Copy link
Contributor

Summary

Adds an option to move cleaned files to the system Trash instead of permanently removing them, so users can recover items if needed.

Closes #439

Changes

  • lib/core/file_ops.sh
    • Add safe_move_to_trash() that uses macOS Finder (osascript) to move paths to Trash.
    • When MOLE_USE_TRASH=1, safe_remove() tries trash first and falls back to rm if trash fails (e.g. headless or permission).
    • Dry-run messages show "Would move to Trash" when --trash is used.
  • bin/clean.sh
    • Add --trash / -t flag and set MOLE_USE_TRASH=1.
    • Update footer hint to mention --trash.
  • lib/core/help.sh
    • Document --trash, -t in clean help.

Usage

  • mo clean --dry-run — preview (no changes)
  • mo clean --dry-run --trash — preview move to Trash
  • mo clean --trash — clean and move items to Trash
  • mo clean — default: permanent removal (unchanged)

Notes

  • Trash is only used for user-level paths that go through safe_remove(). safe_sudo_remove() (system paths) is unchanged and still permanently removes.
  • On non-macOS or when osascript is unavailable, the code falls back to permanent removal.

Testing

  • tests/cli.bats: mo clean --help shows --trash.
  • tests/clean_core.bats: mo clean --dry-run --trash does not delete files.
  • tests/core_safe_functions.bats: safe_remove with MOLE_USE_TRASH=1 removes the file (trash or fallback).

@tw93
Copy link
Owner

tw93 commented Feb 11, 2026

@spider-yamet Thanks for the suggestion and for taking the time to describe the use case.

After reviewing this, we will not plan this feature for now.

Reasoning:

  1. mo clean is designed for immediate disk reclaim, while moving files to Trash does not reliably free space right away.
  2. We already provide a safe preview path with --dry-run, plus protection controls via --whitelist.
  3. Adding a Trash mode introduces behavior ambiguity across environments (interactive/headless) and increases maintenance complexity.

So for now, we keep the current safety model: preview first (--dry-run), then clean with explicit user control (--whitelist).

We may revisit this in the future if we can provide a strict and fully predictable Trash-only workflow.

@tw93 tw93 closed this Feb 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] moving cleaned files to trash can instead of directly removing

2 participants