Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [PATCH?] Nofork and removing newlines
- X-seq: zsh-workers 52741
- From: Oliver Kiddle <opk@xxxxxxx>
- To: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- Cc: zsh-workers@xxxxxxx
- Subject: Re: [PATCH?] Nofork and removing newlines
- Date: Wed, 13 Mar 2024 00:19:33 +0100
- Archived-at: <https://zsh.org/workers/52741>
- In-reply-to: <CAH+w=7Zb_PWs-h2J9uOUMT6TQXnfPUAXyCWZUEcKyyDx0fDLhg@mail.gmail.com>
- List-id: <zsh-workers.zsh.org>
- References: <CAH+w=7aFJH-5GAu6puszGKvjqN-w0sPCi6v-vGPauDHVujDnag@mail.gmail.com> <20240305065606.ccr2ieheahslcpye@chazelas.org> <CAH+w=7Yb6_eULBq6Ez6pEhtUXOqErr+aDL2BDi7zyxr8QpsTiw@mail.gmail.com> <20240306175711.t3uz2sery3b6tbjw@chazelas.org> <CAH+w=7a5K8ioO+mP8RXvtmawHJFfFw1jOWE49GmZdAOVaTPjUQ@mail.gmail.com> <CAHYJk3Tmh0xVQodHuXycDDv21_xgkhq5hvGZgPrZbLUYox2bGA@mail.gmail.com> <CAH+w=7Yq7e7JOiN51=vQjUvS+Yi6xY0VAJUGjoraeBKKazAnkw@mail.gmail.com> <c053e1e2-b9e1-44af-aae4-4998e768e7ed@app.fastmail.com> <CAH+w=7b24HxJMGUBqjC7Fgx3ycLWwAuK0CTpwSSryb0XXxEHMw@mail.gmail.com> <90726-1709936102.086878@xlWC.oGpX.V4Q4> <CAH+w=7Zv1RsPoFBsLVjqS5wh0n4wQpsVQg3z2pKpfuYkjRk6CA@mail.gmail.com> <34739-1710017038.959920@XhYc.enDL.DTxr> <CAH+w=7Zk2usqyP1CtviobNZNnzAxhh_f5tnPdj-aLkBjX6B_cw@mail.gmail.com> <CAH+w=7Zb_PWs-h2J9uOUMT6TQXnfPUAXyCWZUEcKyyDx0fDLhg@mail.gmail.com>
Bart Schaefer wrote:
> On Fri, Mar 8, 2024 at 2:15 PM Oliver Kiddle <opk@xxxxxxx> wrote:
> >
> > Why does it print command not found errors for things like ${|=|:},
> > ${|*|:} and ${|?|:}, I'd rather have $? than it globbing for a single
>
> Bart Schaefer wrote:
> > See above about the requirement for it to look like ${|ident|...}.
> > Since = * and ? are not identifiers, this is like writing { =|: } etc.
Considering this explanation, it is apparent that allowing |ident| is
not fully compatible with mksh where ${|ls| cat -} runs ls.
Not that I think that matters as such. In usage, it is probably wise to
make a convention of always having a space before the command starts.
And this leads on to the later question as we probably don't want to
expand considerably on what is valid between the vertical bars.
> This can be done with e.g.
>
> typeset -n bang=!
> ... ${|bang|...} ...
Yes that works. Is nice to see namerefs coming up in nifty solutions. I
hadn't checked the code for what supporting ? / ! would involve. If
trivial why not, but I well understand not wanting to do anything that
involves the lexer.
> However:
>
> Returning to the original context here, we were talking about how to
> make ${ ... } more newline-trimming-compatible with $(...) while still
> providing a way to specify that newlines not be trimmed, and using
> ${||...} for the latter came up.
>
> In thinking about ${|?|...} etc. I realized that there's no real
> reason a set of non-identifier characters couldn't be allowed to
> follow the first vertical bar. It'd have to be simpler than just
> tossing parameter expansion flags in there, but I could investigate
> whether we could do things like ${|=|...} is the same as ${=${ ... }},
> ${|~|...} is ${~${ ... }}, etc. That only saves 1 character, though,
> and I'm not sure it's clearer.
Would that potentially also extend to something like ${|=var| ... }
That might look like a default value assignment to someone used to a
language where vertical bars delimit closure parameters. Coming within
the vertical bars the character has a closer syntactic attachment to the
variable implying a semantic attachment. If it is hard to support
${= ... } then not doing it at all is probably better.
Given that the ${|var| ... } form appears to create a function-like
scope, should var perhaps be auto-declared local for that scope and the
local value be substituted?
> It does mean, though, that we could use something like ${|<|...} for
> non-trimming command substitution, instead of "empty" || meaning that.
> Just from a "clean look" standpoint, though, I still like the quoting
> approach better.
The quoting approach is clean and logical and is probably my preferred
option. I was initially bothered by the lack of consistency with $(...)
(where quoting prevents word splitting) but it can be useful if the lack
of fork is not the only thing which makes ${ ... } different and because
of the syntactic resemblance, consistency with ${var} is perhaps more
important - it does word splitting based on the shwordsplit option.
> Separately, it's definitely possible to make zsh-mode ${ ... } trim
> only one newline instead of all of them.
Only one is probably the most useful. I would mostly associate the fact
that $(...) strips multiple with the fact that it does word splitting
and so drops repeated newlines (empty words) also from the middle.
Admittedly "$(...)" preserves empty words in the middle but still drops
those at the end.
Oliver
Messages sorted by:
Reverse Date,
Date,
Thread,
Author