Crates.io | mrf |
lib.rs | mrf |
version | 0.1.1 |
source | src |
created_at | 2020-08-22 13:46:00.473896 |
updated_at | 2020-09-06 11:35:52.860393 |
description | Rename files by pattern matching. |
homepage | https://github.com/kerlilow/mrf |
repository | https://github.com/kerlilow/mrf |
max_upload_size | |
id | 279515 |
size | 90,127 |
mrf (pronounced "morph") lets you rename files by pattern matching.
You can install mrf with Homebrew:
brew tap kerlilow/tools
brew install mrf
You can install mrf with Homebrew:
brew tap kerlilow/tools
brew install mrf
You can install mrf from source using Rust's package manager Cargo:
$ cargo install mrf
The release page includes precompiled binaries for Linux, macOS and Windows.
The input string is split into tokens. There are 4 types of tokens:
For example, the string example-001
will be tokenized as [example][-][001]
.
Each matcher matches one or more tokens. There are 2 types of matchers:
{}
.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.
A replacement string may be specified to replace the matched substring with an
equal sign (=
) in the specifier. Example: {=replaced}
.
A format specifier may be specified to format the matched substring (or the replacement, if specified).
The following format specifiers are supported:
{:3}
.0
, followed by the desired
width. Example: {:03}
.mrf mv
mrf mv <item>... <replacer>
$ mrf mv * '{}{=_}{}'
Moving 1 out of 1 items:
image-001.jpg -> image_001.jpg
$ mrf mv * '{=photo}{}'
Moving 1 out of 1 items:
image-001.jpg -> photo-001.jpg
$ mrf mv * '{}{n:03}{}'
Moving 1 out of 1 items:
image-1.jpg -> image-001.jpg
mrf exec
mrf exec <command> <item>... <replacer>
$ mrf exec -r 'mkdir -p' * '{3}{=}'
Matched 1 out of 1 items:
image-2020-01-01.jpg -> 2020
$ mrf exec cp * '{}{=_}{}'
Matched 1 out of 1 items:
image-001.jpg -> image_001.jpg
mrf map
(useful for testing and understanding)mrf map [FLAGS] <item>... <replacer>
$ mrf map example-001 '{}{=_}{}'
example-001 -> example_001
$ mrf map * '{}{=-}{}' | xargs -0 -n2 cp
This project is licensed under the terms of the MIT license.
See the LICENSE.md file in this repository for more information.