zsh-users
 help / color / mirror / code / Atom feed
From: Ahmad Ismail <ismail783@gmail.com>
To: Zsh Users <zsh-users@zsh.org>
Subject: zmv pattern for directory and multiple file types
Date: Sat, 14 Nov 2020 03:45:41 +0600	[thread overview]
Message-ID: <CAHAhJwJVTmCY0ALRDDzcEYCG8Voojp8ZBT2DK8Sb50F-RFAWpg@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 1015 bytes --]

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*

[-- Attachment #2: Type: text/html, Size: 2105 bytes --]

             reply	other threads:[~2020-11-13 21:46 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-13 21:45 Ahmad Ismail [this message]
2020-11-16 19:53 ` Daniel Shahaf
2020-11-16 23:08   ` Ahmad Ismail

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAHAhJwJVTmCY0ALRDDzcEYCG8Voojp8ZBT2DK8Sb50F-RFAWpg@mail.gmail.com \
    --to=ismail783@gmail.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).