Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

exrn 🔄

A Safe & Powerful Batch File Renamer with Regex Magic

Rust Build License: MIT

Interactive TUI

Transform your files like a wizard! 🧙

Features 🌟

  • 🎯 Precision Matching: Supports both standard GLOB patterns and direct Shell-expanded paths.
  • 🔄 Smart Replacement: Use standard Regex Capture Groups (e.g., $1, $2) for complex renaming.
  • ⛓️ Chain Renaming: Safely handles dependency chains (e.g., A -> B, B -> C) using topological sorting.
  • 🎨 Rich TUI:
    • Interactive Mode: Select/Deselect files with a modern Terminal UI (Ratatui-based).
    • Smart Preview: Headless modes (Dry Run/Auto-confirm) also display a beautiful table preview even without interaction.
    • Line Wrapping: Automatically handles long filenames by wrapping text within columns.
    • CI Friendly: Detects non-TTY environments (CI/Pipes) and falls back to plain text output automatically.
  • 🛡️ Safety First:
    • Dry Run mode to preview without touching files.
    • Collision detection.
  • 🚀 Blazing Fast: Built with Rust.

Installation ⚡

Via Cargo (Recommended)

cargo install --git https://github.com/Intro-iu/exrn.git

From Source

git clone https://github.com/Intro-iu/exrn.git
cd exrn
cargo install --path .

Usage 🛠️

Basic Syntax

exrn -s [SOURCES] -r 'REGEX' 'REPLACEMENT' [OPTIONS]

Tip: It is recommended to use single quotes '...' for regex patterns to prevent Shell from incorrectly expanding $1 or *.

Options

Option Short Description
--sources -s File glob patterns or file paths (e.g. '*.txt' or file.txt)
--rule -r Required. Regex pattern and replacement string (e.g. '(.*)\.txt' '$1.md')
--dry-run -d Print the planned changes and exit without modifying anything
--sort Sort the output list by source filename (Default: true)
--yes -y Auto-confirm all prompts (Non-interactive mode)

Interactive Mode (TUI) 🖥️

When running in a terminal without -y or -d, exrn launches a rich interactive interface:

  • ↑/↓: Navigate through the file list.
  • Space: Toggle selection (include/exclude file from renaming).
  • Enter: Confirm and execute the selected renames.
  • Esc/q: Quit without making changes.

Note: In Dry Run or Auto-Confirm modes, exrn will still display the table preview (without interactivity) if running in a terminal. In CI environments, it automatically falls back to plain text.

Examples 🧪

1. Change Extensions (Dry Run first!)

Preview what would happen:

exrn -s '*.txt' -r '(.*)\.txt' '$1.md' --dry-run

2. Rename with Smart Chain Sorting

If you have files part1.txt, part2.txt, part3.txt and want to shift them naming-wise:

# Safely handles renaming part2 -> part3 even if part3 exists (but is also being moved)
exrn -s 'part*' -r 'part(\d+)' 'part${1}_next'

3. Date Formatting

Convert 2023-01-01_log.txt to log_2023-01-01.txt:

exrn -s '*.txt' -r '(\d{4}-\d{2}-\d{2})_(.*)\.txt' '$2_$1.txt'

4. Direct Files (Shell Expansion)

You can let your shell handle the globbing:

exrn -s *.png -r 'Img_(.*)' 'Picture_$1'

License 📄

This project is licensed under the MIT License - see the LICENSE file for details.


💡 Pro Tip: Always use --dry-run (-d) first when trying complex regexes!

🐞 Found an issue? Report it here

⭐ Love exrn? Give us a star on GitHub!

About

A Command-line File Renaming Tool Based on Regular Expressions

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages