Skip to content

Panoplos/fish-regex-rename-files

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 

Repository files navigation

fish-regex-rename-files

Sharing a few fish functions that I have found useful when having to deal with batch name changes on a lot of files in the awesome Fish Shell.

renr renames all the files and directories in the optionally provided dir (default: CWD) according to the provided sed -E acceptable regex replace pattern.

recr recurses through all subdirectories in the optionally provided dir (default: CWD) and renames only files according to the provided sed -E compatible regex replace pattern.

Installation

Download the .fish files and save into your /Users/yourname/.config/fish/functions directory. Fish will automatically read them into all sessions, so they will be usable immediately.

If you would like to enhance the scripts in your own repo, I recommend cloning this repo locally and soft-linking them into the above functions directory.

Usage

⟩ renr [dir] "regex"

where dir is optional and regex is in the form "s/old/new/g" -- note that the regex must be in quites to avoid Fish interpretation. Example:

⟩ renr subdir "s/^([0-9]+\./\1/g"

This will rename all files and directories in the dir subdir that start with the format N*. to N*, where N* is any count of whole numbers, so 01. Fly Me to the Moon.mp3 will be renamed 01 Fly Me to the Moon.mp3.

⟩ recr [dir] "regex"

where dir is optional and regex is in the form "s/old/new/g". As above, make sure to enclose the regex in quotes. Example:

⟩ recr "s/\.js\$/\.jsx/g"

where this time we have omitted the directory (so it defaults to the CWD) and it changes all files in the current and sub directories that end with .js to the .jsx extension. It is important to note that $ within the regex must be escaped with a \ to avoid Fish interpretation.

Important!!

As it is easy to make mistakes when playing with sed's regex, it is strongly recommended that you create a backup of all the files you wish to rename before attempting to use these tools.

About

Fish shell functions to regex rename all objects in directory or recurse and rename files only.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages