From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 406 invoked by alias); 19 Feb 2018 06:28:58 -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: 23145 Received: (qmail 14126 invoked by uid 1010); 19 Feb 2018 06:28:58 -0000 X-Qmail-Scanner-Diagnostics: from mail-it0-f52.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.214.52):SA:0(-1.9/5.0):. Processed in 1.937093 secs); 19 Feb 2018 06:28:58 -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=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_PASS,T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.1 X-Envelope-From: schaefer@brasslantern.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | 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=Mf+FFCVbyLIT+ZHXZ6HUbtcjyUpMDU9llrO7KwuPjnU=; b=rSNCRzErA34vqQGNfCMQV5nq8VGuJW38+HHHhr0tlu5Uwlmdv6EpUUUOxls+elZq6r mfiC99dQ4IsxWF4+q/r/twlLg+ccSEkUkHIMVgVtcuoJyKkA6aIocwPp7L/agGNJy27/ avZbqznmf8jQkqiAA+kBw3hdMnidhmtfbmZxLjh6/E6PchGZ/csh1iXDS5dDQyyrCIg3 a3gVEvfQYCwsLq/u5SSX001IvzV4f7CY80ItR7F2L5k8nfCk13/UWWeCrsKol6cDx14w 6pmvbsjM4e5a/RpQs5gZbaD3xuXKzjfZNXB0StRKOj0VfvKTTgiTWsOsclNLz2J/Ftxj L/Pg== 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=Mf+FFCVbyLIT+ZHXZ6HUbtcjyUpMDU9llrO7KwuPjnU=; b=fppXhrH31LIAkDWLJvYtLzv7n+tSzILaF8hqFqwZQCH/IcXOP7fGV///CK69UCr06r SIrok+oM9fWh3qW3w22+3bj4CI4b4Po4e7y7/BBu3J/HcufjNeG2L4KO7ReJqE+P1qTs P279dKuh+1o+iIzvR1MyM42mZ1tyRXw82ypT+3U0iWWKRSqjFNVMoTDQOg0qYbTNGWV0 ggRF0Qja34GOnuF1p4r+LQX8TW78M4N5262EXDyfBEzHfQx3GxmvrlFe2aUlj3gZO2X2 mLS63+naRUaxPSSqzx6gAF+dDogdBgKRoCxNsoxt7B06W3gCK4Y/T63T5YxK4anKPQTB QRzw== X-Gm-Message-State: APf1xPAHPyTZeWTt4gh4Z4mL1GQIwS1jG5PqNZuj5lWK1/U/Ej4UQZ3J OZWQZo/2ONU8FWjb2a08LPZ7K3oN X-Google-Smtp-Source: AH8x225IXtql3SEuu3PBkpxQOEZKcDR3CR2yzGUJx3VJ+cMUeTD1YnW377j5YutJv2DMkkiOhJU6JA== X-Received: by 10.36.175.67 with SMTP id l3mr8678412iti.43.1519021732222; Sun, 18 Feb 2018 22:28:52 -0800 (PST) From: Bart Schaefer Message-Id: <180218222847.ZM11922@torch.brasslantern.com> Date: Sun, 18 Feb 2018 22:28:47 -0800 In-Reply-To: <1518827410.2159479.1273706656.1F5B436D@webmail.messagingengine.com> Comments: In reply to Daniel Shahaf "Re: alias hygiene" (Feb 17, 12:30am) References: <1679a1e0-f716-e501-c4c2-f7e485f9701f@eastlink.ca> <1518827410.2159479.1273706656.1F5B436D@webmail.messagingengine.com> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: zsh-users@zsh.org Subject: Re: alias hygiene MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii To add a few remarks here ... On Feb 17, 12:30am, Daniel Shahaf wrote: } Subject: Re: alias hygiene } } Ray Andrews wrote on Wed, 14 Feb 2018 08:09 -0800: } > } > [ some test ] && alias _grep="egrep --color=always "$string"" } > || alias _grep="egrep --color=always "^|$1|$string"" } } I don't understand your question The way the quoting is arranged here is funny. If we look at the first line only, the quotes are such that $string must have a value at the time the alias is defined (rather than when it is used) and there is a useless empty quote pair at the end of the line. Although it may seem you can nest double quotes when using $(...) or some ${...} syntax -- echo "Outer and $(echo "inner also") quotes" -- the presence of the $(...) is important. In the absence of any of the balanced-parens or balanced-braces inside, quotes do not nest. } 1. Calling the alias "_grep" clashes with compsys's function of that name. This isn't really important; the completion system disables aliases, and it would not make sense to use the _grep function outside completion, so in practice there's no conflict. } 2. Aliases don't have positional parameters. True (and different from csh aliases which can make history references to simulate positionals) but ever since the introduction of argument processing in anonymous functions it has been possible to write alias _grep='() { egrep --color=always "^|$1|$string" }' There are a few reasons (e.g., the previously mentioned clash with a completion function) why one might prefer this over defining a named function, and a few other reasons why one might avoid it (see below). To be pedantic, in the above example _grep foo woould expand to () { egrep --color=always "^|$1|$string" } foo which would pass "foo" to the anonymous sub as "$1". } 3. Do not interpolate strings into command strings; that's a bobby } tables bug. I think this was unintentional, and that instead there's confusion about the nesting of the quotes. I think Ray meant to write alias _grep='egrep --color=always "$string"' (although in that case I'm not sure where $string comes from). } 4. Those pipe characters are not quoted so they create a pipeline Another likely case of incorrect quote nesting. } More information: } } 0. "||" is invalid at the start of a logical line. Most likely line wrap added in a syntactically invalid place. (Aside: The discussion that led up to the ability to make aliases for command separators was spawned by a desire to be able to put "||" at the start of a logical line.) } 1. ... (depends on how you autoload compinit) No. Even if compinit is loaded with aliases enabled, there's no explicit reference to any of the _* functions to cause confusion with the alias, and aliasing is turned off during _main_complete. You'd have to jump through hoops to deliberately break it. ==== One other remark about aliases with anonymous functions: It's dangerous to do this with global aliases. Example: alias -g BODY='() { echo I am a function body }' echo this is a BODY will (with default setopts) create four functions (echo, this, is, a) all with the same definition -- and that "echo" function calls itself.