Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

zmv pattern for directory and multiple file types



Hi All,

I have the following functions that rename files from camel to sort of kebab case.
function ctokfiles() {
    # Transform [Capital][Capital][Small] to [Capital]-[Capital][Small]
    zmv -Q '(**/)(*[A-Z][A-Z][a-z]*)(.adoc|.txt)' '$1${2//(#b)([A-Z])([A-Z][a-z])/$match[1]-$match[2]}$3'

    # Put - Between [Small][Capital]
    zmv -Q '(**/)(*[a-z][A-Z]*)(.adoc|.txt)' '$1${2//(#b)([a-z])([A-Z])/$match[1]-$match[2]}$3'

    # Change [Capital][Small] to Lovercase
    zmv -Q '(**/)(*[A-Z][a-z]*)(.adoc|.txt)' '$1${2//(#m)[A-Z][a-z]/${(L)MATCH}}$3'
}
So, IF the input name is "ThisIsMyOCDTalking", it becomes "this-is-my-OCD-talking".

Now I want to rename directories, adoc & txt files only. For directories, I think I have to use

    zmv -Q '(**/)(*[A-Z][A-Z][a-z]*)(/)'

How to make a function that will work on adoc, txt and directories. I tried (/|.adoc|.txt), apparently not working.

One more thing, is there any way I can reduce the steps in this functions.

Thanks and Best Regards,

Ahmad Ismail



Messages sorted by: Reverse Date, Date, Thread, Author