Skip to content

A program that makes renaming files on the CLI easier, deferring the main work to renaming rules and profiles or alternatively the system's default text editor or an interactive TUI editor.

License

Notifications You must be signed in to change notification settings

kraasch/renamer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

renamer

demo

features

Rename files with renaming rule string (search files)

renamer -i recursive -s all -o apply -c rule -r " ()||-|_|cAa|"

Rename files with renaming rule string (from pipe)

find | renamer -i pipe -o apply -c rule -r " ()||-|_|cAa|"

Edit files with your editor (for example vim or emacs)

renamer -i recursive -s all -o apply -c editor

Different ways to use renamer:

  • input:
    • dir: list directory (like ls)
    • recursive: search directory tree (like find)
    • pipe: pipe in the input.
  • input:
    • rule: provide a rule string.
    • editor: edit the input yourself.
    • config+profile: provide a configuration file with renaming profiles.
    • interactive: apply rules and profiles with a TUI application.
  • output:
    • apply: rename according to given pattern.
    • print: print what would be done, if apply option was given.
    • validate: print if file system conforms to given rules (i.e. no renaming needed.)

The profile and the rule format are equally powerful, i.e. can be converted into each other. For now see the rename package to see features of rules and profiles.

Example configuration file format:

# An Example Config
title = "Some Example"

[profiles]
[profiles.toast-txt]
    name            = "n0"
    [profiles.toast-txt.profile_rule]
    word_separators = " ()"
    delete_chars    = ""
    small_gap_mark  = "-"
    big_gap_mark    = "_"
    conversions     = "caA"
    modes_string    = ""
[profiles.prettify-txt]
    name            = "n1"
    [profiles.prettify-txt.profile_rule]
    word_separators = " ()"
    delete_chars    = ""
    small_gap_mark  = "-"
    big_gap_mark    = "_"
    conversions     = "cAa"
    modes_string    = ""

tip

Set an alias for your common renames in your ~/.bashrc.

alias rn_mp3='renamer -i recursive -s all -o apply -c rule -r " ()||-|_|cAa|"'
alias rn_txt='renamer -i recursive -s all -o apply -c rule -r " ()||-|_|caA|"'
alias rename='renamer -i dir       -s all -o apply -c editor'

This is an alternative to setting up a config file with profiles.

overview

The CLI program is cmd/renamer.go and compiles to renamer. The main package is rnmanage. In the below tree, the pkg tree is loosely representing the packages' dependencies.

.
├── cmd
│   └── renamer.go // CLI program
└── pkg
    └── rnmanage          // orchestrate renaming (editing, automatic) and file system. 
        ├── edit          // calls editor.
        ├── fsmanage      // deals with file system.
        │   ├── dir       // lists directories.
        │   └── testutil  // creates mock file system.
        └── autorn        // orchestrates renaming.
            ├── profiler  // save renaming rules into profiles.
            └── rename    // renames strings.

tasks

  • renaming: main functionality.
    • implement interactive renaming.
      • for each file choose method: edit, profile or apply some scripts.
  • renaming: features.
    • automatically prefix, infix, suffix before file ending:
      • individual files.
        • add the current date.
          • yyyy-mm-dd.
          • yyyy-mm-dd_HH-MM.
          • precise nano-second-timestamp.
        • add the file creation date.
          • yyyy-mm-dd.
          • yyyy-mm-dd_HH-MM.
          • precise nano-second-timestamp.
        • add a random id (decimal, hexadecimal, alphanumerical)
    • groups of files.
      • add incrementing id to list of files, also with prefixed zeroes.
    • rename scanned pages.
      • rename in different order (afbecd to abcdef) for scanned pages (first front side, then backsides in reverse).
      • example sorting for 6 PNG files: ABCDEF
      • split the files in first and second half: --> ABC and DEF
      • reverse order of second half: --> ABC and FED
      • alternatingly merge the two halfs back together: --> AFBECD.
  • renaming: pitfalls.
    • test various types circular renames: eg (a->b,b->a) should not delete anything, but should execute.
    • test over-naming renames: (a->c,c->c), should not delete anything, should not execute.
    • test colliding renames: (a->c,b->c) should not delete anything, should not execute.
  • misc.
    • also pull out testutil package.

Maybe:

  • Allow separator for rule strings renamer -rule " ();;-;_;caA;" -separator=";" ... for a different separator than a pipe.

Done:

  • misc.
  • input: main functionality.
    • get file list from pipe, ie allow these inputs:
      • ls | grep -E 'mp3$' | renamer -edit
      • find | grep -E '.ogg$' | renamer -profile music_ogg
    • if nothing is piped in, have two search modes: recusvie and dir
      • renamer -i dir -s all ... list all in pwd (default).
      • renamer -i dir -s files ... list all files in pwd.
      • renamer -i dir -s dirs ... list all directories in pwd.
      • renamer -i recursive -s all ... as above, but recursive (default)
      • renamer -i recursive -s files ... as above, but recursive.
      • renamer -i recursive -s dirs ... as above, but recursive.
      • renamer -i recursive -s dirs ... as above, but recursive.
    • allow a way to rename by providing a rule string on CLI.
      • ie renamer -rule " ()||-|_|caA| ..."
  • output: main functionality.
    • allow a -action flag to specify how to apply a name change (profile/editor)
      • have a -action=validate flag which in conjunction with -profile checks if any file breaks the profile, but doesn't apply the profile.
      • default to -action=apply flag which applies the renaming rules specified in profile.
  • renaming: main functionality.
    • implement renaming profiles.
      • run renamer -profile media to rename media files with specified conversion (named media, for renaming music, video, etc).
      • default to renamer -profile default if no profile is specified.
    • implement pure editor version (use native editor, eg vi, emacs)
      • run renamer -edit to rename with editor.

word of caution

This is work in progress. This program is

  • powerful: interprets little input to do big things,
  • risky: might delete by renaming,
  • not tested enough yet.

notes

About

A program that makes renaming files on the CLI easier, deferring the main work to renaming rules and profiles or alternatively the system's default text editor or an interactive TUI editor.

Resources

License

Stars

Watchers

Forks

Packages

No packages published