From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.5 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: from zero.zsh.org (zero.zsh.org [IPv6:2a02:898:31:0:48:4558:7a:7368]) by inbox.vuxu.org (Postfix) with ESMTP id 5BB3D2B8F4 for ; Wed, 13 Mar 2024 00:20:15 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Message-ID:Date: Content-Transfer-Encoding:Content-ID:Content-Type:MIME-Version:Subject:To: References:From:In-reply-to:cc:Reply-To:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=gNpyS/fNkyRQu5IsbykrYkydyCwRCUoeXwE/7hEhmUI=; b=m3J29Yl5za5xFq0PHhWZl0gpXd 1NWkMEklzEsILPYakgPv0YF39iVSsBz/oIThzS6Z1RnnUv8juwtY+nRTuDpiGDU9cIEdUPFGmSiZQ 07NsINhq5hHXyWf17+s/DKCFWHnN+S+QgY5/uuKeZ7AcRGawBd3f9NoRhC1a+1avdNv8PdeMbIZSl ldLYLWppCPe2gEU9dIxAQq2Kn3oWnAh60A1NMT884U8uJqYplPhLekw54+PB49ZEHDA2OdN7HmCSI A+TWXaysZbtbQWFvk6b6eB69aAAjSWxbJolY8lBdpfGy2NOJE3uI33ea35jc8WkD4+JC8h6/EohsL 6I23JPCw==; Received: by zero.zsh.org with local id 1rkBPp-000Gqh-SP; Tue, 12 Mar 2024 23:20:14 +0000 Received: by zero.zsh.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1rkBPD-000GV4-NS; Tue, 12 Mar 2024 23:19:36 +0000 Received: from [192.168.178.21] (helo=hydra) by mail.kiddle.eu with esmtp(Exim 4.97.1) (envelope-from ) id 1rkBPC-000000006an-0ESR; Wed, 13 Mar 2024 00:19:34 +0100 cc: zsh-workers@zsh.org In-reply-to: From: Oliver Kiddle References: <20240305065606.ccr2ieheahslcpye@chazelas.org> <20240306175711.t3uz2sery3b6tbjw@chazelas.org> <90726-1709936102.086878@xlWC.oGpX.V4Q4> <34739-1710017038.959920@XhYc.enDL.DTxr> To: Bart Schaefer Subject: Re: [PATCH?] Nofork and removing newlines MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <25343.1710285573.1@hydra> Content-Transfer-Encoding: 8bit Date: Wed, 13 Mar 2024 00:19:33 +0100 Message-ID: <25344-1710285573.990297@5-7t._0Mp.XRXG> X-Seq: 52741 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: , List-Subscribe: , List-Unsubscribe: , List-Post: List-Owner: List-Archive: Bart Schaefer wrote: > On Fri, Mar 8, 2024 at 2:15 PM Oliver Kiddle 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