zsh-users
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Leonardo dos Reis Gama <leonardo.reis.gama@gmail.com>
Cc: Zsh Users <zsh-users@zsh.org>
Subject: Re: Subcommand dispatcher and alias factory
Date: Fri, 31 Aug 2018 16:01:25 -0700	[thread overview]
Message-ID: <CAH+w=7Y+zVuihV2+vvXSVBkBxak2SXS=-m1k4O7z9v-PrTE++w@mail.gmail.com> (raw)
In-Reply-To: <CAAJJbEUL_PAN08p6fGKQEhajLGQkociru+UYvpV-7x+aN2uYxA@mail.gmail.com>

On Fri, Aug 31, 2018 at 2:54 PM, Leonardo dos Reis Gama
<leonardo.reis.gama@gmail.com> 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.


  reply	other threads:[~2018-08-31 23:01 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-31 21:54 Leonardo dos Reis Gama
2018-08-31 23:01 ` Bart Schaefer [this message]
2018-09-03 14:07   ` Daniel Shahaf
2018-09-08  5:56 ` genelocated
2018-09-08  5:58 ` genelocated

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='CAH+w=7Y+zVuihV2+vvXSVBkBxak2SXS=-m1k4O7z9v-PrTE++w@mail.gmail.com' \
    --to=schaefer@brasslantern.com \
    --cc=leonardo.reis.gama@gmail.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).