Giter Club home page Giter Club logo

stdrename's Introduction

stdrename

Build Status

This small utility is designed to rename all files in a folder according to a specified naming convention (camelCase, snake_case, kebab-case, etc.).

It currently supports the following naming conventions:

  • camelCase
  • kebab-case
  • lower case
  • PascalCase
  • SCREAMING_SNAKE_CASE
  • Sentence case
  • snake_case
  • Title Case
  • Train-Case

screenshot-of-stdrename

Installation

Manual

  1. Download the latest binary executable release supported by your OS.

    For most Linux distributions, download stdrename-x86_64-unknown-linux-gnu.

    For Windows, download stdrename.exe.

    No macOS binary is available yet, but stdrename can still be installed using Cargo.

  2. Add it to your PATH.

    On Linux and MacOS, this is achieved by executing the following command in your terminal after downloading the file.

    chmod +x ~/Downloads/stdrename && sudo mv ~/Downloads/stdrename /usr/local/bin

    On Windows, you can move the file to a new folder such as "C:\Users\YourName\bin" and then add the folder to your PATH using the instructions here.

Cargo

If you have cargo installed you can install stdrename with:

cargo install stdrename

The executable file can then be found in $HOME/.cargo/bin/stdrename.

On Linux and MacOS to make sure $HOME/.cargo/bin is in your $PATH add the following line at the end of .bashrc (in your home directory):

export PATH="$HOME/.cargo/bin:$PATH"

Usage

You must specify the naming convention you want to use with the appropriate flag. For example, this will rename all files in the current directory using the kebab-case naming convention.

stdrename -k

Here is the full list of naming convention flags that can be used:

Short Long Example
-c --camel camelCase.txt
-k --kebab kebab-case.txt
-l --lower lower case.txt
-p --pascal PascalCase.txt
--screaming SCREAMING_SNAKE_CASE.txt
-S --sentence Sentence case.txt
-s --snake snake_case.txt
-T --title Title Case.txt
-t --train Train-Case.txt

Specifying a different folder to parse

You can also specify a different folder to parse with a second argument e.g.:

stdrename -k ~/Pictures

Renaming files in subfolders as well

To rename recursively, use the flag -r or --recursive e.g.:

stdrename -kr ~/Pictures

Renaming directories as well

To rename directories as well, use the flag -D or --dir e.g.:

stdrename -kD ~/Pictures

Ignoring files and subdirectories

By default, patterns in .gitignore files, global gitignore files and git exclude files will be ignored as well if the directory is a git repository.

You may also add a .ignore file with patterns to ignore in the file's directory and its subdirectories.

This file may use any of the glob patterns that can be used in a .gitignore file. It is functionally the same, just with a different name e.g.:

Adding the following line in a new .ignore file in the same directory as stdrename will ignore all files with the extension .py and all files in the subdirectory ./target/ when renaming.

# ./.ignore
# ignore all files ending with .py
# ignore all files in /target and its subdirectories

*.py
/target

You may even add a second .ignore file in a subdirectory e.g.:

# ./subdir1/.ignore
# match .py files despite previous instructions
# ignore .txt files in this directory and all subdirectories

!*.py
*.txt

All files in that directory and all sub directories will then reinclude .py files and ignore .txt files.

If you'd like to use global ignore patterns specific to stdrename, you can do so by creating an "ignore" (notice this one does not start with a ".") in the following location:

On Windows: %USERPROFILE%\AppData\Local\stdrename\"

On Unix based systems (e.g. MacOS or GNU Linux):

$HOME/.config/stdrename/

This file follows the same pattern matching principles as other .gitignore or .ignore files and has a lower precedence than all other sources of ignore rules.

--text mode

Text mode allows for either piping through stdin, e.g.:

echo 'Hello World' | stdrename --text -k

or interactive use, e.g.:

stdrename --text -s
reallyCreativeProgramName.js
really_creative_program_name.js
PYTHONISTA_BANANA.py
pythonista_banana.py
This is really just a normal sentence
this_is_really_just_a_normal_sentence

Either way, the program terminates and stops reading as soon as it encounters an empty line.

To suppress the exit message (if piping stdout to another file for example) add the -q or --quiet flag.

stdrename's People

Contributors

fossabot avatar gadiguibou avatar smhmd 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

Watchers

 avatar  avatar  avatar

stdrename's Issues

[Request] Lowercase convention

$ echo "Party Perfect Keep Dinner Simple Heat Frozen" | stdrename --text -l
party perfect keep dinner simple heat frozen

ERROR: Access is denied

❯ .\stdrename.exe -srD "C:\Users\ptanmay143\!data"
Application error: The system cannot find the path specified. (os error 3)

[Request] support files with multiple dot separators in file name

Hi! Thank you for writing this library, it's really helpful.

Here's the story behind the request - in a project I'm working on, we have a naming convention where we have [name].[type].[ext].

For example, I'd like to be able to use this util for a file like logger-manager.service.ext, or logger-manager.request-interceptor.ext ( it's a little enterprise-y but it's what I'm working with )

It seems that the extension is currently detected as whatever comes after the first . - the current behavior of stdrename -c is causing this file to become loggerManagerService.ext.

it'd be nice to have dot separators considered separately from other characters. I know this case is a little non-standard, and I appreciate you putting this work up in the first place.

Would be happy to discuss further!

Global config

A global ignore file (~/.config/stdrename/ignore) would be great.

Group flags in `--help`

I'm not sure if this is possible within your CLI framework, but grouping flags as such (or some other way):

CONVENTIONS:
    -k, --kebab        Uses the kebab-case naming convention
    -p, --pascal       Uses the PascalCase naming convention
        --screaming    Uses the SCREAMING_SNAKE_CASE naming convention
    -S, --sentence     Uses the Sentence case naming convention
    -T, --title        Uses the Title Case naming convention
    -t, --train        Uses the Train-Case naming convention
    -c, --camel        Uses the camelCase naming convention
    -s, --snake        Uses the snake_case naming convention

FLAGS:
    -D, --dir          Renames directories as well
    -r, --recursive    Makes renaming recursive, renaming files in subfolders as well
    -q, --quiet        Suppress output

    -h, --help         Prints help information
    -V, --version      Prints version information

And, perhaps, to simplify USAGE as such:

USAGE:
    stdrename [FLAGS] <convention> [TARGET]

Use flags instead of strings/help flag

It's evidently painful to type any of these arugments:

Arguments Examples
camelCase "camelCase.txt"
kebab-case "kebab-case.txt"
PascalCase "PascalCase.txt"
SCREAMING_SNAKE_CASE "SCREAMING_SNAKE_CASE.txt"
Sentence_case "Sentence case.txt"
snake_case "snake_case.txt"
Title_Case "Title Case.txt"
Train-Case "Train-Case.txt"

Could you make these actual CLI arguments?

"Arguments" Actual Arguments
camelCase -c, --camel
kebab-case -k, --kebab
PascalCase -p, --pascal
snake_case -s, --snake
Title_Case -t, --title
Sentence_case -S, --sentence
SCREAMING_SNAKE_CASE -C, --scream
Train-Case -T, --train

also, a -h, --help flag that displays something like this:

stdrename is a tool for renaming files based on naming conventions.

usage:
stdrename <convention flag> <dir> [-r]

flags:
-c, --camel    : camelCase           
-k, --kebab    : kebab-case          
-p, --pascal   : PascalCase          
-s, --snake    : snake_case          
-t, --title    : Title Case          
-S, --sentence : Sentence case       
-C, --scream   : SCREAMING_SNAKE_CASE
-T, --train    : Train-Case

-r, --recursive: rename recursively

Error handling could also be better with:

- Application error: naming convention not found
+ Naming convention not found. Run stdrename -h for a list of supported conventions.

(and dare I say the name is a little bit hard to remember/type.)

Bug: Files with same name in recursive operations

Hi there,

first: Thanks for this great tool!

I have found a small bug related to recursive operations, I have not completely analysed it yet.

MWE:

test/
|
|-- test-file.txt
|-- test-2/
     |-- test-file.txt     
     |-- test-3/
          |-- test-file.txt     

In /test folder: stdrename -tDr (also other alternatives)

Expected:

test/
|
|-- Test File.txt
|-- Test 2/
     |-- Test File.txt     
     |-- Test 3/
          |-- Test File.txt     

Actual (after first run):

test/
|
|-- test-file.txt
|-- Test2/
     |-- test-file.txt     
     |-- test-3/
          |-- test-file.txt     

(os error 3) (I currentöy have german language error messages, basically: The OS cannot find the provided path)
After another run:

test/
|
|-- test-file.txt
|-- Test2/
     |-- test-file.txt     
     |-- Test3/
          |-- test-file.txt     

same error, and then again another run;
Success (with bug, see below):

2 files renamed in 0.001352 s. See you next time!
Actually 3 files and another folder have been renamed.

test/
|
|-- Test File.txt
|-- Test2/
     |-- Test File.txt     
     |-- Test3/
          |-- Test File.txt     

The problems are probably in the area:

  • Parsing/interpreting number symbols in folder names
  • Multiple files with the same name

If I now on the changed structure use stdrename -kDr to revert the changes, I get

test/
|
|-- test-file.txt
|-- test-2/
     |-- Test File.txt     
     |-- Test3/
          |-- Test File.txt     

Same error (os 3)

Next time:

test/
|
|-- test-file.txt
|-- test-2/
     |-- test-file.txt     
     |-- test-3/
          |-- Test File.txt     

Same error (os 3)

Last (3rd) time;

test/
|
|-- test-file.txt
|-- test-2/
     |-- test-file.txt     
     |-- test-3/
          |-- test-file.txt     

1 files renamed in 0.00111 s. See you next time!

So the operations are revertable.

Hope this helps!

Default action

Even though kebab-case is my preferred convention as well, I think the default action of stdrename, i.e. stdrename kebab-case . is dangerous. I almost ran it in my home directory before I backed up and tested it in a directory in /tmp. (I know it's indicated in README, but it's easily missed.) The default action could be equivalent to stdrename -h (much like git and other popular CLIs.)

error[E0658]: use of unstable library feature 'scoped_threads'

To reproduce

  • Install cargo on Ubuntu with
sudo apt install cargo
  • Run cargo install stdrename.

The error

[...]
   Compiling Inflector v0.11.4
   Compiling ignore v0.4.20
error[E0658]: use of unstable library feature 'scoped_threads'
    --> /home/andrew/.cargo/registry/src/github.com-1ecc6299db9ec823/ignore-0.4.20/src/walk.rs:1285:9
     |
1285 |         std::thread::scope(|s| {
     |         ^^^^^^^^^^^^^^^^^^
     |
     = note: see issue #93203 <https://github.com/rust-lang/rust/issues/93203> for more information

error[E0658]: use of unstable library feature 'scoped_threads'
    --> /home/andrew/.cargo/registry/src/github.com-1ecc6299db9ec823/ignore-0.4.20/src/walk.rs:1299:32
     |
1299 |                 handles.push(s.spawn(|| worker.run()));
     |                                ^^^^^
     |
     = note: see issue #93203 <https://github.com/rust-lang/rust/issues/93203> for more information

error[E0658]: use of unstable library feature 'scoped_threads'
    --> /home/andrew/.cargo/registry/src/github.com-1ecc6299db9ec823/ignore-0.4.20/src/walk.rs:1302:24
     |
1302 |                 handle.join().unwrap();
     |                        ^^^^
     |
     = note: see issue #93203 <https://github.com/rust-lang/rust/issues/93203> for more information

For more information about this error, try `rustc --explain E0658`.
error: could not compile `ignore` due to 3 previous errors
warning: build failed, waiting for other jobs to finish...
error: failed to compile `stdrename v1.3.0`, intermediate artifacts can be found at `/tmp/cargo-install8cEAgp`

Explanation

I'm not an expert on Rust, so I'm not totally sure - but it looks like the rust compiler does not want you to use scoped threads. There's probably a way to force cargo to install this anyway, but I don't know it.

Request: Files renamed count

It would be great if the finish message would say:

60 files renamed.
(^ _ ^)/ See you next time!

Also, is the new line before the message intentional? It's a bit untidy/unsettling, imo.

Folders only

Hi, is there any way to rename only folders, excluding any files within them?

Files get overwritten if new names are the same

To reproduce:
Run the following commands:

$ mkdir test
$ cd test
$ touch thisTest.txt this_test.txt
$ ls
thisTest.txt this_test.txt
$ stdrename -s
$ ls
this_test.txt

Observed behavior:
If you have two different files which have the same name but different naming conventions, when you use stdrename to change them to have the same naming convention one will get overwritten.

Expected behavior:
Either the name doesn't get changed or something is added to the name to avoid the collision, e.g. "this_test.txt" and "this_test_1.txt" (just a quick example; there may be better naming scheme ideas).

Ignore directory with based on their content/ignore git repo directories

Instead of ignoring directories based on their name in the ignore file, it would also be great to ignore directories based on their content. E.g., ignore all directories that have .git/node_modules even if you're renaming recursively. (I lost unpushed git commits to this once 😢 RIP in peace.)

If this would be too complicated for nothing, an option to never rename git directories would suffice, I think.

Feature request: provide binaries that don't depend on glibc 2.18

Hi,

Today, I tried running stdrename on a system that does not have glibc (or at least not 2.18+) installed.
It gives me the following error:

/stdrename: /lib64/libc.so.6: version `GLIBC_2.18' not found (required by ./stdrename) 

I never knew it, but this is something that affects almost everything that's built with rust.

You can statically link MUSL to make the program not rely on glibc, or compile with a really old version since glibc is forward-compatible.
https://saarw.github.io/dev/2020/06/18/shipping-linux-binaries-that-dont-break-with-rust.html

It would be great if this could be incorporated, so stdrename can be a truly "it just runs" binary.


Off-topic: This great tool has been a very helpful tool in my Linux toolbelt for a while. It's so simple, yet so perfect for everything I need it for (well, until today ofc).

[bug] Sentence case should preserve sentences.

-S should preserve sentences.

$ echo 'This is a sentence. this is another sentence' | stdrename --text -S
This is a sentence. this is another sentence
$ echo 'This is a sentence. this is another sentence.' | stdrename --text -S
This is a sentence this is another sentence

First case, this is another... should be This is another....
I'm not sure why having a dot at the end of the input results in all dots being removed in the second case.

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.