To separate out words in title-case, like for FooBarBaz.mp4
to become Foo Bar Baz.mp4
, you can do insert a space before every uppercase letter except when it's the first character in the file name, which with zsh's zmv
you could do (recursively) with:
$ autoload -Uz zmv
$ zmv -n '(**/)(?)(*.mp4)' '$1$2${3//(#m)[[:upper:]]/ $MATCH}'
mv -- FooBarBaz.mp4 'Foo Bar Baz.mp4'
mv -- OnceUponATime.mp4 'Once Upon A Time.mp4'
(remove the -n
for dry-run if happy).
Beware it changes Foo-Bar.mp4
to Foo- Bar.mp4
.
zmv -n '(**/)(*.mp4)' '$1${2//(#b)([[:alpha:]])([[:upper:]])/$match[1] $match[2]}'
Would only insert spaces between a letter and an uppercase letter, but would not work for OnceUponATime
above as the space would be inserted between n
and A
, but not between A
and T
as the A
would have already be consumed by the previous substitution.
As zsh globs don't have the equivalent of perl's look around operators, working around that is more difficult. A simple approach in this case though is to just repeat the substitution an extra time:
$ zmv -n '(**/)(*.mp4)' '$1${${2//(#b)([[:alpha:]])([[:upper:]])/$match[1] $match[2]}//(#b)([[:alpha:]])([[:upper:]])/$match[1] $match[2]}'
mv -- ABCDEF.mp4 'A B C D E F.mp4'
mv -- AChristmasCarol.mp4 'A Christmas Carol.mp4'
mv -- FooBarBaz.mp4 'Foo Bar Baz.mp4'
mv -- LeSongeD\'UneNuitD\'Été.mp4 'Le Songe D'\''Une Nuit D'\'Été.mp4
mv -- LifeOfΠ.mp4 'Life Of Π.mp4'
mv -- OnceUponATime.mp4 'Once Upon A Time.mp4'
_
instead of spaces and they will still be easily readable while not being harder to handle.