| src | ||
| tasks | ||
| .gitignore | ||
| Cargo.lock | ||
| Cargo.toml | ||
| QWEN.md | ||
| README.md | ||
re-sort
A command-line and interactive terminal-based application for organizing files based on their modification dates and custom time ranges. Built with Rust and the ratatui crate for a text-based user interface (TUI).
Features
- Date-based file organization: Automatically sorts files into dated directories based on their modification time
- Custom time ranges: Define your own time buckets with names (e.g., "insomnia" for 2-8 AM, "work" for 9-5 PM)
- Multiple operation modes: Move, copy, or create symbolic links
- Preview mode: See how files will be organized before executing
- Interactive TUI: Easy-to-use terminal interface with keyboard navigation
- Non-interactive mode: Command-line only operation for automation
- Recursive scanning: Option to include subdirectories
Installation
# Clone the repository
git clone https://github.com/your-username/re-sort.git
cd re-sort
# Build the project
cargo build --release
# Run directly with Cargo
cargo run -- [options]
Usage
Interactive Mode
Simply run the application without any arguments to start the interactive TUI:
cargo run
Non-Interactive Mode
# Basic usage
re-sort --source /path/to/source --target /path/to/target --ranges "2:00..8:00:insomnia,9:00..12:00:morning,13:00..18:00:afternoon,19:00..25:00:night" --format "%Y-%m-%d" --mode move
# With recursive scanning
re-sort --source /path/to/source --target /path/to/target --ranges "2:00..8:00:insomnia,9:00..12:00:morning" --recursive
# Only process specific file extensions
re-sort --source /path/to/source --target /path/to/target --ranges "9:00..17:00:work" --extensions ".jpg,.png,.gif"
CLI Options
--source: Source directory to scan for files (default: current directory)--target: Target directory for organized files (default: current directory)--ranges: Time ranges with names (e.g., "2:00..8:00:insomnia,9:00..12:00:morning")--format: Date format for directory names (default: "%Y-%m-%d")--mode: Operation mode (move, copy, symlink) (default: move)--recursive: Enable recursive scanning of subdirectories--extensions: File extensions to include (comma-separated, e.g., ".jpg,.png")--non-interactive: Run in non-interactive mode (command-line only)
Time Range Format
Time ranges are specified as:
HH:MM..HH:MM:namefor basic ranges (e.g., "2:00..8:00:insomnia")HH:MM:SS..HH:MM:SS:namefor ranges with seconds (e.g., "2:00:30..8:15:45:insomnia")- Ranges can cross midnight using hours > 24 (e.g., "23:00..25:30:night" means 11 PM to 1:30 AM next day)
Multiple ranges are comma-separated: "2:00..8:00:insomnia,9:00..12:00:morning,13:00..18:00:afternoon"
Navigation in TUI
Enter: Confirm selection or proceed to next stepq: Quit applicationj/k: Navigate through file lists in preview mode- Arrow keys: Navigate UI elements
Examples
Organize images from a download folder into daily directories with custom time ranges:
re-sort --source ~/Downloads --target ~/Organized --ranges "2:00..8:00:sleep,8:00..12:00:morning,12:00..18:00:afternoon,18:00..24:00:evening" --format "%Y-%m-%d" --extensions ".jpg,.png,.gif" --mode move --recursive
Architecture
The application is organized into the following modules:
src/main.rs: CLI entry point and TUI launchersrc/core/parser.rs: Time range and date format parsingsrc/core/organizer.rs: File discovery, grouping, and execution logicsrc/tui/app.rs: Terminal user interface implementation
Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
License
This project is licensed under the MIT License - see the LICENSE file for details.