zsh-users
 help / color / mirror / code / Atom feed
From: mathieu stumpf guntz <psychoslave@culture-libre.org>
To: mathieu stumpf guntz <mathieu.stumpf-guntz@epopia.com>,
	zsh-users@zsh.org
Subject: Re: Can zsh `else` reserved keyword command be aliased and the lexem itself be repurposed as `fi` keyword command?
Date: Thu, 28 Dec 2017 16:19:52 +0100	[thread overview]
Message-ID: <ef2c2e74-8f03-bfcb-1dd9-bfb1594c8b40@culture-libre.org> (raw)
In-Reply-To: <ecebd27c-08ad-7cb3-50a9-d6ba56e288ef@epopia.com>

[-- Attachment #1: Type: text/plain, Size: 2917 bytes --]

On a side note, the line `enable -r else; if true; then else fi; disable 
-r else` won't work with two execution in a row:

      ▶ enable -r else; if true; then else fi; disable -r else # works
      ▶ export LANC=C enable -r else; if true; then else fi; disable -r else
      fi # added to close the `if`
      => export: not valid in this context: -r

Is there a way to force execution at some point on a single line, as if 
there was performed on two lines?


Le 28/12/2017 à 16:07, mathieu stumpf guntz a écrit :
> 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
>
>


  reply	other threads:[~2017-12-28 15:20 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-28 15:07 mathieu stumpf guntz
2017-12-28 15:19 ` mathieu stumpf guntz [this message]
2017-12-29  8:47   ` Bart Schaefer
2017-12-29 10:51     ` mathieu stumpf guntz
2017-12-29 19:15       ` Bart Schaefer
2017-12-29 19:29         ` mathieu stumpf guntz
2017-12-29 19:49           ` Bart Schaefer
2017-12-29 20:27             ` Ray Andrews
2017-12-29 23:45               ` Bart Schaefer
2017-12-30  1:07                 ` Bart Schaefer
2017-12-30  9:50                   ` mathieu stumpf guntz
2017-12-30 10:05                     ` Frank Terbeck
2017-12-30 17:22                   ` Ray Andrews
2017-12-30 22:06                     ` Bart Schaefer
2017-12-30 23:00                       ` Ray Andrews
2017-12-30 17:16                 ` Ray Andrews
2017-12-30 22:23                   ` mathieu stumpf guntz
2017-12-30 23:06                     ` Ray Andrews
2017-12-30 23:32                       ` mathieu stumpf guntz
2017-12-30  9:36               ` mathieu stumpf guntz
2017-12-30 17:39                 ` Ray Andrews
2017-12-29 22:59       ` Nikolay Aleksandrovich Pavlov (ZyX)
2017-12-29  8:38 ` Bart Schaefer
2017-12-29 10:24   ` mathieu stumpf guntz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ef2c2e74-8f03-bfcb-1dd9-bfb1594c8b40@culture-libre.org \
    --to=psychoslave@culture-libre.org \
    --cc=mathieu.stumpf-guntz@epopia.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).