0

Following ZSH: Call in-built function from zsh function that uses the same name and Run a command that is shadowed by an alias, 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? for more details.

So an hypothetical attempt to implement that, if the keyword command existed, would be:

alias alie="keyword else" alias else='fi'

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
psychoslave
  • 2,783
  • 3
  • 27
  • 44
  • Related resources: https://unix.stackexchange.com/questions/148484/how-to-disable-a-shell-keyword – psychoslave Dec 28 '17 at 12:29
  • According to [the builtin documentation](http://zsh.sourceforge.net/Doc/Release/Shell-Builtin-Commands.html) `disable -r else` should disable the `else` keyword, but it lakes explicit example of how to use it. – psychoslave Dec 28 '17 at 12:43

1 Answers1

0

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 really on the "else" substitution that something break, as a non-inline version will indeed enter the else-branch and print "mirinda mondo".

psychoslave
  • 2,783
  • 3
  • 27
  • 44