shenwei356 / brename

A practical cross-platform command-line tool for safely batch renaming files/directories via regular expression
https://github.com/shenwei356/brename
MIT License
262 stars 22 forks source link

Supporting undo renames #8

Closed shenwei356 closed 1 year ago

shenwei356 commented 6 years ago
  1. Saving renaming details of the LAST successful operation into current path, like .brename_detail.txt.
    1. We may not use \t as the delimiter cause it's legal in path name, _shenwei356-brename_ may better.
  2. Running brename -u to read the file and reverse the renaming.
    1. Warning if the log file not existed.
    2. Reading and reversely renaming.
    3. Removing the log file.
mo-han commented 3 years ago

Please add an option to disable undo, otherwise I need to do an extra step to delete the .brename_detail.txt file

shenwei356 commented 3 years ago

Safety is the priority of brename.

An environment variable could be a good way.

BRENAME_DISABLE_UNDO
sergeevabc commented 1 year ago

Dear @shenwei356, creating environment variables is not a portable way to do things. Also a constant fear of doing something wrong is a major obstacle to grow — it shifts responsibility from humans to computers, reinforces personal helplessness and, above all, deprives growing (grown) users of completing advanced tasks.

So please consider adding a couple of switches to mitigate long-irritating features:

shenwei356 commented 1 year ago

Here's my plan:

disable creating .brename_detail.txt

  1. add a new flag to recursively remove all .brename_detail.txt files in the current or given directory.
  2. add a new flag to disable creating creating .brename_detail.txt files.

include objects starting with dot

  1. add a new option (default value: ^\. for skipping file starting with a dot) to set an excluding filter, similar to -F, --exclude-filters. Adding an extra filter is for backward compatibility.
shenwei356 commented 1 year ago

Implemented. Please have a try.

Added examples:

  11. disable undo if you do not want to create .brename_detail.txt (-x)
      brename -p xxx -r yyy -x
  12. clear/remove all .brename_detail.txt files (--clear)
      brename --clear -R
  13. also operate on hidden files: empty -S (default: ^\.)
      brename -p xxx -r yyy -S ""

New options

      --clear                     remove all .brename_detail.txt" file,  you may need to add
                                  -R/--recursive to recursively clear all files in the given path
  -x, --disable-undo              do not create .brename_detail.txt file for undo
  -S, --skip-filters strings      skip file filter(s) (regular expression, NOT wildcard). multiple
                                  values supported, e.g., -S "^\." for skipping files starting with a
                                  dot, but ATTENTION: each comma in the filter is treated as the
                                  separator of multiple filters, please use double quotation marks for
                                  patterns containing comma, e.g., -p '"A{2,}" (default [^\.])
sergeevabc commented 1 year ago

@shenwei356, I'm relieved to hear that you agreed to implement the requested features for advanced users so quickly. It did feel as though a weight had been lifted off my mind. Happily renaming folders throughout today.

shenwei356 commented 1 year ago

Cheers! If no error or bug is found, I'll release the new version the next day.

shenwei356 commented 1 year ago

It's available here: https://github.com/shenwei356/brename/releases/tag/v2.12.0