Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: translate all sequences of whitespace/underscores to single dashes
- X-seq: zsh-users 20425
- From: Stephane Chazelas <stephane.chazelas@xxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Re: translate all sequences of whitespace/underscores to single dashes
- Date: Mon, 17 Aug 2015 13:19:39 +0100
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:subject:message-id:mail-followup-to:references :mime-version:content-type:content-disposition:in-reply-to :user-agent; bh=P2U7VWFnm+n/1m0JpIFTYkyFxq0EdZlVW4LJXXlnndw=; b=C7WZ07KPdYM8KIqyNEbbahCBFWYXo4sXlWj0IFHrM7AEo8jdS26HJGNcPx07XB063Q L7vqvOPHKClzpupycLdY7TPSzR/v6R/pkNmZoaEBzuh7yJKOEvb6NekP32ioVA7s3wk2 5VPABtQMdhDMQVke9kppY2eSnu29WqX2NsIi7pAcw4x+yGpAlgPeVhvBv0FwxtRn6s/v kwG90bnb5ICsTANaOf/cQY5gW6wkkZBkyTN2sgyYCd/ZtjDyfbeo0YcUaHX6GTwRAPZU f0lU/y3Sakzb6rN3gs+ev8pj6PAyGguL8hkU0bUdfXitnFJ9IEEyOBRTSAIWFLCDXXk8 L2bw==
- In-reply-to: <9D99B267-5DDD-4C5B-A33A-C5A0251A4B9F__19706.0165032328$1439813299$gmane$org@kba.biglobe.ne.jp>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mail-followup-to: zsh-users@xxxxxxx
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <87r3n2dav7.fsf@nl106-137-147.student.uu.se> <CABx2=D_ji1dy1K3UxxD5vKyjJ+pckLMqj1Pr4Si8i3G2c30mXA@mail.gmail.com> <20150817094752.53c314fe@pwslap01u.europe.root.pri> <9D99B267-5DDD-4C5B-A33A-C5A0251A4B9F__19706.0165032328$1439813299$gmane$org@kba.biglobe.ne.jp>
2015-08-17 20:27:22 +0900, Jun T.:
> In theory, if we want the same effect as the original code
> (which uses 'tr -s "-"'), we need
>
> ${x//[-_[:space:]]##/-}
>
> so that x='a_-_z' becomes 'a-z' (not 'a---z').
>
> BTW, the line
> mv $f $new_name 2> /dev/null
> in the function clean-filename() is dangerous, because two files
> $f can have the same $new_name, in which case one of them is lost
> (or $new_name may already exist before the function is called).
[...]
Note that zmv accounts for that (and also adds the missing
"--") (and turns on extendedglob).
zmv '*' '${f//[-_[:space:]]##/-}'
--
Stephane
Messages sorted by:
Reverse Date,
Date,
Thread,
Author