Coder Social home page Coder Social logo

marcusbuffett / pipe-rename Goto Github PK

View Code? Open in Web Editor NEW
385.0 6.0 14.0 293 KB

Rename your files using your favorite text editor

Home Page: https://crates.io/crates/pipe-rename

License: MIT License

Rust 97.23% Python 2.77%
command-line-tool devtool rust

pipe-rename's Introduction

pipe-rename

Crates.io

pipe-rename takes a list of files as input, opens your $EDITOR of choice, then renames those files accordingly.

Installation

cargo install pipe-rename

This will install the renamer binary.

Usage

Usage is simple, just pipe a list of files into renamer. This will open your $EDITOR (or vim, if not set or passed with --editor) -- or %EDITOR% (or Notepad on Windows, if not set or passed with --editor), and once your editor exits it will detect which files were renamed:

ls | renamer

You can also supply filenames as positional arguments. To rename .txt files in the current directory:

renamer *.txt

The default behavior is to rename files, but you can override this. If you want to run git mv old new on each rename, you can do something like this:

ls | renamer --rename-command "git mv"

Help text

Takes a list of files and renames/moves them by piping them through an external editor

USAGE:
    renamer [OPTIONS] [FILES]...

ARGS:
    <FILES>...


OPTIONS:
    -c, --rename-command <COMMAND>
            Optionally set a custom rename command, like 'git mv'

    -e, --editor <EDITOR>
            Optionally set an editor, overriding EDITOR environment variable and default

    -f, --force
            Overwrite existing files

    -h, --help
            Print help information

    -n, --filenames-only
            Only rename filenames

    -p, --pretty-diff
            Prettify diffs

    -u, --undo
            Undo the previous renaming operation

    -V, --version
            Print version information

    -y, --yes
            Answer all prompts with yes

Caveat emptor

NB: it makes sense to be aware of the issues ls can cause in this context, depending on the ls flavor (or substitute, such as lsd, exa ...) used. Please read this document for more information.

While your shell will pass the file names individually, no matter if they contain whitespace, an ls that fails to detect the pipe and print one file name per line will cause issues. Unfortunately ls -Q also isn't a solution here, because unlike the shell -- which will strip quotes prior to passing them to invoked commands -- renamer won't handle the quoted names and will probably complain about non-existent files, too.

Advanced usage

If you have tools like GNU find at your disposal, you can also use the following method:

find -type f -exec renamer {} +

This would execute renamer with all of the files matched by find. You can use additional find predicates such as -name or -ipath to limit which files to rename. There is, however, one caveat: on large lists of files you may encounter multiple invocations of renamer -- and thus your editor -- due to how find ... -exec {} + works. It will pass as many file names on the command line as it can fit but it is limited by ARG_MAX (see getconf ARG_MAX output for how long the overall command line length can be on your system).

Other find flavors would allow the following, but it would invoke renamer -- and thus your editor -- once for every single found file:

find -type f -exec renamer {} \;

In order to sidestep this issue, you can employ xargs in conjunction with find like so (-print is implied for find):

find -type f | xargs renamer --editor vim

The part past xargs is the invocation of renamer without the file names. It exists just to demonstrate how you would pass arguments to renamer using this method.

If your files contain wonky characters you could also try:

find -type f -print0 | xargs -0 renamer --editor vim

Alas, this could be asking for trouble. If your file names contain line breaks, for example, this could confuse renamer which expects a single file name per line when re-reading the edited file.

Known workarounds

renamer will wait for the editor to close, before offering to rename the files according to your changes. Some editors cause issues with this method, because they spawn child processes or similar. This is a list of known workarounds for some editors. Feel free to contribute by sending a pull request or opening an issue and giving the details.

We can work around these issues by explicitly using a method to invoke the desired editor, which works with the assumptions made by renamer. It can be done by passing --editor (short -e) or setting the environment $EDITOR (%EDITOR% with cmd.exe or $env:EDITOR with pwsh.exe).

  • Sublime Text can be used by passing --editor "subl -w" to have it wait until the files are closed

Windows-specific workarounds

  • VS Code can be used by passing --editor "code.cmd -" and then giving the other files
  • VSCodium analogously can be used with --editor "codium.cmd -"

Contributors ✨


Marcus Buffett

🤔 💻

Robin Krahl

🤔 💻 🐛

Max Timkovich

🤔 💻

Benoit de Chezelles

🤔

Oliver Schneider

🤔 💻

This project follows the all-contributors specification. Contributions of any kind welcome!

pipe-rename's People

Contributors

assarbad avatar bew avatar femiagbabiaka avatar marcusbuffett avatar mtimkovich avatar pythoncoderas avatar robinkrahl 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  avatar

pipe-rename's Issues

using pipe-rename in a pipe seems to misconfigure terminal

$ echo unum.pl |renamer

This should work well, but instead on exit from vim, my terminal doesn't convert line endings correctly anymore. I'm using vim 8.2.1525. bash 5.1.4.

I think your project is fine, and some new ideas, which is why I'm using it in my mpvreadname project.

If you used a temporary file I think the problems would go away. please remember bash might close the piping subshell after it reconfigures the terminal for the bash prompt and readline.

Crashing when editor closes, after editing a given line

When on Ubuntu 20.04 with UTF-8 as code page I am seeing the following:

$ env RUST_BACKTRACE=1 renamer Wirecard\ -\ Die\ Milliarden-Lüge.mp4 Zölibat\ -\ Der\ katholische\ Leidensweg\ \[1080464
5\].mp4
thread 'main' panicked at 'byte index 2 is not a char boundary; it is inside 'ö' (bytes 1..3) of Zölibat - Der katholische Leidensweg.mp4', library/core/src/str/mod.rs:127:5
stack backtrace:
   0: rust_begin_unwind
             at /rustc/e092d0b6b43f2de967af0887873151bb1c0b18d3/library/std/src/panicking.rs:584:5
   1: core::panicking::panic_fmt
             at /rustc/e092d0b6b43f2de967af0887873151bb1c0b18d3/library/core/src/panicking.rs:142:14
   2: core::str::slice_error_fail_rt
   3: core::ops::function::FnOnce::call_once
             at /rustc/e092d0b6b43f2de967af0887873151bb1c0b18d3/library/core/src/ops/function.rs:248:5
   4: core::intrinsics::const_eval_select
             at /rustc/e092d0b6b43f2de967af0887873151bb1c0b18d3/library/core/src/intrinsics.rs:2372:5
   5: core::str::slice_error_fail
             at /rustc/e092d0b6b43f2de967af0887873151bb1c0b18d3/library/core/src/str/mod.rs:86:9
   6: core::ops::function::impls::<impl core::ops::function::FnMut<A> for &mut F>::call_mut
   7: <alloc::vec::Vec<T> as alloc::vec::spec_from_iter::SpecFromIter<T,I>>::from_iter
   8: renamer::main
note: Some details are omitted, run with RUST_BACKTRACE=full for a verbose backtrace.

For the issue to surface I need to:

  • pass at least two names, editing the second line
  • first name (or renaming of it) doesn't seem to matter at all, as long as the file exists and the other (above second) entry is preceded by some file name

I am still collecting more information on this on my end, but I suspect some sort of normalization issue. This happens on an NTFS drive (which may play a role) with the commercial version of the Paragon NTFS driver (may also play a role). Could also have to do with NTFS as storage (which uses UTF-16 internally and may use other Unicode normalization rules).

I'll have to try to narrow this down further, but wanted to already bring this to your attention to the extent to which I have gathered information.

What would be great to see, however, would be the real bytes underneath. I mean I trust Rust to figure out if we end up in the middle of a surrogate or so, but since environmental factors like (potentially) normalization on part of the editor, the file system etc could play a role, it would be great to see input and output as raw bytes in case of this sort of panic.

Doesn't seem to work with VSCode

> O:\bin\pipe-rename-1-6-5-msvc.exe --editor code .\file1.jpg .\file2.txt
Error: Failed to execute editor command: 'code'

Caused by:
    program not found

Store each path as a Path instead of a String (which is utf8-only)

Comment on:

pipe-rename/src/main.rs

Lines 168 to 175 in 5658581

fn expand_dir(path: &str) -> anyhow::Result<Vec<String>, io::Error> {
Ok(fs::read_dir(path)?
.filter_map(|e| e.ok()
.and_then(|e| e.path()
.into_os_string()
.into_string().ok()))
.collect())
}

I'm thinking, the filter_map exists only because the conversion from an OsString to a String could fail if the path is not UTF-8 and we might get an Err(...) instead of an Ok(String).

Edit: the filter_map also exists because each entry in from read_dir can be an error, my bad.
My observation is still valid though and is on: .into_string().ok() which will return None for a non-utf8 path, and discard it.

I don't think that's right, the tool shouldn't skip non-utf8 paths.

@marcusbuffett I'm wondering if we could change something in the entire codebase:
--> Instead of storing each path in a String (utf8), we could simply keep it as a Path (which can contain non-utf8).
For the occasional cases where we need to print a path (like for the diff), we could use a replacement char for the non-utf8 chars. With a note for the user at the end of the diff if at least one path is non-utf8, the detection / change could be done before the diff to not over complicate it.


NOTE: I'd be interested to take a stab at this if you're ok with this

Idea: post-processing of certain characters

I am using renamer a lot to tidy up the names of downloaded articles, papers etc.

Issues that I encounter a lot are characters such as double quotes "some phrase" which could be defanged into „some phrase“ or : which is invalid on Windows and could be defanged into , similarly to ? which could be defanged into . Additionally \n (LF) occurs in some file names copied based on titles of papers, which is no issue on Linux, but becomes an issue when copying to exfat/FAT32 (etc.).

I wonder how this could be best implemented and whether renamer itself is the right scope or whether it should simply allow to call a post-processing executable (no arguments allowed) to pipe the contents through after they were edited by the user.

What are your thoughts?

Misbehaving on Windows without %EDITOR%

On Windows (using 88ea95b) I noticed some quite strange behavior in renamer compared to Linux. If I unset EDITOR on Linux, it'll still open an editor (well of course it does), but on Windows nothing will work without setting the environment variable. Additionally the error when the program execution fails is anything but helpful ("Failed to execute editor process" 🤨); here it would make sense to stash the path/name in the error message.

I also think it should default to notepad.exe which on modern Windows is going to be able to handle Unix line endings and so on and should be perfectly capable of handling basic renaming. It is definitely a better choice than vim for Windows users.

Probably this is a good case for implementing an -e/--editor command line switch as per #44.

Renaming on a drive with case-insensitive file system (or a file system placed into that mode)

I encountered that when I changed the casing of a single letter in a file name on an exfat USB stick (i.e. case-insensitive, but case-retaining), renamer complained that it would overwrite existing files.

This happened on Linux with 1.6.5.

May be related to #75?!

PS: the obvious fix is the same that everyone knows from Windows in order to rename a file and only change the casing: simply split it into two. 1. rename to something else (e.g. append _) then 2. do the case change and remove the appended "something".

Alternative diff mode for confirmation

On the confirmation step, the output can be difficult to read, to see the real differences:

  • when the terminal width is (too) small
  • when the file names are long
  • when the changes are small

I'm suggesting the use of another way to show the changes, similar to a git diff (with potential nice colors to highlight the changes), so instead of the current old_file -> new_file we could have:

  • plain diff mode:

    - old_file
    + new_file
    
    - old_other_file
    + new_other_file
    

    like this:
    rename-plain

  • smart diff mode: same as plain diff mode but with additional details on the changes (similar to delta, maybe some things can be re-used there, or use the same algorithm as delta (or a simpler one!) for the diff details)

    like this:
    rename-hi
    (and we could still add the -/+ like the plain mode, in case colors don't work for some reason)

What do you think about this?

Support other rename methods, e. g. git mv

I really like this approach for bulk renaming! It would be nice to be able to use this with git mv. Currently, I can call pipe-rename and then git add -A, but this only works if there are no unstaged changes.

What do you think about adding a --rename-command option so that I could call ls * | renamer --rename-command "git mv"?

Error: Nonexisting input files. Aborting.

Error is shown even if file exists!

$ ls
PARSIFAL - Bavarian State Opera-1.mp4  PARSIFAL - Bavarian State Opera-3.mp4
PARSIFAL - Bavarian State Opera-2.mp4  PARSIFAL - Bavarian State Opera.mp4
$ ls | renamer 
The following input files do not exist:
PARSIFAL - Bavarian State Opera-1.mp4  PARSIFAL - Bavarian State Opera-3.mp4
PARSIFAL - Bavarian State Opera-2.mp4  PARSIFAL - Bavarian State Opera.mp4

Error: Nonexisting input files. Aborting.
$ ls -la
total 573M
664 -rw-rw-r-- 1 nikhil nikhil 123M 2022-04-15 19:57 PARSIFAL - Bavarian State Opera-1.mp4
664 -rw-rw-r-- 1 nikhil nikhil 123M 2022-04-15 19:57 PARSIFAL - Bavarian State Opera-2.mp4
664 -rw-rw-r-- 1 nikhil nikhil 169M 2022-04-15 19:57 PARSIFAL - Bavarian State Opera-3.mp4
664 -rw-rw-r-- 1 nikhil nikhil 161M 2022-04-15 19:41 PARSIFAL - Bavarian State Opera.mp4
$  renamer  *.mp4
Error: No replacements found

error[E0599] no function or associated item named `parse` found for struct `Opts` main.rs

Along with #40, I received the following error when trying
cargo install pipe-rename

error[E0599]: no function or associated item named `parse` found for struct `Opts` in the current scope
   --> /home/sugimoto/build/cargo/registry/src/github.com-1ecc6299db9ec823/pipe-rename-1.4.0/src/main.rs:317:22
    |
33  | struct Opts {
    | ----------- function or associated item `parse` not found for this
...
317 |     let opts = Opts::parse();
    |                      ^^^^^ function or associated item not found in `Opts`
    |
    = help: items from traits can only be used if the trait is implemented and in scope
    = note: the following trait defines an item `parse`, perhaps you need to implement it:
            candidate #1: `Parser`

Not sure if it is related, but I figured I should file an issue just in case.

Allow to re-edit on confirmation step

Imagine you make some changes, and at the confirmation step you realise you made a mistake.

It would be nice to be able to add more actions than yes/no like:

  • edit (re-open the tmp file to continue edit)
  • restart/reset (discard the tmp file and make a new one)

What do you think of this?

Can't use command line arguments in EDITOR

I use Visual Studio Code, and I have to pass the --wait option to use it with pipe-rename. However, if I try doing that, I get an error:

PS C:\Files> $env:EDITOR="code.exe --wait"
PS C:\Files> renamer *.txt
Error: Failed to execute editor process

Caused by:
    The system cannot find the file specified. (os error 2)

I found that, as a workaround, I can create a batch file, say code-wait.bat, containing

code --wait %1

and then set EDITOR to it:

PS C:\Files> $env:EDITOR="code-wait.bat"

And then it works, but I'd rather not have to use the batch file. I may try to fix this someday if no one else does.

I'm using Windows 10 and pipe-rename 1.3.0 (updated today from crates.io).

BTW, I love the idea of pipe-rename! Thanks for writing and releasing it!

Odd error message when attempting to pass full path to --editor

I get the following (found while looking into #76), running from cmd.exe.

>renamer -p -e "%LOCALAPPDATA%\Programs\Microsoft VS Code\code.exe" *
Error: Failed to execute editor command: 'C:UsersOliverAppDataLocalProgramsMicrosoft VS Codecode.exe'

Caused by:
    program not found

The same can be got via pwsh.exe:

$ & renamer -p -e "$env:LOCALAPPDATA\Programs\Microsoft VS Code\code.exe" *
Error: Failed to execute editor command: 'C:UsersOliverAppDataLocalProgramsMicrosoft VS Codecode.exe'

Caused by:
    program not found

It appears that either the output of the path interpolates the backslashes somehow or the path gets interpolated by renamer (1.6.5) removing all backslashes.

@mtimkovich My current working theory is that shell_words::split() and/or shell_words::join() are coming back to haunt us in this case. Mind you, I introduced those 😑. It may be sufficient to make sure that all backslashes are doubled on Windows. I'll have a look.

Messed up terminal after calling pipe-rename

After calling renamer, somehow my terminal is messed up: I no longer see the input that I type, and new lines are no longer aligned at column 0. My first guess was that pipe-rename might forget to clear some ANSI escape code, but at first glance, I can’t find the problem in the source code. Maybe it is related to the spawned editor process?

Environment:

  • GNU bash 5.0.3
  • st 0.8.2
  • $EDITOR is vim 8.1.1401

Hello from xplr

Hi, nice tool. I have migrated the bach rename xplr hack from mmv to pipe-rename because it supports reading filenames from stdin.

This solves the following problems:

  • I don't have to deal with escaping file paths that include white spaces. I can just use cat $XPLR_PIPE_RESULT_OUT | renamer.
  • The input is not limited to the maximum size of command-line arguments supported by the system.

Really neat thinking 👍

Also, I like the custom rename command argument. That gave me this project idea of a more generic tool, let's call it batch.

So when I execute ls | batch 'mv {} {}', editor will open

mv "a" "a"
mv "b" "b"

or rm -rf {}

rm -rf "a"
rm -rf "b"

Basically xargs but lets you edit and review the operation before executing, with a nice confirmation prompt.

Create directories if needed

Right now if you add/change the directory part of the path then it will (silently) fail. It seems to work correctly if I try to move it to an existing directory.

We would have to add some mkdir -p calls (or equivalent), either after detecting that the directory doesn't exist or just always doing so.

It might also be nice to be able to delete (clear the line) or create (touch) files (add a new line to the end), but that might be even more out of scope

Can't pipe file names to pipe-rename without -y

I've ran into an issue when piping file names into rename. The editor opens correctly, but after closing it the program immediately exits at the prompt:

Execute these renames?:
> Yes
  No
  Edit
  Reset
Error: Incorrect function. (os error 1)
error: process didn't exit successfully: `target\debug\renamer.exe` (exit code: 1)

Running in debug mode didn't provide a stack trace but it looks like it's the call to dialoguer::prompts::select::Select. Using -y to skip the prompt works as an alternative. I'm using Windows if that makes a difference.

Also, thanks for this cool tool 👍

Correctly handle `.` and `..`

What I'm thinking of doing is if the argument is just one directory, expand it e.g:

renamer .
renamer ..
renamer src

Globs aren't expanded on Windows

If I run this command:

PS C:\Files> renamer *.txt

Then this file opens in my text editor:

*.txt

Windows passes command line arguments as-is to programs, and it seems that pipe-rename doesn't expand the glob like I would expect. I found that I can use this command:

PS C:\Files> renamer (Get-Item *.txt)

and then the opened file looks like I'd expect:

C:\Files\file1.txt
C:\Files\file2.txt

And I can rename files. But using (Get-Item *.txt) is annoying, and I probably won't remember it the next time I use pipe-rename.

I'm using Windows 10, PowerShell, and pipe-rename 1.3.0 (updated today from crates.io).

Check if file already exists before renaming

To avoid accidentally overriding files, pipe-rename should check whether a target file already exists before renaming. This would also help to avoid a potential problem if the user selects the name of one of the input files as an output file.

Expand `~/` in the replacement list

Right now, if you try to rename something using ~ it'll fail, so instead, replace it with env::var("HOME"), if set.

This expansion would only happen if the path starts with exactly ~/.

e.g.

.vimrc -> ~/.vimrc -> /home/max/.vimrc

Provide binaries, please

I am on Windows, using Internet through my phone and its Internet phone plan (slow, limited connection).
To use your software, I have to use cargo.
To use cargo, I how to download rustup.
To run it, I have to download Visual Studio Installer.
This one is a more than 1 GB download!
That's a lot to get a "simple" command line tool, no?

I like the concept of your tool, leveraging the power of the text editor of our choice rather than dealing with more or less exotic options. But the entrypoint is a bit too high.

Found an issue when renaming overwrites existing file

I tried to rename a number of .epub files. Seven to be precise.

In the course of renaming, I changed one existing file to another name and gave a new file that previous name. So essentially I had something like (condensed to two files):

ABC -> ABC1
BCD -> ABC

It complained that the renaming of BCD to ABC would overwrite existing files.

There were two issues with that:

  1. it didn't include all renames performed
  2. it wrongly concluded that the renaming of BCD to ABC would overwrite the file which -- in the same renaming session -- had been reassigned the name ABC1

Here's the actual output:

$ renamer *.epub

The following replacements overwrite existing files:
Циолковский Константин. На Луне - royallib.com.epub -> На Луне (Константин Циолковский).epub

Execute these renames?: Yes

Also accept files as positional arguments

I think it would be more intuitive if I could call renamer *.txt instead of ls -l | renamer. My suggestion would be to use the positional arguments as input per default and only check stdin if there are no positional arguments. What do you think?

Error: Nonexisting input files. Aborting. @FreeBSD

Hi,

not sure it is FreeBSD related but:

% find . | sort
.
./Velvet Acid Christ 'Fun With Knives' 01. Decypher.mp3
./Velvet Acid Christ 'Fun With Knives' 02. The Dark Inside Me.mp3
./Velvet Acid Christ 'Fun With Knives' 03. There Is No God.mp3
./Velvet Acid Christ 'Fun With Knives' 04. Icon.mp3
./Velvet Acid Christ 'Fun With Knives' 05. Fun With Drugs.mp3
./Velvet Acid Christ 'Fun With Knives' 06. Speedball O.D..mp3
./Velvet Acid Christ 'Fun With Knives' 07. Psycho.mp3
./Velvet Acid Christ 'Fun With Knives' 08. Slut.mp3
./Velvet Acid Christ 'Fun With Knives' 09. Apflux.mp3
./Velvet Acid Christ 'Fun With Knives' 10. Fun With Knives.mp3
./Velvet Acid Christ 'Fun With Knives' 11. Caught.mp3
./Velvet Acid Christ 'Fun With Knives' 12. Futile 98.mp3
./Velvet Acid Christ 'Fun With Knives' 13. The Dark Inside Her.mp3
./Velvet Acid Christ 'Fun With Knives' 14. Cyber Communists Plotting Red Revolt.mp3
./Velvet Acid Christ 'Fun With Knives' 15. Over.mp3

% ls -1 | env EDITOR=geany renamer

The following input files do not exist:
Velvet Acid Christ 'Fun With Knives' 01. Decypher.mp3
Velvet Acid Christ 'Fun With Knives' 02. The Dark Inside Me.mp3
Velvet Acid Christ 'Fun With Knives' 03. There Is No God.mp3
Velvet Acid Christ 'Fun With Knives' 04. Icon.mp3
Velvet Acid Christ 'Fun With Knives' 05. Fun With Drugs.mp3
Velvet Acid Christ 'Fun With Knives' 06. Speedball O.D..mp3
Velvet Acid Christ 'Fun With Knives' 07. Psycho.mp3
Velvet Acid Christ 'Fun With Knives' 08. Slut.mp3
Velvet Acid Christ 'Fun With Knives' 09. Apflux.mp3
Velvet Acid Christ 'Fun With Knives' 10. Fun With Knives.mp3
Velvet Acid Christ 'Fun With Knives' 11. Caught.mp3
Velvet Acid Christ 'Fun With Knives' 12. Futile 98.mp3
Velvet Acid Christ 'Fun With Knives' 13. The Dark Inside Her.mp3
Velvet Acid Christ 'Fun With Knives' 14. Cyber Communists Plotting Red Revolt.mp3
Velvet Acid Christ 'Fun With Knives' 15. Over.mp3

Error: Nonexisting input files. Aborting.

Regards.

`cargo install` reports no `clap::Clap`

The first error (out of many pages, of course) is:

error[E0432]: unresolved import clap::Clap

I am a total noob, so don't want to make wrong guesses about how to fix this.

Customize the editor command

This could be to use something other than $EDITOR for the renaming. But my use case is actually to set up some custom functionality in nvim, try and get better completion and highlighting.

Either way, a CLI argument for customizing the editor command.

maybe a config file in XDG_CONFIG_HOME for customizing the editor and rename command

Inconsistent version reported by -V and cargo

renamer -V returns version 1.2. However, cargo thinks I have version 1.4.1.

$ cargo install --list
bottom v0.6.4:
    btm
cargo-update v8.0.0:
    cargo-install-update
    cargo-install-update-config
du-dust v0.7.0:
    dust
pipe-rename v1.4.1:
    renamer
$ which -a renamer
/Users/user/.cargo/bin/renamer
$ renamer -V
pipe-rename 1.2

I am using macOS 11.6.1

The program should check that the input files does exist

TSIA I think!

$ renamer i-do-not-exist

..... [open editor, make changes] .....

The following replacements were found:

i-do-not-exist -> i-do-not-exist-foo

Execute these renames? yes
Error: No such file or directory (os error 2)

Add option to rename file names only

Hello!

When giving a list of paths to rename like:

renamer ~/foo/bar ~/foo/other_bar ./a_local_bar

The whole path is given to the program, and when renaming I get a file with:

/home/my_user/foo/bar
/home/my_user/foo/other_bar
./a_local_bar

I'd like to suggest an option to only have a list of file names and not a list of full paths when renaming, so the renaming file would look like:

bar
other_bar
a_local_bar

And for the confirmation step, the filenames changes could be grouped by directories, like:

# in directory: /home/my_user/foo
bar -> new_bar
other_bar -> new_other_bar

# in current directory
a_local_bar -> new_local_bar

The only trick/potential-problem I see is when a filename is the same in 2 directories, but is it really a problem?
And #17 could help in case something's wrong


For the option name, maybe --filenames-only ? Or --same-dir/--keep-dir ?

What do you think of this?

`--rename-command` is broken for commands with arguments

E.g:

$ renamer -c 'git mv' Cargo.toml 

The following replacements were found:

Cargo.toml -> Cargo.json

Execute these renames?: Yes
Error: No such file or directory (os error 2)

Caused by:
    No such file or directory (os error 2)

I think reverting back to

subprocess::Exec::shell(format!(
    "{} {} {}",
    cmd,
    escape(Cow::from(replacement.original.clone())),
    escape(Cow::from(replacement.new.clone()))
))
.join()?;

should fix it.

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.