From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11294 invoked by alias); 17 Feb 2018 13:54:50 -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: List-Unsubscribe: X-Seq: 23134 Received: (qmail 15117 invoked by uid 1010); 17 Feb 2018 13:54:50 -0000 X-Qmail-Scanner-Diagnostics: from out5-smtp.messagingengine.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(66.111.4.29):SA:0(-2.6/5.0):. Processed in 7.790334 secs); 17 Feb 2018 13:54:50 -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=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.1 X-Envelope-From: d.s@daniel.shahaf.name X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= daniel.shahaf.name; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=eit90v wfRPmb9e5L4lePcZDrlcz8sGwlTwNLGteKHqE=; b=bzd46kXyY/jauDC3/M/fUA 4lHtC+K1L+38JtvHRsskRLj0qZ7tJo4daxomKkpunEvanC4mvvNMIcdVFYoZl6LJ H23Yv992rYmxCKErMXB2tlyQbkyBID0OIQr9GGngdctEMPTfgw0HwTKUf9FKs8sv AHEZt4LUfDWYX846q8xMDY1xrwWHVzQSNlfEgyqIv11Nv120D678WPwOVeA3ZXLK yvO49EQ0ipGtE2QN7MxR7fKe4rNUhZK/Rkojmcn9ggUsQyYAAuElwy/Zri+E+OZz DN+SSsQEe52AH3Gqu1XCtssaK2uw0FdcTy3nCpaQY3flmR2fePoAI/8LG/sL/Ozg == 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-sender:x-me-sender:x-sasl-enc; s=fm2; bh=eit90v wfRPmb9e5L4lePcZDrlcz8sGwlTwNLGteKHqE=; b=lo/gM5g41gt+cc8EfqlE9L qqvaxGeyf9crVEIYEEZIYpkNtBe93LLkeutBLVZGpLat9sGgsGmpfTQW+bbTo98T i8xUan5jf6My8l0RJArclBpJaWQ/JLh2Ro3/H4MqSvlsZWFA3WYHHLKCr0bXfpc9 SnITz0UV/1Bmh/1tkOnKJvdIRL1e+9HbEjrC7CIImU+9/qp8EtghV7UNMJcd5o7X YnK3FCpEFZ9uB7ltnBLo99GQeV+e1T0NGztJlxALBwMjiEJYA6shvEq8i0SHtaqr 8SqrCiPrXNqQtibVVOF9ZIf3jAcZbKYEZ4U124uLrRoZrhKxraqi7AoKixnpjTKw == X-ME-Sender: Message-Id: <1518875676.3562728.1274073304.5ED24DC8@webmail.messagingengine.com> From: Daniel Shahaf To: zsh-users@zsh.org MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" X-Mailer: MessagingEngine.com Webmail Interface - ajax-1b99b2df In-Reply-To: <37bb7b6b-ad70-6d03-f979-0e0d3b0be4d3@eastlink.ca> Date: Sat, 17 Feb 2018 13:54:36 +0000 References: <1679a1e0-f716-e501-c4c2-f7e485f9701f@eastlink.ca> <1518827410.2159479.1273706656.1F5B436D@webmail.messagingengine.com> <37bb7b6b-ad70-6d03-f979-0e0d3b0be4d3@eastlink.ca> Subject: Re: alias hygiene Ray Andrews wrote on Fri, 16 Feb 2018 19:14 -0800: > On 16/02/18 04:30 PM, Daniel Shahaf wrote: > > > > I don't understand your question, but allow me to review this code _wit= hout_ > > knowing its context or purpose: > Thanks Daniel, I did suspect it would not be kosher. Is there some way=20 > to see how this looks to the parser after expansion? That way I'd=20 > probably be able to understand the issue better. You could use a widget such as: [[[ f() { local arg for arg in ${(z)1}; do print -r -l -- =C2=AB${(Q)arg}=C2=BB done } show-buffer-parse() { zle -M "$(f "$PREBUFFER$LBUFFER")" } zle -N show-buffer-parse bindkey '^T' show-buffer-parse ]]] There may be plugins that could help, too. > > > > 0. It's a syntax error. > > > > 1. Calling the alias =C2=AB_grep=C2=BB clashes with compsys's function = of that name. > Ah! So I could just rename it as far as that goes? It does seem to=20 > work fine, but this sounds like a gotcha. Yes, just rename it. > > 2. Aliases don't have positional parameters. That =C2=AB$1=C2=BB is sy= ntactically valid > > but I am not sure whether it does what you want (or, rather, whether it= would > > do what you want after you fix #4). > Actually that's the reason for the alias, I want it to pick up the=20 > parameters inline after the alias is expanded. That does not require using $1: % alias x=3D'echo foo' % x qux However, note also: % alias x=3D'echo foo; echo bar' % x qux If you wanted that to print =C2=ABfoo qux=C2=BB, you would have had to use = a function. The use of $1 in your excerpt is a latent bug. > It does what I want but=20 > I question its safety. In practical terms the=20 > "^|$string|$second_string" construction is not something I want to try= =20 > passing to a function You really, really have to learn quoting and escaping. There is no problem= at all with strings that contain variable substitutions and shell and extended= glob metacharacters, provided that they are quoted. I refer you again to the second point #4 in my previous email. Without run= ning that command, what do you expect it to output? Now run it. Do you underst= and why it behaved as it did? > so I thought to just leave it there for the=20 > expanded alias to eat, that is, for egrep to eat. That pipe is not quoted, hence it is syntactical. Alias definitions are si= mple command so they end at a command separator =E2=80=94 which includes =C2=AB;= =C2=BB and =C2=AB&&=C2=BB and =C2=AB|=C2=BB, among others. > > > > 3. Do not interpolate strings into command strings; that's a bobby tabl= es bug. > This is what I had expected the issue would be. Mind, I cobble strings=20 > together into command strings all the time and I've gotten used to the=20 > little tweaks needed. How can I read up on this 'bobby tables'? I=20 > might have developed some bad habits. You might do a web search for that term. > > More information: > > > > 0. =C2=AB||=C2=BB is invalid at the start of a logical line. Either th= ere is an error > > message you did not tell us about or there is a difference between what= you ran > > and what you posted. >=20 > Right, context again, I should only show what is strictly relevant to=20 > the question. I was trying to point out that your report was either incomplete or inaccur= ate, not that it had excessive detail.