{[m]atch=[r]eplace:[f]ormat}
mrf (pronounced "morph") lets you rename files by pattern matching.
Demo
Rename files
Organize files
Format numbers
Installation
On Linux
You can install mrf with Homebrew:
brew tap kerlilow/tools
brew install mrf
On macOS
You can install mrf with Homebrew:
brew tap kerlilow/tools
brew install mrf
From source
You can install mrf from source using Rust's package manager Cargo:
From binaries
The release page includes precompiled binaries for Linux, macOS and Windows.
How It Works
Tokenization
The input string is split into tokens. There are 4 types of tokens:
- Number - A contiguous string of ASCII digits (0-9).
- Whitespace - A contiguous string of ASCII whitespaces.
- Punctuation - A contiguous string of ASCII punctuations.
- Text - A contiguous string of characters that are none of the above.
For example, the string example-001
will be tokenized as [example][-][001]
.
Matching
Each matcher matches one or more tokens. There are 2 types of matchers:
- Any - Match any type of tokens, the default matcher. Example:
{}
. - Number - Match a Number token, specified with
n
. Example:{n}
.
Note: A matcher matches the minimum number of tokens required.
For example, the string example-001
with the replacer string {}{n}
will be
matched as:
[example-][001]
^^^^^^^^ ^^^
Any Number
Note that the Any matcher matches 2 tokens here.
On the other hand, for the same string, if the replacer string {}{}
will be
matched as:
[example][-001]
^^^^^^^ ^^^^
Any Any
Note that this time, the first Any matcher matched the 1 token, while the second Any matcher matched 2 tokens.
Replacing
A replacement string may be specified to replace the matched substring with an
equal sign (=
) in the specifier. Example: {=replaced}
.
Formatting
A format specifier may be specified to format the matched substring (or the replacement, if specified).
The following format specifiers are supported:
- Padding (aligned to the right) - Specify the desired width. Example:
{:3}
. - Zero padding (aligned to the right) - Specify
0
, followed by the desired width. Example:{:03}
.
Usage
Rename/move files with mrf mv
mrf mv <item>... <replacer>
Examples
Replace hyphen with underscore
Rename while keeping numbering
Add zero padding
Execute commands with mrf exec
mrf exec <command> <item>... <replacer>
Examples
Make directory
Copy files
Map strings with mrf map
(useful for testing and understanding)
mrf map [FLAGS] <item>... <replacer>
Examples
Replace hyphen with underscore
Pipe to cp (consider using the "exec" subcommand instead)
|
Roadmap
- Nicer error reports
- Match highlighting
- More installation methods
- Exact, prefix, suffix matcher
- Regex matcher
License
This project is licensed under the terms of the MIT license.
See the LICENSE.md file in this repository for more information.