Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Can zsh `else` reserved keyword command be aliased and the lexem itself be repurposed as `fi` keyword command?
- X-seq: zsh-users 23015
- From: mathieu stumpf guntz <mathieu.stumpf-guntz@xxxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Can zsh `else` reserved keyword command be aliased and the lexem itself be repurposed as `fi` keyword command?
- Date: Thu, 28 Dec 2017 16:07:41 +0100
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mail.epopia.com; s=mail; t=1514473662; bh=dyNe3fF3b8/CEBasukJPasijRjidywbwEbPF/pd/LA4=; h=From:Subject:To:Date; b=JdmNE7Rc16Jf8c9GmgcxvYGdga5BQxBMpPsKyyOOr8faORssdb2znfnDxldt4e0vX 2V/yakFTDn7ZudxREUSNq8DOp/Xp4yhiEXjoQg+pl4yrgcV8zV2eIaVaSMl8ELY3fm 99C66f90zAnnjLYLE3VIPMbt2XsrtUTpcEMG+QbQ=
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- List-unsubscribe: <mailto:zsh-users-unsubscribe@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
Hi everybody,
This is mostly a copy of [a question already posted on
stackoverflow](https://stackoverflow.com/questions/48006335/can-zsh-else-reserved-keyword-command-be-aliased-and-the-lexem-itself-be-repur).
Maybe it might have more chance to get an answer over here.
# The problem
Following [ZSH: Call in-built function from zsh function that uses the
same
name](https://stackoverflow.com/questions/37498409/zsh-call-in-built-function-from-zsh-function-that-uses-the-same-name)
and [Run a command that is shadowed by an
alias](https://unix.stackexchange.com/questions/39291/run-a-command-that-is-shadowed-by-an-alias#39296),
it might be expected that a command `keyword` equivalent of what
`builtin` and `command` are doing for their respective eponymous token
category; so that
if [ -z 'love' ]; then echo 'sad world'; keyword else echo
'wonderful world'; fi
would be equivalent to
if [ -z 'love' ]; then echo 'sad world'; else echo 'wonderful
world'; fi
This problem was found in the following tricky scenario: being able to
replace `else` with `alie` and `fi` with `else`. See [Can zsh buildtins
be
aliased?](https://stackoverflow.com/questions/47999451/can-zsh-buildtins-be-aliased)
for more details.
So an hypothetical attempt to implement that, if the `keyword` command
existed, would be:
alias alie="keyword else"
alias else='fi'
# Summary
So, to sum it up, the question is how do you make the following peace of
zsh code works as expected by the previous command:
if [ -z 'love' ]; then echo 'sad world'; alie echo 'wonderful
world'; else
# A first trail
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. So:
alias se='enable -r else; if'
alias alie='else'
disable -r else
alias else="fi; disable -r else"
This unfortunately doesn't work
se [ -z 'amo' ]; then echo 'trista mondo'; alie echo 'mirinda
mondo'; else
# zsh: parse error near `fi'
This is however supposedly on the "else" alias substitution that
something break, as a non-inline version will indeed enter the
else-branch and print "mirinda mondo".
Kind regards
Messages sorted by:
Reverse Date,
Date,
Thread,
Author