Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: PATCH: trailing components
- X-seq: zsh-workers 44422
- From: "Daniel Shahaf" <d.s@xxxxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: Re: PATCH: trailing components
- Date: Tue, 18 Jun 2019 13:37:30 +0000
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= daniel.shahaf.name; h=mime-version:message-id:in-reply-to :references:date:from:to:subject:content-type :content-transfer-encoding; s=fm3; bh=/5vTSLpZ+IhLBwGsQSq1MFpxIs sGysvQE2r9CmhM094=; b=tiaVflIOIAEghMGLLA20VIjLDJaHTaW362hvn7CBwF XH4mG3gZeMevj6+mzKaV8FqVdtqSxwyyD81YbD/oF7ZtMYfKKXPFOVnZyHtXcyuY ZAFoTl0Iv9z88wG3r500Yi6iRwuhuWpLEm4ee4+yYpOZ613SOYuf1SH/TTdybH0X gbqGglS8RxmMRI0qnNdhh5zpBarhpCK5mhWdPQm8RACSU43+dmkNAExuI2FLO0zD lj5zFrYchjgDXCOy5rXjiew6cnDNjF9V7H1oC3ujGGUGMkPWnPpTtYZZhXtR3lON jLLfpEi+73R7UO+nvTvZTLx8DzCh+8rdFQJaANihIYsQ==
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=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=fm3; bh=/5vTSLpZ+IhLBwGsQSq1MFpxIssGysvQE2r9CmhM0 94=; b=UdKYIIiN27ZKHKqxEyUMnxwZhV08I9Bcq5LZtNmWDP0PNdX1lW7EHRGKQ oBtGimdtYkJ6lkVWlQ7qVx1rrEmAZwEtwPW3ny6oR0pHuvKNAPMY+UWShE2/m7Oj n6uHGxbj+cYURc1LC7D+f85YMq4yOklDuetYSPsJ6s3n1Upne4r2znrc51GB+Mrd JpWAGu0/Nm2le2gdOYiPzlum9GuSjQxwfMaqLHDG/uxGw6FDSwHI2+AgJiG8YezF oWHFI2YoJrlGp3wD3qVWGBMC9AmeBMXxl7ywkLwNi8BPqukA3bKh/f397MDeeTf8 dM3gqC8QaX9UhAV+lUOdwynzfQPTw==
- In-reply-to: <1560862806.7731.11.camel@samsung.com>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-unsubscribe: <mailto:zsh-workers-unsubscribe@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <CGME20190618130008eucas1p176cc19c1c8b831fc30b4bf7b3294f3af@eucas1p1.samsung.com> <1560862806.7731.11.camel@samsung.com>
Peter Stephenson wrote on Tue, 18 Jun 2019 13:01 +00:00:
> I needed to preserve a number of trailing components of a path (other
> than one) and couldn't think of an easy way of doing it. Rather than
> craft obscure pattern substitutions, or use an ad-hoc expression to
> strip the prefix, I came up with a patch to add an optional number after
> the "t" in history style modifiers to do this. I put it after rather
> than before because history-style colon expressions are quite sensitive
> to what the first character is after the colon.
>
> Before I come up with tests and fix up the ensuing failures, you can let
> me know if there's a better way of doing this to save me the trouble.
Here are some alternatives, but I'm not claiming any of them is better than «${foo:t2}»:
f() {
REPLY=
for 1 in {1..$1} ; do REPLY=$2:t/$REPLY; 2=$2:h ; done
}
f $N "$foo"; foo=$REPLY
or
foo=${(j./.)${${(s./.)foo}[-$N,-1]}}
(plus or minus handling of runs of several consecutive slashes)
or
tmp=$foo
for i in {1..$N} ; do tmp=$tmp:h ; done
foo=${foo#$tmp/*}
Messages sorted by:
Reverse Date,
Date,
Thread,
Author