From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1638 invoked by alias); 28 Dec 2016 06:04:57 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 22301 Received: (qmail 2008 invoked from network); 28 Dec 2016 06:04:57 -0000 X-Qmail-Scanner-Diagnostics: from mail-ua0-f182.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(209.85.217.182):SA:0(-0.0/5.0):. Processed in 1.033083 secs); 28 Dec 2016 06:04:57 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_PASS,T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.1 X-Envelope-From: schaefer@brasslantern.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at _netblocks.google.com designates 209.85.217.182 as permitted sender) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=from:message-id:date:in-reply-to:comments:references:to:subject :mime-version; bh=YdP4SAbA7C5gLsRILun21+/t36Fwf4CvBr8exBWQSnw=; b=1+my2bYkMLNDKjuIgYvfOneIelQU43jlBO4harW9pkMoutolviNlZVn2TnTvFkhvXo qPRi+N3I9AVkUi3USHXvp+XLuEEujvLqJHHcAL+81cVUdzHW7YWFV630Y+vL/9IsvDFi CYJU4BTlf99Rqk7bDBcxqOhaeC5j1j/Tlyl9/A0LfCtCFpaEK9A0uDFaaPjG6pdU5DmN BM+uwWL3Q3dpV/n+DRtzKPZ4arz9Cq5O7Z4Di6PsOnWHDuOiMdpvfFFWUNZ65d/yTcsu Eo6eo6VttugfFJ/xH+avAuwdtrKDt29MpZSwuf688zkdqQxMaDDBeFImynBDf52C84Vr qVbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:message-id:date:in-reply-to:comments :references:to:subject:mime-version; bh=YdP4SAbA7C5gLsRILun21+/t36Fwf4CvBr8exBWQSnw=; b=mt06DrKqVk9Iz3rMupEwnvYjWrsL66fl2MXWrBtCe7dgaF7tBE2O7HUweaNI+8RiSu HBk+Kok52v7Nn8c+t7X5OFtP0NNCQVHZg3h+bP9mi7rEEnPJ1kkfIgzKVrM+Nr8JCqJI uQlbK/fbQi2NMPaI+4pGMxi4vmX3i9/dp71hEN98AZTy6Ndjk5Y53NQMh1kRsUZswvcT Yn1aP6xY+7aPPtc27/4whIjO+J89WY5KUJOVy9g3I493oL4N8LLjqhVHnthF7pSlHZN8 nN1jn4+nZY6ZBO1VlZbNWqex6/iEsvqCWXVOcty6qTnHDRxU1sOTvgh+4ITYP88YyI0Q Ba3Q== X-Gm-Message-State: AIkVDXKRCbfcWR5aS/iYbNnoCh1JU6u1Vq1P1AKJ8ox/kgC5FHXUfQIYY1DikStdmB1vsA== X-Received: by 10.176.0.14 with SMTP id 14mr16916666uai.20.1482905088951; Tue, 27 Dec 2016 22:04:48 -0800 (PST) From: Bart Schaefer Message-Id: <161227220458.ZM3240@torch.brasslantern.com> Date: Tue, 27 Dec 2016 22:04:58 -0800 In-Reply-To: Comments: In reply to Ray Andrews "Re: append to history entry?" (Dec 27, 4:57pm) References: <5288b537-f06a-d18a-60ea-1f962856c80c__41345.3811700039$1482803962$gmane$org@eastlink.ca> <20161227125530.GA4796@fujitsu.shahaf.local2> <161227080022.ZM519@torch.brasslantern.com> <99549001-5744-c36f-a4dc-404071aba08a@eastlink.ca> <161227110954.ZM1153@torch.brasslantern.com> <0a48db86-b41a-283c-8193-e2766aa5d30b@eastlink.ca> <161227155552.ZM2385@torch.brasslantern.com> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: zsh-users@zsh.org Subject: Re: append to history entry? MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii On Dec 27, 4:57pm, Ray Andrews wrote: } Subject: Re: append to history entry? } } It's all this backslash and 'is it one string or several strings' } stuff. The "one or several" distinction of course has to do with the way arguments are processed. You definitely want to be able to preserve inside the function whatever argument division was supplied to it at the call, so you need a way to indicate that; you just have to be sure you're only making that indication when you mean it. } ... it seems that the backslashes need protecting and reprotecting and } yet more protecting and each stage of the protection is different from } the last. The backslash stuff is borrowed conceptually from C (\t for tab, etc.). Having that same paradigm applied at multiple levels of processing stems from the language being interpreted rather than compiled. } For me, the task is to see the 'naturalness' for lack of a better word } of the way that zsh does this: } } print -rS -- "rap ${${(q+)@}}; : ${(q-)HOST}" The point is that this isn't "natural," because what you asked for isn't natural. Think through what you said you want: 1. Take a command line and parse it. 2. When the parsed arguments are received by the command ... a. reconstitute the original command line b. append another command that includes the host name 3. Put all of that into the history, formatted such that a. it shows what you want when you recall the history, and b. it executes again without errors Which step of that after the first one is "natural" for the shell? Of course you can fudge any one of those steps. The host name most probably doesn't have any special characters, so ${(q-)HOST} is likely going overboard and all you really need is $HOST; but for the sake of everyone else who's going to see this and copy-paste, it may be worth forestopping any future problems. Similarly you may never have any quoted spaces or backslashes or anything like that in the arguments of "rap" and therefore ${(q+)@} might also be unnecessary, but someone might try to use this same recipe for some other command that does have those things. I tend to want those people to make their own mistakes and come back with more questions; Daniel tries to cover all corner cases up front. } Couldn't we just: } } setopt protect-backslashes-thanks } print -S "rap $@; : $HOST" That still wouldn't work because $@ is the way you preserve argument divisions. You can't get away from thinking about what you mean. } Bart and Daniel didn't get it exactly right the first time. What hope } do I have? Stop worrying about getting it exactly right. What you had in the first place was going to work in 90%+ of cases, and when you found a case that didn't, then someone could have explained why not.