zsh-workers
 help / color / mirror / code / Atom feed
From: "Daniel Shahaf" <d.s@daniel.shahaf.name>
To: zsh-workers@zsh.org
Subject: Re: PATCH: trailing components
Date: Tue, 18 Jun 2019 13:37:30 +0000	[thread overview]
Message-ID: <523ba6f0-651a-444a-8ceb-c7c4ec186b20@www.fastmail.com> (raw)
In-Reply-To: <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/*}

  reply	other threads:[~2019-06-18 13:38 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20190618130008eucas1p176cc19c1c8b831fc30b4bf7b3294f3af@eucas1p1.samsung.com>
2019-06-18 13:00 ` Peter Stephenson
2019-06-18 13:37   ` Daniel Shahaf [this message]
2019-06-18 13:54     ` Peter Stephenson
2019-06-18 14:45       ` Mikael Magnusson
2019-06-18 15:39         ` Peter Stephenson
2019-06-18 19:37       ` Daniel Shahaf
2019-06-19 15:02         ` Peter Stephenson
2019-06-20 10:14           ` Peter Stephenson
2019-06-18 14:42     ` Mikael Magnusson

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=523ba6f0-651a-444a-8ceb-c7c4ec186b20@www.fastmail.com \
    --to=d.s@daniel.shahaf.name \
    --cc=zsh-workers@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).