marcusbuffett / pipe-rename

Rename your files using your favorite text editor
https://crates.io/crates/pipe-rename
MIT License
397 stars 12 forks source link

Allow the user to edit the replacements, even if the current replacements are not possible #37

Closed frsche closed 3 years ago

frsche commented 3 years ago

Hello!

Currently, the program aborts when there will be a collision with the renamed files. I think it is more convenient to allow the user to fix the current renaming, instead of expecting him to do all the renaming again.

This pull request hides the "Yes" answer when there is a collision with the filenames. This allows the user to select the "Edit" or "Reset" option to fix the collision. When the --yes option is given, the program aborts when there is a collision (so that it is never interactive with --yes).

I have also changed the color in which the collisions are shown to red so that it is more obvious that something went wrong.

bew commented 3 years ago

I think the prompt shouldn't have that much logic, also the is_successful parameters name is confusing in my opinion. What about this alternative: move the possible_selection vec outside of the prompt function, and simply give it as a parameter? This way:

  1. The possibles selections stays at the same place where we check the results, I think it's better for locality.
  2. The prompt function stays simple, no specific logic based on obscure unknown condition (from the point of view of the function).
  3. Since you know beforehand the various conditions you can request prompt only with the relevant selection!
  4. The prompt function uses the first possibility as the default, maybe for the case of confocts, the default should be Edit, not No?

Other things I'm thinking:

marcusbuffett commented 3 years ago

Makes a lot of sense to me, agree just aborting is wrong. I do think eliminating the "Yes" option when there are conflicts is a bit overkill, I can imagine use cases where you'd be fine with overwriting existing files. I'm going to merge this then just add the "Yes" option back in, but not as the first option, so people don't just mindlessly hit enter and lose files. Thank you for the contribution!

marcusbuffett commented 3 years ago

Published a new version w/ this :+1: 1.4.0 has this update