From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11341 invoked by alias); 28 Dec 2017 15:20:08 -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: 23016 Received: (qmail 27986 invoked by uid 1010); 28 Dec 2017 15:20:07 -0000 X-Qmail-Scanner-Diagnostics: from mail.epopia.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(137.74.101.162):SA:0(-1.9/5.0):. Processed in 11.328605 secs); 28 Dec 2017 15:20:07 -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,HTML_MESSAGE autolearn=ham autolearn_force=no version=3.4.1 X-Envelope-From: psychoslave@culture-libre.org X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Subject: Re: Can zsh `else` reserved keyword command be aliased and the lexem itself be repurposed as `fi` keyword command? To: mathieu stumpf guntz , zsh-users@zsh.org References: From: mathieu stumpf guntz Message-ID: Date: Thu, 28 Dec 2017 16:19:52 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/alternative; boundary="------------D70D7F59EC58DC78325F5686" Content-Language: fr-FR --------------D70D7F59EC58DC78325F5686 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit 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 > > --------------D70D7F59EC58DC78325F5686--