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,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 3302 invoked from network); 16 Nov 2020 19:54:22 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 16 Nov 2020 19:54:22 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20200801; t=1605556462; b=m9W5Uls/Mr5wH7VjohyspWB3yw57TFDVmcfc/3RYGbjJtImHsJuwL1MxVNCnpJSMY8zzVBVqDp IT9z74GDr08m3QWq5vkU+L7TMgiL43l5lUDYtOXqctmMqfpPB1xsWQ3YY2UvXH0vjvg2yZwx+P BYtYsCIm3ftZBrFmIqmFBOcQfePhqcB2UordKQKNLKtMSAb6qV2Ps+aOo0oxPsDP7OiMhBamyD ZvrqYSBOpxv/g40yc2xgEJXLcIEVgiAU5NSr/J0pcHVmYOFb6xd7Nd5dbKJJ+AKoXW26jZal7T vhQuuLo2StxAJX0ZIppZ1o6pBeNAByhtauaFVjlWSDA9TA==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (wout5-smtp.messagingengine.com) smtp.remote-ip=64.147.123.21; dkim=pass header.d=daniel.shahaf.name header.s=fm1 header.a=rsa-sha256; dkim=pass header.d=messagingengine.com header.s=fm1 header.a=rsa-sha256; dmarc=none header.from=daniel.shahaf.name; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20200801; t=1605556462; bh=GUYV6wAektaOLD+ZCbYYGgQyBXcB1Ar2CXnX84al/+A=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Transfer-Encoding:Content-Type:MIME-Version: References:In-Reply-To:Message-ID:Subject:Cc:To:From:Date:DKIM-Signature: DKIM-Signature:DKIM-Signature; b=Ptfj5iRxUZu836YtBzX4BMvQV/mgETBWvePgllxXxYq+ytHaM4ghfSBWYgeRHS11H60dX3RfKW q2ivjqGmlOBi9jOeQT5LJJlSPh1Gs/C6gsF922+csfRsfYH65w+14KQwoK77I9nw7mS0vAgSh8 ODqMgRJlpqSuVl7g3/vKy2fKHHjROZ4x3aztOw9u3DI5beIaSiYnMJUZwAncaqp0pr7uLwn7uI zXCavw3cb7czw20kmuM6MDg1M0w71F6Kf7XV7ZeVFCEhl4HEakLDMxzZBFTasKWoKSlae1NpF+ 1mFjHEidbsXdZYSBhk7kEQXBBoxnh9CKAspn7zmHDUx49A==; 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-Transfer-Encoding: Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Subject:Cc:To: From:Date:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=kCriY40AGcZanMdSmshAnMQVHlUqx7oWeRj3Wp0o09A=; b=q7WduaXUZbyPnSQDb07fG0OnVk xOp5c9kyyo0wfRa2051VsD2rSCVxgRn3Jvl4B0+fjhfZFq39j5xcBJMyciEA/QeZhVmoMZ5UzHMIf UIPEuSoX8Iug6T2LqpcK2gM1BwnpzcCWd+TRBGsH+v8hxK/Fyq22jU7Gnij0W9fuWw8w+M5vqbMOD nMpjAZvQzq7+AZOqOS7rmPsuTxkDFixd1S12+VHdbP8oYvsWqdymZjh/A/KbOucQijvTqK8m3tYQn pxoaoKXR+NVAJ0aACdDYuRD9feXG5XLFx2rXtZKqukiw5kyCACqX6FA1AYBes243fn0GQh0y3N/G1 aNJJtKIg==; Received: from authenticated user by zero.zsh.org with local id 1kekZy-000FJv-7W; Mon, 16 Nov 2020 19:54:22 +0000 Authentication-Results: zsh.org; iprev=pass (wout5-smtp.messagingengine.com) smtp.remote-ip=64.147.123.21; dkim=pass header.d=daniel.shahaf.name header.s=fm1 header.a=rsa-sha256; dkim=pass header.d=messagingengine.com header.s=fm1 header.a=rsa-sha256; dmarc=none header.from=daniel.shahaf.name; arc=none Received: from wout5-smtp.messagingengine.com ([64.147.123.21]:41551) by zero.zsh.org with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) id 1kekZZ-000ExD-Nf; Mon, 16 Nov 2020 19:53:59 +0000 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.west.internal (Postfix) with ESMTP id BCDF518A; Mon, 16 Nov 2020 14:53:55 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Mon, 16 Nov 2020 14:53:55 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= daniel.shahaf.name; h=date:from:to:cc:subject:message-id :in-reply-to:references:mime-version:content-type :content-transfer-encoding; s=fm1; bh=kCriY40AGcZanMdSmshAnMQVHl Uqx7oWeRj3Wp0o09A=; b=TAPZUkCP4F+MVTJGAO2m0xKDZe6jUwk0Wfzu8yLcmB 4df4aPM6Xxh12wSHEy1fP70GtugKTzGTliw8o484eEAX845mIoyVr1XKRG5LWPAW egJc5G68Xcs7dj9CS9rmanDHvV++r374OFEkezYh58fdI2v6qNctEnZeHkYTN6C+ ANgpWn413q/fOB6vdBCddJbDBEVpXdc0tnN6I2wA66f567s+rcO7sDxgHbC+On5G HlS6RXNUMyNk4f5pIoxH0jpidV71m3g8WAM+LFJCoUVWUcuo6XgzixfRqrDHIQ8W jsKnNygawANPXqerKbBbTvN8yFfGvtiRLaPgjxr78dMA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; bh=kCriY40AGcZanMdSmshAnMQVHlUqx7oWeRj3Wp0o0 9A=; b=mbT/ACVEHB1ImItN/n9auX2S6vggOQvY0YMEFtec3eCGsJehtMryIQLKx qztkcDtCLDuyVpGr1W6gvmZ6NJIUOsowUJsNm6O9JS2tYG2GS0/1kwvW3JdVng+Z Xk1LPzKi/2bXnKEVy0ryg/d/cqk2ZtM6c9FwjIKjpzxbyx+mJnh6N1UZmpu5LQYh JP3RZY9/aM3R7zmis0OpJHcOUoFbHjNN5IfuJIgauSO2t+ZfpCEmo2CqL/J5gwb1 K4nMy1+LJTNNzmWkHV9EgSCNYCvqONsWb6qBCVqXB6ojSjYPm//s7TeaympW2Gy2 yuX3GwkGC/K6KRrtMb12kpiMNR06w== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrudefuddgudefudcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvuffkjghfofggtgfgsehtqhdttdertdejnecuhfhrohhmpeffrghn ihgvlhcuufhhrghhrghfuceougdrshesuggrnhhivghlrdhshhgrhhgrfhdrnhgrmhgvqe enucggtffrrghtthgvrhhnpefhtdetfeehveeutdehuddtieefgeettedtjedtffehudei ieejleetteekudetheenucfkphepjeelrddukedtrdeikedrudefheenucevlhhushhtvg hrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegurdhssegurghnihgvlhdr shhhrghhrghfrdhnrghmvg X-ME-Proxy: Received: from tarpaulin.shahaf.local2 (bzq-79-180-68-135.red.bezeqint.net [79.180.68.135]) by mail.messagingengine.com (Postfix) with ESMTPA id E4EF53064AB3; Mon, 16 Nov 2020 14:53:54 -0500 (EST) Received: from tarpaulin.shahaf.local2 (localhost [IPv6:::1]) by tarpaulin.shahaf.local2 (Postfix) with ESMTP id 4CZfsD6ggMz1vM; Mon, 16 Nov 2020 19:53:52 +0000 (UTC) Date: Mon, 16 Nov 2020 19:53:51 +0000 From: Daniel Shahaf To: Ahmad Ismail Cc: Zsh Users Subject: Re: zmv pattern for directory and multiple file types Message-ID: <20201116195351.679cbaa1@tarpaulin.shahaf.local2> In-Reply-To: References: X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Seq: 26174 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: Ahmad Ismail wrote on Sat, 14 Nov 2020 03:45 +0600: > Hi All, >=20 > I have the following functions that rename files from camel to sort of > kebab case. >=20 > 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' >=20 > # Put - Between [Small][Capital] > zmv -Q '(**/)(*[a-z][A-Z]*)(.adoc|.txt)' '$1${2//(#b)([a-z])([A-Z])/$= match[1]-$match[2]}$3' >=20 > # Change [Capital][Small] to Lovercase > zmv -Q '(**/)(*[A-Z][a-z]*)(.adoc|.txt)' '$1${2//(#m)[A-Z][a-z]/${(L)= MATCH}}$3' > } =20 >=20 > So, IF the input name is "ThisIsMyOCDTalking", it becomes > "this-is-my-OCD-talking". >=20 > Now I want to rename directories, adoc & txt files only. For directories,= I > think I have to use >=20 > zmv -Q '(**/)(*[A-Z][A-Z][a-z]*)(/)' >=20 > How to make a function that will work on adoc, txt and directories. I tri= ed > (/|.adoc|.txt), apparently not working. >=20 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. 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=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 "-", 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) %=20 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 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 children before their parents. Cheers, Daniel