Metadata-Version: 2.5
Name: ordena-cli
Version: 0.1.0
Summary: Tidy your Downloads folder safely: dry run by default, never overwrites, every run can be undone.
Project-URL: Homepage, https://github.com/jdmahecha1/ordena
Project-URL: Issues, https://github.com/jdmahecha1/ordena/issues
Author: Juan Diego Mahecha Martinez
License-Expression: MIT
License-File: LICENSE
Keywords: cli,downloads,files,organizer,undo
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: End Users/Desktop
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Desktop Environment :: File Managers
Classifier: Topic :: Utilities
Requires-Python: >=3.11
Provides-Extra: dev
Requires-Dist: hypothesis>=6.100; extra == 'dev'
Requires-Dist: pytest>=8; extra == 'dev'
Requires-Dist: ruff>=0.6; extra == 'dev'
Description-Content-Type: text/markdown

# ordena

[![CI](https://github.com/jdmahecha1/ordena/actions/workflows/ci.yml/badge.svg)](https://github.com/jdmahecha1/ordena/actions/workflows/ci.yml)
[![PyPI](https://img.shields.io/pypi/v/ordena-cli)](https://pypi.org/project/ordena-cli/)
![Python](https://img.shields.io/badge/python-3.11%2B-blue)
![Dependencies](https://img.shields.io/badge/dependencies-0-brightgreen)
![License](https://img.shields.io/badge/license-MIT-green)

**English** · [Español](https://github.com/jdmahecha1/ordena/blob/main/README.es.md)

Tidy your Downloads folder from the terminal, **safely**: it shows a dry run first, never
overwrites a file, and every run can be undone.

```console
$ ordena
Folder: ~/Downloads  (dry run: nothing was moved)

  Archives          2  (new folder)
  Documents         4  (new folder)
  Images            2  (new folder)
  Installers        1  (new folder)
  Video             1  (new folder)

10 files to move · 3 skipped (1 download in progress, 1 modified in the last minutes, 1 unknown type)

Run ordena --apply to move them. You can always go back with ordena undo.

$ ordena --apply
Moved 10 files into 5 folders.
Run 20261017-210301-aa53. Undo it with: ordena undo

$ ordena undo
Restored 10 files.
Removed empty folders: Video, Installers, Images, Documents, Archives
```

## Install

```bash
pipx install ordena-cli      # or: uv tool install ordena-cli / pip install ordena-cli
```

Python 3.11+ on Windows, macOS or Linux. No dependencies outside the standard library.

## Usage

| Command | What it does |
| --- | --- |
| `ordena [FOLDER]` | Dry run: what would move, by category, and what is skipped and why. Default folder: your Downloads. |
| `ordena [FOLDER] --apply` | Move the files. |
| `ordena undo [RUN_ID]` | Put the files of the last run (or the given one) back. |
| `ordena history` | List past runs. |

Options: `-v` lists every file, `--json` prints machine-readable output, `--config FILE`,
`--include-recent` also moves files modified in the last 2 minutes, and `--force` sorts a
folder the safety check refuses.

Exit codes: `0` ok · `1` some files were not moved or restored · `2` usage or config error ·
`3` another `ordena` is running.

## How it keeps your files safe

- **Dry run by default.** Nothing moves without `--apply`.
- **Never overwrites.** If `report.pdf` already exists in `Documents`, the new one becomes
  `report (1).pdf`. Names are compared ignoring case and Unicode normalization, so
  `Foto.JPG` and `foto.jpg` never collide, not even on macOS or Windows. The move itself also
  refuses to overwrite, in case a file appears between planning and moving.
- **Every run can be undone.** The plan is written to a journal (atomically, with `fsync`)
  *before* the first file moves. `undo` moves a file back only if it is still where `ordena`
  left it, unchanged. If the original name has been taken since, it restores the file as
  `name (restored).ext` instead of overwriting.
- **Crash-safe.** Each move is an atomic rename inside one volume, so a file is always in
  exactly one place. If the process dies halfway, `undo` checks the disk to find out what
  actually moved.
- **Leaves alone** hidden and system files, downloads in progress (`.crdownload`, `.part`…),
  files modified in the last 2 minutes, shortcuts, symlinks, subfolders and unknown types.
- **Doesn't read your files.** It never opens them, so OneDrive or iCloud files that live only
  in the cloud are not downloaded.
- **Refuses dangerous folders**: the file-system root, your home folder and system folders.
- **One run at a time**, enforced with an OS file lock.

The full design is in [docs/design.md](https://github.com/jdmahecha1/ordena/blob/main/docs/design.md).

## Categories

| Folder | Spanish name | Examples |
| --- | --- | --- |
| Images | Imágenes | jpg, png, heic, webp, svg, raw camera formats |
| Documents | Documentos | pdf, docx, txt, md, odt, rtf |
| Spreadsheets | Hojas de cálculo | xlsx, xls, csv, ods |
| Presentations | Presentaciones | pptx, key, odp |
| Audio | Audio | mp3, flac, wav, m4a, ogg |
| Video | Video | mp4, mkv, mov, avi, webm |
| Archives | Comprimidos | zip, rar, 7z, tar.gz, iso |
| Installers | Instaladores | exe, msi, dmg, pkg, deb, apk, AppImage |
| Code | Código | py, js, html, json, sh, sql… |
| Fonts | Fuentes | ttf, otf, woff2 |
| Ebooks | Libros electrónicos | epub, mobi, azw3, cbz |

Matching ignores case, and the longest extension wins, so `backup.tar.gz` counts as `tar.gz`
rather than `gz`.

## Configuration

Optional. `ordena` looks for `config.toml` in `%APPDATA%\ordena` (Windows),
`~/Library/Application Support/ordena` (macOS) or `~/.config/ordena` (Linux), or takes one with
`--config`:

```toml
language = "es"            # Spanish folder names: Imágenes, Documentos...
move_unknown = true        # unknown types go to "Other" / "Otros" instead of staying put
recent_minutes = 5
ignore = ["*.iso", "keep-*"]

[categories.Ebooks]        # replace a built-in category...
extensions = ["epub", "mobi", "pdf"]

[categories."Design files"] # ...or add your own
extensions = ["fig", "psd", "sketch"]
```

Mistakes in the config are reported with the file and the key at fault, and nothing moves.

## Development

```bash
git clone https://github.com/jdmahecha1/ordena.git
cd ordena
python -m venv .venv && source .venv/bin/activate   # Windows: .venv\Scripts\activate
pip install -e ".[dev]"
ruff check . && ruff format --check .
pytest
```

About 400 tests, including property-based tests with
[Hypothesis](https://hypothesis.readthedocs.io/). For example, for any random set of files,
"apply, then undo" restores the exact original folder: same names, bytes and modification
times. CI runs on Windows, macOS and Linux with Python 3.11 and 3.14, then builds the package
and checks that the installed wheel works in a clean environment.

Releases go to PyPI from a `v*` tag through
[Trusted Publishing](https://docs.pypi.org/trusted-publishers/), so no API token is stored
anywhere.

## License

[MIT](https://github.com/jdmahecha1/ordena/blob/main/LICENSE)
