felix icon indicating copy to clipboard operation
felix copied to clipboard

Support for bulk rename

Open aminnairi opened this issue 8 months ago • 1 comments

It would be awesome to support bulk renaming files in the context of renaming a huge set of file without having to rename those one-by-one.

For now, if we need to rename, let's say 10 files, we need to hit the keybind 10 times. It can be quite cumbersome for a lot of file rename.

Also, it would be great to use our favorite text editor (like Neovim for instance) in order to have a preview of all the files to rename (that have been marked for bulk rename) and make changes quickly. This can leverage Neovim & Vim's macro feature to speed up the process for complex file rename as well as for quick file rename. Emacs can also benefit from this since it implements macros as well.

Any editor would do just fine and it would be great to be able to setup the bulk rename program for that.

# ~/.config/felix/config.yml
rename:
  bulk:
    program: nvim #default to the "default" key if specified, or $EDITOR otherwise

The bulk renaming can be done using a temporary file, and then converting every old marked files to the new ones (this could use a vector for the old files and a vector for the new files). If the new vector does not contain the same amount of elements (i.e lines), the operation should be aborted in order to keep consistency within the filesystem.

As for the documentation and the default keybinds, there is room for that in visual mode.

V (uppercase)      :Switch to the linewise visual mode.
  - y              ...
  - d              ...
  - c              :In the visual mode, bulk rename selected item(s) inside your default editor. 
  - "ay            ...
  - "ad            ...
  - "Ay            ...
  - "Ad            ...

One thing to consider is the undo for this operation. I suggest keeping track of the files that have been renamed in a hash map and allowing the user to revert the bulk renaming by re-applying the changes to those files in the said hash map.

Do you think that this could be done for Felix?

Thank you for your hard work on Felix!

aminnairi avatar Jan 02 '24 10:01 aminnairi

This would make more sense and be more powerful if we have a select file option. So, we could select multiple files that we want to rename (say with ), and then press c to rename the files with a temp file.

Pressing c would open the temp file with a list of the filenames in vim like:

file2
file4
file7

To rename, you would simply change each filename to its new filename:

file2_new
file4_new
file7_new

I believe there is a select file feature issue opened here: https://github.com/kyoheiu/felix/issues/263.

RioNight avatar Jan 05 '24 05:01 RioNight