Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Subcommand dispatcher and alias factory



On Fri, Aug 31, 2018 at 2:54 PM, Leonardo dos Reis Gama
<leonardo.reis.gama@xxxxxxxxx> wrote:
>
> It's a common theme: you have a program with subcommands and want to alter
> its default behaviour somehow (what would be easy to do for a common
> command with a simple alias or function).
>
> Is there any zsh plugin that implements either of these features for *any
> command*?

This can't really be done by the shell in a generalized way, because
in a construct like

% git myfancything ...

the shell MUST first execute "git".  Unless all commands with
subcommands were to share some standard exit status or error message
that would allow the shell to discover that the reason for failure was
that the subcommand is not found, the shell has no generic way to know
why the primary command failed in order to try it again differently.
You can program it separately for each command that has subcommands,
as was shown in examples in a couple of the links you mentioned.

This, by the way, is why commands with subcommands are basically
horrible, and a perversion of the UNIX command model.  It's like
creating a custom shell within the shell.  Which latter is fine if you
tell the user that's what you're doing (I was one of the major
contributors to a custom shell for managing email, back in the day),
but in the git-style incarnation always grates on me in the same way
that layering violations in object-oriented programs do.



Messages sorted by: Reverse Date, Date, Thread, Author