ismaelgv / rnr Goto Github PK
View Code? Open in Web Editor NEWA command-line tool to batch rename files and directories
License: MIT License
A command-line tool to batch rename files and directories
License: MIT License
Hello! rnr
is an excellent tool and I'm very grateful to you for making it!
When I run rnr
a file like rnr-2024-08-09_101725.json
is created in the current directory. This is nice (being able to undo my changes is great!) but a little bit annoying, because Git immediately shows an untracked file I have to be careful to not commit.
In my global gitignore
file, I ignore all files that start with xxx
so that I can write temporary notes and scratch output to files with names like xxx-notes.md
or xxx-ghc-output.txt
and not worry about committing them. I would like to instruct rnr
to write its dump file with a name like this (e.g. xxx-rnr-2024-08-09_101725.json
) to save me the hassle.
Does this make sense? I'm not sure when, but I could probably write an implementation if this sounds like a good idea to you.
Implement silent mode to hide standard output of the application.
For example I have some files:
sadasd.png, asdjklsa,png, kflsadl.png
And I want to rename them to:
1.png, 2.png, 3.png
So as far as I know in current state it's impossible to do it?
P.S. Yeah, I know there are tons of tools that can do it but I'm interested in rnr only because it has working in cmd undo feature.
First of all, thanks for making rnr!
I've spent a few minutes confused as to why the capture groups didn't work, only to realize later that I was using double quotes rather than single quotes, and so my shell (zsh
in that case) was expanding them, thus rnr
didn't receive anything.
A small example. Assuming we have the following list of files (songs encoded at a specific bitrate):
-128K Song1 .opus
-192K Song1 .opus
-128K Song2 .opus
-192K Song2 .opus
We want to rename the files to have the name of the song first, and the bitrate later:
Song1 128K.opus
Song1 192K.opus
Song2 128K.opus
Song2 192K.opus
We come up with a simple pattern: rnr "-(\d+K) (\w+) " "${2} ${1}" *
. However this will not work: before rnr
has the chance to read the arguments, ${2}
will be substituted with the contents of the environment variable 2
, and the same thing with happen for ${1}
.
I don't think there's a technical solution here, however we can add a small warning in the capture groups part of the documentation. Maybe also in the "ARGS" part of the --help
, just after " Expression replacement".
ripgrep
has a paragraph about the same issue in the help text of the -r/--replace REPLACEMENT_TEXT
flag:
In shells such as Bash and zsh, you should wrap the pattern in single quotes instead of double quotes. Otherwise, capture group indices will be replaced by expanded shell variables which will most likely be empty.
I can make a PR if you're okay with the idea.
Add a flag to continue if there are any errors.
Very useful of only half of an undo succeeds.
When I capture a group, how to output a lowercase version of it? Could this be made possible?
It would be nice to set some default options for rnr
, like --backup
, --force
, --hidden
, --recursive
, --include-dirs
, or --silent
.
I would like a configuration file (e.g. ~/.config/rnr.toml
) to set these options in.
This would require a few things:
--silent
is set in the configuration file, an option named something like --loud
or --verbose
can undo that setting at invocation-timeThis is mostly a tracking issue, thanks again for rnr
, it's super useful!
I am not sure if I'm doing something wrong here, but I'm trying to do this:
Statement_022024_1234.pdf->Statement_20240220_5678.pdf
But this command isn't doing what I expect:
rnr "_(\d\d)(\d\d)(\d\d)_1234" "_20${3}${2}${1}_5678" Statement_*
Instead, the dry run tells me that the command will do this:
Statement_022024_1234.pdf->Statement_20_5678.pdf
Is this a bug in rnr
? I've just downloaded it, rnr 0.4.2
Add a flag to ignore version control system directories:
Hi, I want to replace multiple continuous whitespaces to 1 in the folder names. However the following regex doesn't work:
rnr -Dr '\s+' ' ' .
Any idea?
If I use '\s{2,}'
instead of '\s+'
, it works as expected. It seems the + is not supported?
Context (like in the other issue): About a year ago, Diesel changed the name format of the migrations that it generates. I still have many migrations in the old format and want to use rnr
to rename them into the new format.
At first I tried to run this in cmd.exe:
rnr -D '(\d{4})(\d{2})(\d{2})(\d{6})' '$1-$2-$3-$4' ./*
in my migrations folder, but it didn't show any matches/replacements, only This is a DRY-RUN
.
I also tried with double quotes, but I got the same result (no matches/replacements) :/
(When I execute it in the sh.exe of the Git Shell (powershell) of GitHub Desktop for Windows, it works, but it's very inconvenient..)
Is there a way to make it work in cmd.exe, too?
Create a new GitHub workflow to generate releases:
Ignore hidden directories by default. Add new flag to include hidden directories.
--color
): always
, auto
and never
auto
mode.Hello!
Thanks for a great tool. I have an mp3 library I'm trying to wrangle into consistency and rnr has smoothed that path quite nicely. I especially appreciate undo file/dry-run by default.
Anyway, I think it's not possible, but can rnr be incorporated into another rust app via a crate dependency, i.e. is there an api implementation for rnr? Or is the only option to use rnr from within a rust program to call rnr via std process Command?
Thanks!
About a year ago, Diesel changed the name format of the migrations that it generates.
I still have many migrations in the old format and want to use rnr to rename them into the new format.
But how can I do the renaming with git mv
so that git properly recognizes that the folders were renamed?
If I just do rnr -f -D '(\d{4})(\d{2})(\d{2})(\d{6})' '$1-$2-$3-$4' ./*
, git shows the files as being removed and new files added.
When I use git mv
manually, it correctly shows them as renamed..
can provide a parameter to save the historical naming replacement rules
and can give this rule a name.
which I find very useful. :)
Thank you to developed this tools, I love it. ๐ฅฐ
Hi, thanks for rnr
!
It would be nice to highlight in color what is replaced with what in a dry-run mode.
Useful cases:
That's how ripgrep
highlights found matches by default, for instance (rg fn
):
Or another toy example (echo barfoobar | rg bar --replace baz
):
What do you think?
It would be also useful to be able to rename folders not just files.
Hi all,
rnr --force --no-dump to-ascii "UDTEAL - ํด์๊ณ ์๊ธฐ๋.mp3"
This is a DRY-RUN
UDTEAL - ํด์๊ณ ์๊ธฐ๋.mp3 -> UDTEAL - HaeSangGoSogGiDong.mp3
does not rename anything and leads to the same result as
rnr --dry-run --no-dump to-ascii "UDTEAL - ํด์๊ณ ์๊ธฐ๋.mp3"
This is a DRY-RUN
UDTEAL - ํด์๊ณ ์๊ธฐ๋.mp3 -> UDTEAL - HaeSangGoSogGiDong.mp3
Tested on Windows 11 using releases v0.4.2, v0.4.1, and v0.4.0 with both msvc and gnu builds.
Other operations like
rnr --force -r foo bar .
are working just fine.
Kindly check and fix this bug.
Best regards
Hello, thanks for making this wonderful little tool!
I have a scenario where I have a bunch of directories, and each directory has files with same name as directory, but different extensions. Example -
โโโ X Men - Apocalypse (2016) (720p)
โย ย โโโ X Men - Apocalypse (2016) (720p).mp4
โย ย โโโ X Men - Apocalypse (2016) (720p).srt
โโโ X Men - Days Of Future Past (2014) (720p)
โย ย โโโ X Men - Days Of Future Past (2014) (720p).mp4
โย ย โโโ X Men - Days Of Future Past (2014) (720p).srt
โโโ X Men - First Class (2011) (720p)
โย ย โโโ X Men - First Class (2011) (720p).mp4
โย ย โโโ X Men - First Class (2011) (720p).srt
I only want to rename the directories, but not the files inside. Is this possible with rnr? Going through the help page, it doesn't look like rnr supports this, but wanted to confirm.
precondition:
Pattern "strin" should be changed to pattern "strout" in current directory
Does not work next command
rnr -n -r strin strout ./*
but the workaround with recursive option and dept=1 works well:
rnr -n -r -d 1 strin strout ./
next issue
regexp with single quotes does not work correct,
rnr -n -r -d 1 '(.+)\.d(\w+)' '${1}' ./
but double quotes works well
rnr -n -r -d 1 "(.+)\.d(\w+)" "${1}" ./
Unicodeยฎ Standard Annex #15
unicode-rs/unicode-normalization
NFC and NFD are particularly beneficial for macOS users. While APFS supports both NFC and NFD, many macOS APIs and applications automatically convert filenames to NFD. See: gist
NFKC and NFKD are useful for compatibility purposes. For example, it can convert Japanese squared characters like ใฟ and ใ to their compatible equivalents, such as ๆ ชๅผไผ็คพ and ใขใใผใ. See: UAX #15: Examples of Compatibility Equivalence
This tool seems very useful, does it support Windows, too? :)
Implement an interactive mode similar to git add --interactive
, git add --patch
, package managers, etc.
Detect non-compatible colored output when auto
is set.
Thank you for this amazing tool.
I am wondering if it's possible to achieve the following in a single pass of rnr:
.
โโโ dir1/
โ โโโ file:with_a_*
โ โโโ file2_also_has<a_**-3
โโโ dir2/
โโโ some!<other_file": ok?
I want to change [*<"?!]
chars to underscores _
and change colon :
to -
(hyphen surrounded by space)
Final result should be:
.
โโโ dir1/
โ โโโ file - with_a__
โ โโโ file2_also_has_a___-3
โโโ dir2/
โโโ some__other_file_ - ok?
Is it possible?
Improve return code from different errors in the application to be properly handled by terminal/shells.
Add new option that let user replace more than one occurrence, currently is default to first match.
Add an option to dump the operation to a file (rename list). Also, rnr
should allow reading that file to do/undo the operation.
i am using this tool mainly to fix filesystem issues that i am having after working with different files from different sources, an example being files using UTF-8 character set outside the standard ascii range like Asian, Slavic, extended Latin or German special characters (i.e. 'ฤ
ลลฤลผ' ). Those files while working on modern file systems like btrfs without a problem but in some cases, for example when being copied or transferred to file systems not supporting UTF-8 out of the box, it's erroneous or just prevents me from doing so, since the drivers do not know what to do with those.
Here comes the RnR which i use to strip those as far as i am able to, but it takes some wizardry to do properly and i am still not sure if i am not overlooked something. Also, it's extremely lossy at this moment.
there is an library that translates the special characters to ASCII bound ones - https://github.com/anyascii/anyascii
can we get a flag that for example in addition to running regexp, forces the special characters to be conversed to the ascii ones? for example, --restrict
this issue is related mainly to unix/linux platform.
On Windows, with a case-insensitive but case-preserving file-system, what's the best way to change the case of a file?
For example, this command produces an error message:
$ rnr -f .JPG$ .jpg image.JPG
Error: Conflict with existing path image.JPG -> image.jpg
Currently I'm renaming via a temp file name (eg, rename to .jpg.tmp
, then strip out the .tmp
). Maybe this would work if the conflict detection ignored the source file when checking to see if the target file exists, which is kind of an edge case due to case-insensitivity where the source file won't conflict once it has been renamed.
Excellent tool, would be great to have it available in Homebrew!
Extend code to support non-valid UTF-8 strings in filenames, paths and arguments:
clap
, regex
, walkdir
and ansi_term
Create several examples explained in detail in the documentation.
Hello. I am a designer. I can design a logo for you. If you like it, I'll give it a gift.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.