Batch rename utility for developers
you can download a pre-compiled executable for Linux, then you should copy that executable to /usr/bin
or add it to your $PATH
env. Do not forget to chmod +x nomino
.
- Install rust:
curl -sSf https://sh.rustup.rs | sh
- Run
cargo install --git https://github.com/yaa110/nomino.git
USAGE:
nomino [FLAGS] [OPTIONS] [OUTPUT]
FLAGS:
-e, --extension Preserves the extension of input files in 'sort' and 'regex' options
-h, --help Prints help information
-p, --print Prints the map table to stdout
-t, --test Runs in test mode without renaming actual files
-V, --version Prints version information
OPTIONS:
-d, --dir <PATH> Sets the working directory
-g, --generate <PATH> Stores a JSON map file in '<PATH>' after renaming files
-m, --map <PATH> Sets the path of map file to be used for renaming files
-r, --regex <PATTERN> Regex pattern (RE2 syntax) to match by filenames
-s, --sort <ORDER> Sets the order of sorting (by name) to rename files using enumerator [possible values: ASC, DESC]
ARGS:
<OUTPUT> Output pattern to be used for renaming files
It might work on Windows, MacOS and other operating systems, however, the pre-compiled executable is only tested and generated for Linux.
{
"<input1>": "<output1>",
"<input2>": "<output2>",
"<...>": "<...>"
}
The output is necessary when using --sort
or --regex
options.
The accepted syntax of regex pattern is RE2.
- Placeholders have the format of
{I:P}
whereI
is the index of captured group andP
is the padding of digits with0
. For example,{2:3}
means the third captured group with a padding of 3, i.e.1
is formatted as001
. - Indices start from
0
, and{0}
means the filename. - The index
I
could be dropped, i.e.{}
or{:3}
. In this case an auto incremental index is used which starts from1
. For example,{} {}
equals{1} {2}
. {
and}
characters could be escaped using\
character, i.e.\\{
and\\}
in cli.- Padding is only used for positive numbers, e.g. the formatted result of
{:3}
for1
is001
, for-1
is-1
and fora
isa
. - If
--sort
option is used, the first index{0}
is the filename and the second index{1}
or first occurrence of{}
is the enumerator index.
Consider the following directory:
➜ ls
Nomino (2020) S1.E1.1080p.mkv
Nomino (2020) S1.E2.1080p.mkv
Nomino (2020) S1.E3.1080p.mkv
Nomino (2020) S1.E4.1080p.mkv
Nomino (2020) S1.E5.1080p.mkv
Note that -p
flag is used to print the table and -e
flag is used to preserve the extension of input.
- Rename files using
regex
option:
➜ nomino -pr ".* S(\d+).E(\d+).*.(mkv)" "S{:2}E{:2}.{}"
+-------------------------------+------------+
| Input | Output |
+-------------------------------+------------+
| Nomino (2020) S1.E1.1080p.mkv | S01E01.mkv |
| Nomino (2020) S1.E2.1080p.mkv | S01E02.mkv |
| Nomino (2020) S1.E3.1080p.mkv | S01E03.mkv |
| Nomino (2020) S1.E4.1080p.mkv | S01E04.mkv |
| Nomino (2020) S1.E5.1080p.mkv | S01E05.mkv |
+-------------------------------+------------+
- Rename files using
sort
option:
➜ nomino -pes asc "{:3}"
+-------------------------------+---------+
| Input | Output |
+-------------------------------+---------+
| Nomino (2020) S1.E1.1080p.mkv | 001.mkv |
| Nomino (2020) S1.E2.1080p.mkv | 002.mkv |
| Nomino (2020) S1.E3.1080p.mkv | 003.mkv |
| Nomino (2020) S1.E4.1080p.mkv | 004.mkv |
| Nomino (2020) S1.E5.1080p.mkv | 005.mkv |
+-------------------------------+---------+
➜ nomino -pes desc "{:3}"
+-------------------------------+----------+
| Input | Output |
+-------------------------------+----------+
| Nomino (2020) S1.E5.1080p.mkv | 001.mkv |
| Nomino (2020) S1.E4.1080p.mkv | 002.mkv |
| Nomino (2020) S1.E3.1080p.mkv | 003.mkv |
| Nomino (2020) S1.E2.1080p.mkv | 004.mkv |
| Nomino (2020) S1.E1.1080p.mkv | 005.mkv |
+-------------------------------+----------+
- Rename files using the following
map.json
file:
{
"Nomino (2020) S1.E1.1080p.mkv": "0101.mkv",
"Nomino (2020) S1.E2.1080p.mkv": "0102.mkv",
"Nomino (2020) S1.E3.1080p.mkv": "0103.mkv",
"Nomino (2020) S1.E4.1080p.mkv": "0104.mkv",
"Nomino (2020) S1.E5.1080p.mkv": "0105.mkv"
}
➜ nomino -pm map.json
+-------------------------------+----------+
| Input | Output |
+-------------------------------+----------+
| Nomino (2020) S1.E1.1080p.mkv | 0101.mkv |
| Nomino (2020) S1.E2.1080p.mkv | 0102.mkv |
| Nomino (2020) S1.E3.1080p.mkv | 0103.mkv |
| Nomino (2020) S1.E4.1080p.mkv | 0104.mkv |
| Nomino (2020) S1.E5.1080p.mkv | 0105.mkv |
+-------------------------------+----------+
- Undo renaming files: rename files by creating a map file using
-g
option, then use that map file to undo renaming:
➜ nomino -g undo.json -pr ".*.(mkv)" "a.{}"
+-------------------------------+-----------+
| Input | Output |
+-------------------------------+-----------+
| Nomino (2020) S1.E1.1080p.mkv | ____a.mkv |
| Nomino (2020) S1.E4.1080p.mkv | ___a.mkv |
| Nomino (2020) S1.E3.1080p.mkv | __a.mkv |
| Nomino (2020) S1.E2.1080p.mkv | _a.mkv |
| Nomino (2020) S1.E5.1080p.mkv | a.mkv |
+-------------------------------+-----------+
➜ nomino -pm undo.json
+-----------+-------------------------------+
| Input | Output |
+-----------+-------------------------------+
| ____a.mkv | Nomino (2020) S1.E1.1080p.mkv |
| _a.mkv | Nomino (2020) S1.E2.1080p.mkv |
| __a.mkv | Nomino (2020) S1.E3.1080p.mkv |
| ___a.mkv | Nomino (2020) S1.E4.1080p.mkv |
| a.mkv | Nomino (2020) S1.E5.1080p.mkv |
+-----------+-------------------------------+