shenwei356/brename

Supporting undo renames

Closed this issue ยท 8 comments

  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.

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

Safety is the priority of brename.

An environment variable could be a good way.

BRENAME_DISABLE_UNDO

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:

  • include objects starting with dot (e.g. I maintain tags that way and sometimes need to rename them C:\DOCS\.tags1 secret internal public -> rename secret into confidential)
  • disable creating .brename_detail.txt, because it's a pain to delete it manually

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.

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 [^\.])

@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.

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