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