Batch Rename with ZMV

Need to rename a bunch of files to update to Composer autoloading. Migrating from underscored Namespace and Class names to PSR12 compliant Pascal Case.

Found this:

uscore="this_is_the_string_to_be_converted"
arr=(${(s:_:)uscore})
printf %s "${(C)arr}"
ThisIsTheStringToBeConverted

Found this for zsh:

$ ls -F -G
File-A-B.gif  File-C-D.gif  File-E-F.gif

$ zmv -n 'File-(*)-(*).gif' 'File-${1}${2}.gif'
mv -- File-A-B.gif File-AB.gif
mv -- File-C-D.gif File-CD.gif
mv -- File-E-F.gif File-EF.gif

In case of zsh: command not found: zmv load it with autoload -U zmv.

The -n is to test out. This is what I came up with:

zmv -n 'src/(*)/class-(*)-(*).php' 'src/${1}/${(C)2}${(C)3}.php'

And

zmv 'src/(*)/(*)_(*).php' 'src/${1}/${(C)2}${(C)3}.php'

Leave a Reply

Your email address will not be published. Required fields are marked *