From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,HTML_MESSAGE,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,T_KAM_HTML_FONT_INVALID,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 24685 invoked from network); 16 Nov 2020 23:09:07 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 16 Nov 2020 23:09:07 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20200801; t=1605568147; b=XwF/T59JbBgrupkbDKKIfuL4nzKlukkOWNHGEMotasfUyH98I2t2I0eXWN4IRookNWHUyezW4J heBoNYIqq/81rqofliPYc7rfSYaCzQonUfrAZ+jIpfVu7nleizQTKkxXE9koxy67f9riRRtxpb eHpJoVMsAQCvmXef+iwTk7irDXRBhr0mnhomuDTcEn+IaMzJgDIj0T3tHl0kwuFfwyu3l0IQKX VkFRcSG2+aqw+jLO7kl/dSOWYBUIZoYiRRDgXXZbbL0pg7caKgl+Wm0FkNAPIuo1oq8tvYK7qp uUTS4fHd706+zWO/7u1B57M0W6qFRlOpU7Mt1sRY88ypfw==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-oi1-f182.google.com) smtp.remote-ip=209.85.167.182; dkim=pass header.d=gmail.com header.s=20161025 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20200801; t=1605568147; bh=sLy6bqbvapOGnO5kuq55mY9xAO20OxTR8uNdMJf4sSk=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:Cc:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:DKIM-Signature:DKIM-Signature; b=Q0U76XtPAh/y/xjQf3/z+s5160GKxBkK4bu//ap0+XU1W8SJ7PZa4GsY1a6p9EYWiy3GPsYVIh I1P+bZCt/uVc4ZI17ju7V3mHFjra0IUbQYgks8WCJQeq08RoN0OkyF/54524RHd+aHY90yN31C moEE3CnMsr6+HivflV+d+DVCH303gX1q3a7lz2zVo3CkinPt71SBac8VkLqRckS1hC70ZSwZjO AQPsD0ReFKe+ldg+lMuwrQjvy+HvsAPZXSaDwqnSYGbBtr1Schfu5dxDbTsGn9uVcrX4rtr/B7 oeYZs4NBv5UZZocq30wxYqJOdUXYIfnwN3hNXoucD/ELuw==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20200801; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Type:Cc:To:Subject:Message-ID :Date:From:In-Reply-To:References:MIME-Version:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=VTwvBd+LeCFLvhaY7OfZnAXzNYzPDETcd2dDQPFxdEM=; b=SA/B9KJo1WuW5cXkUVxsNVBrEE ibrV9IAUHPM7MWTNU/97m94qsjjls+1XJ2HylpTm+SN7UQe/UJlx8jvgQMu4/OhlvGo5NyzEwGucK /FFVre6LNsiGlV3NbyQ1RQPxxDbw0w9aFNlC7KTtwkwp4B6Xq12a6iOQR/dJ8Sw7N7y95tBIB7jXg yUPaFigpWUMgohZYQSk4fVI+Xmz/w8/EuPhAear+7Kqi3sPWwx0iC1xqmvX8QqYG9W5l4cQCDhDMJ QfpEIl23bC4l3KNQUKZ95SeXcesosxfEqpvykj5MRt6whoa+L0pUElEK4moRY4ok36YLl1ZwZxdvE N0xa6j9A==; Received: from authenticated user by zero.zsh.org with local id 1kencN-000MTD-9L; Mon, 16 Nov 2020 23:09:03 +0000 Authentication-Results: zsh.org; iprev=pass (mail-oi1-f182.google.com) smtp.remote-ip=209.85.167.182; dkim=pass header.d=gmail.com header.s=20161025 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none Received: from mail-oi1-f182.google.com ([209.85.167.182]:43492) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1kenbs-000M6t-JF; Mon, 16 Nov 2020 23:08:33 +0000 Received: by mail-oi1-f182.google.com with SMTP id t143so20567454oif.10 for ; Mon, 16 Nov 2020 15:08:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=VTwvBd+LeCFLvhaY7OfZnAXzNYzPDETcd2dDQPFxdEM=; b=ezLZtzmZRrJ9XzlXxStZ714hNbk+fTwecrWhSS0Uuj2+w3iSHAonHc1mGhHRTx0+BG rkHmUVk3worGFHOB9bv4MrM07sa1xo4CpBfd/Xq+Bj1JG4MeSFhM1DpbP9sBx8nrKJeE HC0AYCPfpXl/dxyp1U4ALhV9BUOzWb5jJ5s3ebhHP/uUQdPHcXyYLfAvZQThKaG5ooE6 MepMu1/pPkpRJqPauR8Ry8qVBcVrREWCtGxUYCVRyrhHijuXvQ2KhERdOqzfzbsqVqtX ffndr9an9ISPwFX0pg92+y7mLFEFYGwuq3/ktSTKfbkGn8nKQBDpDxoAHkZtKJ75x5Mu O98A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=VTwvBd+LeCFLvhaY7OfZnAXzNYzPDETcd2dDQPFxdEM=; b=Zoc9TpN13yJU0jSFwRPgA4w45uXv84HlgDdH23UTaQtKYS5zEyLb6sof1bfgh6Z2UH qu22mttabKEF5mrs7qj9oYotVlCd3lZ02zBf/9J6lZJeWO6c4e8tHiQoPJv20PNbDYya KBb31+B6INnoV0baa2x1fD5SBxFkvHtoP+JwT1sR7/sNKnllnFtjmapvyJTmvl5cXa+8 zv+z17/dxN0p23MSEpUpM70dxQbEl8CLhVdTaeQprkm0RNlr0QAcPEt25S8h4nl6Uds5 rXdDRm5ZArTlLlJS65X3IdOYrZ+pfsT0V0f6hZsa23Up2YfT/2KFgLE/X3EFEckl454U Uuzw== X-Gm-Message-State: AOAM533WBnQ/ayrJVZo4hPCD3NxbH7KE0u9/R+apocg3wKlLDutaHAnj 9YXe+u10kd5Ex9WZm42I6T4OdBKgkUDwW+YC0xlOqdpL3gA= X-Google-Smtp-Source: ABdhPJzf8aVDlfED8CGVhtO6A6MoNrGkWGVtde/dcFFaMqNHe2KtPWJAmftEFRNIus5ffRDk4i8wk0YtKZcSZ2TpNLs= X-Received: by 2002:a05:6808:494:: with SMTP id z20mr664507oid.10.1605568111247; Mon, 16 Nov 2020 15:08:31 -0800 (PST) MIME-Version: 1.0 References: <20201116195351.679cbaa1@tarpaulin.shahaf.local2> In-Reply-To: <20201116195351.679cbaa1@tarpaulin.shahaf.local2> From: Ahmad Ismail Date: Tue, 17 Nov 2020 05:08:20 +0600 Message-ID: Subject: Re: zmv pattern for directory and multiple file types To: Daniel Shahaf Cc: Zsh Users Content-Type: multipart/alternative; boundary="000000000000ef04db05b44174f2" X-Seq: 26176 Archived-At: X-Loop: zsh-users@zsh.org Errors-To: zsh-users-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-users-request@zsh.org X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: Archived-At: --000000000000ef04db05b44174f2 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Daniel Shahaf, Thank you very much. *Thanks and Best Regards,Ahmad Ismail* On Tue, Nov 17, 2020 at 1:53 AM Daniel Shahaf wrote: > Ahmad Ismail wrote on Sat, 14 Nov 2020 03:45 +0600: > > 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. > > > > Consider how in =C2=AB*foo*(bar)=C2=BB, the =C2=ABfoo=C2=BB are matched a= gainst the > filename but the =C2=ABbar=C2=BB are parsed as glob qualifiers. You can'= t just > juxtapose them within the same set of parentheses; they're apples and > oranges. > > I don't see a good solution for "Everything in =C2=AB**/*=C2=BB that's > a directory or named *.foo or *.bar". I'd consider find(1) for this. > > > One more thing, is there any way I can reduce the steps in this > functions. > > As a rule, I wouldn't recommend reducing steps in functions in the > first place, unless you're coding for sport rather than robustness =E2=80= =94 in > which case, I'd probably opt for Perl: > > % print -rNC1 -- *.(adoc|txt)(N) *(/N) | rename -0 -n '$_ =3D join "-", m= ap > { /[a-z]/ ? lc : $_ } split /(?<=3D[a-z])(?=3D[A-Z])|(?=3D[A-Z][a-z])/' > rename(ThisIsMyOCDTalking.adoc, this-is-my-OCD-talking.adoc) > % > > The main algorithmic difference is splitting the filename into an array > on zero-width lookaround matches. I don't think there's a native zsh > equivalent of this. > > Note that changing =C2=ABprint -rNC1=C2=BB to =C2=ABls=C2=BB would introd= uce two separate bugs. > > I'm not sure how to extend this to nested hierarchies, given the > possibility of foo/bar where both foo and bar have to be changed. > Perhaps with =C2=ABrename -d=C2=BB and ensuring the input is sorted child= ren > before their parents. > > Cheers, > > Daniel > --000000000000ef04db05b44174f2 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi Daniel Shahaf,

Thank you = very much.

Thanks and Best Regards,

Ahmad Ismail



On Tue, Nov 17, 2020 at 1:53 AM Daniel Shahaf <d.s@daniel.shahaf.name> wrote:
Ahmad Ismail wrot= e on Sat, 14 Nov 2020 03:45 +0600:
> Hi All,
>
> I have the following functions that rename files from camel to sort of=
> kebab case.
>
> function ctokfiles() {
>=C2=A0 =C2=A0 =C2=A0# Transform [Capital][Capital][Small] to [Capital]-= [Capital][Small]
>=C2=A0 =C2=A0 =C2=A0zmv -Q '(**/)(*[A-Z][A-Z][a-z]*)(.adoc|.txt)= 9; '$1${2//(#b)([A-Z])([A-Z][a-z])/$match[1]-$match[2]}$3'
>
>=C2=A0 =C2=A0 =C2=A0# Put - Between [Small][Capital]
>=C2=A0 =C2=A0 =C2=A0zmv -Q '(**/)(*[a-z][A-Z]*)(.adoc|.txt)' &#= 39;$1${2//(#b)([a-z])([A-Z])/$match[1]-$match[2]}$3'
>
>=C2=A0 =C2=A0 =C2=A0# Change [Capital][Small] to Lovercase
>=C2=A0 =C2=A0 =C2=A0zmv -Q '(**/)(*[A-Z][a-z]*)(.adoc|.txt)' &#= 39;$1${2//(#m)[A-Z][a-z]/${(L)MATCH}}$3'
> }=C2=A0
>
> 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 direc= tories, I
> think I have to use
>
>=C2=A0 =C2=A0 =C2=A0zmv -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.
>

Consider how in =C2=AB*foo*(bar)=C2=BB, the =C2=ABfoo=C2=BB are matched aga= inst the
filename but the =C2=ABbar=C2=BB are parsed as glob qualifiers.=C2=A0 You c= an't just
juxtapose them within the same set of parentheses; they're apples and oranges.

I don't see a good solution for "Everything in =C2=AB**/*=C2=BB th= at's
a directory or named *.foo or *.bar".=C2=A0 I'd consider find(1) f= or this.

> One more thing, is there any way I can reduce the steps in this functi= ons.

As a rule, I wouldn't recommend reducing steps in functions in the
first place, unless you're coding for sport rather than robustness=C2= =A0=E2=80=94 in
which case, I'd probably opt for Perl:

% print -rNC1 -- *.(adoc|txt)(N) *(/N) | rename -0 -n '$_ =3D join &quo= t;-", map { /[a-z]/ ? lc : $_ } split /(?<=3D[a-z])(?=3D[A-Z])|(?= =3D[A-Z][a-z])/'
rename(ThisIsMyOCDTalking.adoc, this-is-my-OCD-talking.adoc)
%

The main algorithmic difference is splitting the filename into an array
on zero-width lookaround matches.=C2=A0 I don't think there's a nat= ive zsh
equivalent of this.

Note that changing =C2=ABprint -rNC1=C2=BB to =C2=ABls=C2=BB would introduc= e two separate bugs.

I'm not sure how to extend this to nested hierarchies, given the
possibility of foo/bar where both foo and bar have to be changed.
Perhaps with =C2=ABrename -d=C2=BB and ensuring the input is sorted childre= n
before their parents.

Cheers,

Daniel
--000000000000ef04db05b44174f2--