Zsh Mailing List Archive
Messages sorted by:
Re: Can zsh `else` reserved keyword command be aliased and the lexem itself be repurposed as `fi` keyword command?
- X-seq: zsh-users 23017
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: Zsh Users <zsh-users@xxxxxxx>
- Subject: Re: Can zsh `else` reserved keyword command be aliased and the lexem itself be repurposed as `fi` keyword command?
- Date: Fri, 29 Dec 2017 00:38:13 -0800
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=frh2QWnxl6099LsFsz/8qg7ZquFzjLj1VMUKOYrY6OI=; b=fDfTlY7ozPwq5Uh0Stus8XvsqNPDNAdsdaCFj1rtxkxv7iSZWo5DaKzQDuTA3+CCcK wgAHhTOIBosePQcMSIuFY1Xkp/mU16u2QfsouHivn/akf9uXCzEW5UqBy2eh/hEk6+a7 qzuSg7HiRl8gQjncDSAB75htD82qloBCqq99LJxLUVGSrr4EPVPSi+Ajd4y0b5qBZEzn jiuPTKm+/eMncRWE5ZiVKbwIrq+ea/hwgW3TS8qtOTOgHeyqHigaK4y53v3kIc6B0t8n A0rDWRIlqSMg7smKc3nU+KJKUxr+0i6NkSzt/jDPxDto2ZjHOi9axpkRiu3DTSQQff5z qgsw==
- In-reply-to: <email@example.com>
- List-help: <mailto:firstname.lastname@example.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:email@example.com>
- List-unsubscribe: <mailto:firstname.lastname@example.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <email@example.com>
On Thu, Dec 28, 2017 at 7:07 AM, mathieu stumpf guntz
> it might be expected that a command `keyword` equivalent of what `builtin`
> and `command` are doing for their respective eponymous token category
If you haven't already, go read https://askubuntu.com/a/590335 which
was linked from
Your hypothetical "keyword" would have to itself be a keyword (and
thus not a command).
> This problem was found in the following tricky scenario: being able to
> replace `else` with `alie` and `fi` with `else`.
> alias alie="keyword else"
> alias else='fi'
What's the underlying reason for doing this? That is, aside from the
overall desire to write in Esperanto (?), I get wanting "alie" to
mean the same thing "else" means, but not why "else" should mean "fi".
Even in your "alie echo 'mirinda mondo'" example it looks like "else"
is meant to act as "fi;else" so that you can continue with more of the
> This is not yet a working solution, but here is an idea: using the `-r` flag
> of `enable` and `disable` builtin commands to change visibility of the
> `else` keyword
This is doomed to failure, because complex shell syntax is fully
parsed before it is executed. Your "disable" or "enable" has to take
place before the parsing step, because it won't be executed during the
parse. Some extremely simple cases might appear to work at the
command prompt, but as soon as you embed them in a larger structure
like a function body they will fail.
In fact the "fully parsed before executed" property is one of the
important reasons for keywords being distinct from commands.
Aliases "work" before the parse because they are merely text
replacements and can be done before full token analysis is performed.
What is needed is an alias that ends recursive replacement. Normally
one does this by including quoting (e.g., a leading backslash) in the
value of the alias, but that doesn't help in this case because it
prevents the replacement from being considered a keyword as well.
There may be a clever way to accomplish this -- recursion stops if
replacement results in a previously replaced alias, for example, to
avoid infinite loop -- but I haven't worked out an answer.
Messages sorted by: