GithubHelp home page GithubHelp logo

yaa110 / nomino Goto Github PK

View Code? Open in Web Editor NEW
558.0 5.0 19.0 910 KB

Batch rename utility for developers

License: Apache License 2.0

Rust 100.00%
rust utility batch-rename command-line-tool rustlang regex rename subdirectories files

nomino's Introduction

nomino

Test Download Wiki

Batch rename utility for developers

Alt text

How to install

Pre-Compiled

You can download a pre-compiled executable for Linux, MacOS and Windows operating systems, then you should copy that executable to a location from your $PATH env:

You might need to run chmod +x nomino-linux-64bit or chmod +x nomino-macos-64bit.

Build Manually

If you prefer to build nomino manually, or a pre-compiled executable is not provided for your target, then you can build nomino from scratch:

  • Install Rust: curl -sSf https://sh.rustup.rs | sh
  • Run cargo install nomino

Usage

USAGE:
    nomino [FLAGS] [OPTIONS] [[SOURCE] OUTPUT]...

FLAGS:
    -e, --extension    Preserves the extension of input files in 'sort' and 'regex' options
    -h, --help         Prints help information
    -k, --mkdir        Recursively creates all parent directories of '<OUTPUT>' if they are missing
    -w, --overwrite    Overwrites output files, otherwise, a '_' is prepended to filename
    -p, --print        Prints the map table to stdout
    -t, --test         Runs in test mode without renaming actual files (dry-run)
    -V, --version      Prints version information

OPTIONS:
        --depth <DEPTH>        Optional value to overwrite inferred subdirectory depth value in 'regex' mode
        --max-depth <DEPTH>    Optional value to set the maximum of subdirectory depth value in 'regex' mode
    -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 natural sorting (by name) to rename files using enumerator [possible values: ASC, DESC]

ARGS:
    <[SOURCE] OUTPUT>...    OUTPUT is the pattern to be used for renaming files, and SOURCE is the optional regex pattern to match by filenames. SOURCE has the same function as -r option

Map file format

{
    "<input1>": "<output1>",
    "<input2>": "<output2>",
    "<...>": "<...>"
}

Output

The output is necessary when using --sort or --regex options.

Regex

The accepted syntax of regex pattern is RE2.

Placeholders

  1. Placeholders have the format of {I:P} where I is the index of captured group and P is the padding of digits with 0. For example, {2:3} means the third captured group with a padding of 3, i.e. 1 is formatted as 001.
  2. Indices start from 0, and {0} means the filename.
  3. The index I could be dropped, i.e. {} or {:3}. In this case an auto incremental index is used which starts from 1. For example, {} {} equals {1} {2}.
  4. { and } characters could be escaped using \ character, i.e. \\{ and \\} in cli.
  5. Padding is only used for positive numbers, e.g. the formatted result of {:3} for 1 is 001, for -1 is -1 and for a is a.
  6. 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.

Wiki

  • Examples learn nomino by examples
  • Benchmark benchmark test of similar utilities to nomino

nomino's People

Contributors

dnaka91 avatar micwoj92 avatar yaa110 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

nomino's Issues

More nests and recursion

Describe the bug
Given the following nested hierarchy:

start_dir
├── a
├── b
├── c
│   ├── cc1
│   └── cc2
└── u
    ├── uu1
    └── uu2

nomino's recursion goes only 1 level deep.

Command

➜  nomino -tpkr ".*/(.*)/(.*)" "start_{}_{}"

This should create start_c_cc1,start_c_cc2,start_u_uu1,start_u_uu2
Instead, nomino stops looking at items located in c and u folders.

Version (nomino -V)
nomino 0.3.1

Environment

  • OS: Linux 5.6.4

Better error message for `error: No such file or directory (os error 2)`

I try to rename episode names of a series using a JSON map.

When running nomino, it returns the following error:

$ nomino -ktmp renamed.json 
error: No such file or directory (os error 2)

I cannot debug where the actual issue is. I would like a more verbose error message.

episodes.json
{
 "Season 01/Episode 01.mp4": "Season01/Episode 01 - Echoes of Thunder.mp4",
 "Season 01/Episode 02.mp4": "Season 01/Episode 02 - What Is Done.mp4",
 "…": "…",
 "Season 05/Episode 09.mp4": "Season05/Episode 09 - Infantis Sanguine.mp4"
}
╭─[/mnt/Series/The Dragon Prince]
╰──╼ls
 renamed.json  'Season 01'  'Season 02'  'Season 03'  'Season 04'  'Season 05'
╭─[/mnt/Series/The Dragon Prince]
╰──╼ls Season\ 01/
'Episode 01.mp4'  'Episode 02.mp4'  'Episode 03.mp4'  'Episode 04.mp4'  'Episode 05.mp4'  'Episode 06.mp4'  'Episode 07.mp4'  'Episode 08.mp4'  'Episode 09.mp4'   Subs

OS: Debian 12
nomino: v.1.3.4

Add support for creating links/symlinks insted of renaming

Is your feature request related to a problem? Please describe.
I'm downloading torrents and I want them to keep seeding but at the same time I want to have correctly named files

Describe the solution you'd like
I would like to have a flag like -s or -h to create symlinks or to create links similar to what the rename utility has

Add a flag to select the printed format

Is your feature request related to a problem? Please describe.

I loved nomino pragmatic approach to renaming files.

But I missing:

  • Printing output column aligned without table borders/headers/formating
  • Printing to markdown
  • Printing generated json to stdout

Describe the solution you'd like

Add some command-line options like:

USAGE:
    nomino [FLAGS] [OPTIONS] [[SOURCE] OUTPUT]...

FLAGS:
    -e, --extension    Preserves the extension of input files in 'sort' and 'regex' options
    -h, --help         Prints help information
    -k, --mkdir        Recursively creates all parent directories of '<OUTPUT>' if they are missing
    -w, --overwrite    Overwrites output files, otherwise, a '_' is prepended to filename
-    -p, --print        Prints the rename map as table to stdout
+    -p, --print        Prints the rename map as table to stdout
+    -l, --log          Prints the rename map as table to stderr
    -t, --test         Runs in test mode without renaming actual files (dry-run)
    -V, --version      Prints version information

OPTIONS:
        --depth <DEPTH>        Optional value to overwrite inferred subdirectory depth value in 'regex' mode
    -d, --dir <PATH>           Sets the working directory
    -g, --generate <PATH>      Stores a JSON map file in '<PATH>' after renaming files
+    -G, --gen-as [FMT]         Change stored file format to <FMT> [possible values: cols, csv, json, markdown, table]
+    -F, --format [FMT]         Change printed format to <FMT> [possible values: cols, csv, json, markdown, table]
    -m, --map <PATH>           Sets the path of map file to be used for renaming files
        --max-depth <DEPTH>    Optional value to set the maximum of subdirectory depth value in 'regex' mode
    -r, --regex <PATTERN>      Regex pattern (RE2 syntax) to match by filenames
    -s, --sort <ORDER>         Sets the order of natural sorting (by name) to rename files using enumerator [possible
                               values: ASC, DESC]

So command invocations like the bellow will print:

$ ls -l *.md
-rw-r--r--  1 root  root   4707 Jun 18 11:38 CODE_OF_CONDUCT.md
-rw-r--r--  1 root  root  10429 Jun 18 11:38 CONTRIBUTING.md
-rw-r--r--  1 root  root   4955 Jun 18 11:38 README.md
$$ nomino -pt -F cols '(.*)\.(md)' '{2}-{1}+{}'
CODE_OF_CONDUCT.md md-CODE_OF_CONDUCT+CODE_OF_CONDUCT
CONTRIBUTING.md    md-CONTRIBUTING+CONTRIBUTING      
README.md          md-README+README                  

Consider cross-platform support\builds

You should consider making this a cross-platform tool (which should be fairly easy to accomplish being in go).

Having builds available for Windows and Mac would expand the potential user base a great deal.

AUR packaging dependency

Describe the bug

According to Rust package guidelines, Rust packages on the AUR should declare makedepends=('cargo') instead of makedepends=('rust'). This allows rustup's installed toolchains to be picked up and makes the makepkg -dsi workaround unnecessary.

I saw that you maintain the AUR package yourself so I thought I'd report the issue here.

Unwelcomed `_` when zero-padding filenames

Hey Navid,
let me start by expressing my gratitude for your efforts into this nice project !

A frequent use case of mine is to rename a set of numbered files / directories by padding them with zeroes, and Nomino seems best suited for this.

Unfortunately, it insists in renaming some paths when there's no need to.

Take the following example:

d="$(mktemp -d)"
mkdir -p "$d/{1,5,10} - Whatever"
nomino --dir "$d" --print --test '(\d+)(.*)' '{:2}{}'
rmdir "$d"/* ; rmdir "$d"

which outputs

+---------------+----------------+
| Input         | Output         |
+---------------+----------------+
| 1 - Whatever  | 01 - Whatever  |
| 5 - Whatever  | 05 - Whatever  |
| 10 - Whatever | _10 - Whatever |
+---------------+----------------+

whereas I'd expect to get

+---------------+----------------+
| Input         | Output         |
+---------------+----------------+
| 1 - Whatever  | 01 - Whatever  |
| 5 - Whatever  | 05 - Whatever  |
| 10 - Whatever | 10 - Whatever |
+---------------+----------------+

Could you please consider solving this ?

Cheers, and best wished for this end of year !

Add support for subdirectories

First, thanks for the work you've put into this project. I find it really handy. ;)

Is your feature request related to a problem? Please describe.
I think your project could benefit from letting the user also recurse into subdirectories

For, instance, one could replace a whole subtree-structure as follows:

➜ nomino -p -r "(.*)/(.*)/(.*)" "{} {}.{}"

Could restore your default structure

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

from, let's say a structure like this:

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

Describe the solution you'd like
I would recommend that recursion is disabled by default, however, if a / is used, it is turned on automatically. Recursion depth should be an option in the cli as well.

Additional context

Best,
da-h

Missing error messages

Describe the bug
When not having write permissions to files, nomino fails silently

Command

➜ nomino -er "(\d).(.*)" "{}-{}"

Expected
An error message that it could not do what it tried to do. (Running the same command with sudo (obviously) worked)

Command map file (create using -g option)

{
doesnt matter
}

Expected map file

{
tables print fine as expected
}

Version (nomino -V)
nomino 0.4.3

Environment

  • OS: FreeBSD 12.1-RELEASE-p10 GENERIC amd64

Add support of files lists

It would be great to be able to feed nomino a .txt with a list of files which need renaming (full paths, one path per line).

Replace all substrings

Is your feature request related to a problem? Please describe.
I was impressed by the benchmark results and gave nomino a try. It looks like nomino needs a regex pattern of the full string (file path). Most of the time I will just need to replace sub strings in file names but not those in the directory names. E.g., replace all hyphen with space.

Describe the solution you'd like
I might not be aware of it, but has nomino something similar to rnr's sed like solution? rnr -f -r -l0 "pattern" "replacement"

Allow manually specifying search depth

Is your feature request related to a problem? Please describe.
([^/]*)/.* would search one more depth than I expect.

Regex::new(pattern)?,
pattern.chars().filter(|c| *c == MAIN_SEPARATOR).count() + 1,

Describe the solution you'd like
Add a --max-depth and/or --depth option to control search depth of subdirectories.

\d not works on Windows

nomino 1.2.2 on Windows 10 21h2 x64
files in the current dir:
1.txt 2.txt ... 10.txt
nomino -tp "(\d+).txt" "{:2}.txt" (not work)
nomino -tp "([0-9]+).txt" "{:2}.txt" (works)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.