zsh-users
 help / color / mirror / code / Atom feed
* Subcommand dispatcher and alias factory
@ 2018-08-31 21:54 Leonardo dos Reis Gama
  2018-08-31 23:01 ` Bart Schaefer
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Leonardo dos Reis Gama @ 2018-08-31 21:54 UTC (permalink / raw)
  To: zsh-users

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

Hi there! I'm new here...

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). Or, if you feel adventurous, you
may want to create your own subcommand. Git, for example, solve both
problems seamlessly with its "git aliases" and by looking for a
"git-myfancysubcommand" executable in your path when confronted with an
unknown subcommand.

Is there any zsh plugin that implements either of these features for *any
command*? I could not find one. If there isn't such a thing, I would be
happy to create it!

Some previous discussions about the issue:
https://unix.stackexchange.com/questions/48862/how-can-i-create-an-alias-for-a-git-action-command-which-includes-spaces
https://www.zsh.org/mla/users//2014/msg01067.html
https://stackoverflow.com/questions/34748747/can-i-alias-a-subcommand-shortening-the-output-of-docker-ps
https://stackoverflow.com/questions/40654352/how-to-write-an-alias-for-two-words
https://eklitzke.org/bash-subcommand-aliases


Thank you for your attention,

Leonardo Gama
[image: https://]about.me/leogama
<https://about.me/leogama>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Subcommand dispatcher and alias factory
  2018-08-31 21:54 Subcommand dispatcher and alias factory Leonardo dos Reis Gama
@ 2018-08-31 23:01 ` Bart Schaefer
  2018-09-03 14:07   ` Daniel Shahaf
  2018-09-08  5:56 ` genelocated
  2018-09-08  5:58 ` genelocated
  2 siblings, 1 reply; 5+ messages in thread
From: Bart Schaefer @ 2018-08-31 23:01 UTC (permalink / raw)
  To: Leonardo dos Reis Gama; +Cc: Zsh Users

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.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Subcommand dispatcher and alias factory
  2018-08-31 23:01 ` Bart Schaefer
@ 2018-09-03 14:07   ` Daniel Shahaf
  0 siblings, 0 replies; 5+ messages in thread
From: Daniel Shahaf @ 2018-09-03 14:07 UTC (permalink / raw)
  To: Zsh Users; +Cc: Leonardo dos Reis Gama

Bart Schaefer wrote on Fri, Aug 31, 2018 at 16:01:25 -0700:
> 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.
> 

I don't understand what's so bad about subcommands.  What's different
between, say, «git ci -S foo» failing because 'git' doesn't know the
'ci' subcommand, and that command failing for any other business logic
reason (e.g., 'foo' being an invalid argument)?

> 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.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Subcommand dispatcher and alias factory
  2018-08-31 21:54 Subcommand dispatcher and alias factory Leonardo dos Reis Gama
  2018-08-31 23:01 ` Bart Schaefer
@ 2018-09-08  5:56 ` genelocated
  2018-09-08  5:58 ` genelocated
  2 siblings, 0 replies; 5+ messages in thread
From: genelocated @ 2018-09-08  5:56 UTC (permalink / raw)
  To: Leonardo dos Reis Gama, zsh-users

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

You may like this...
https://github.com/ktr0731/salias

---Original---
From: "Leonardo dos Reis Gama"<leonardo.reis.gama@gmail.com>
Date: Sat, Sep 1, 2018 05:55 AM
To: "zsh-users"<zsh-users@zsh.org>;
Subject: Subcommand dispatcher and alias factory


Hi there! I'm new here...

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). Or, if you feel adventurous, you
may want to create your own subcommand. Git, for example, solve both
problems seamlessly with its "git aliases" and by looking for a
"git-myfancysubcommand" executable in your path when confronted with an
unknown subcommand.

Is there any zsh plugin that implements either of these features for *any
command*? I could not find one. If there isn't such a thing, I would be
happy to create it!

Some previous discussions about the issue:
https://unix.stackexchange.com/questions/48862/how-can-i-create-an-alias-for-a-git-action-command-which-includes-spaces
https://www.zsh.org/mla/users//2014/msg01067.html
https://stackoverflow.com/questions/34748747/can-i-alias-a-subcommand-shortening-the-output-of-docker-ps
https://stackoverflow.com/questions/40654352/how-to-write-an-alias-for-two-words
https://eklitzke.org/bash-subcommand-aliases


Thank you for your attention,

Leonardo Gama
[image: https://]about.me/leogama
<https://about.me/leogama>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Subcommand dispatcher and alias factory
  2018-08-31 21:54 Subcommand dispatcher and alias factory Leonardo dos Reis Gama
  2018-08-31 23:01 ` Bart Schaefer
  2018-09-08  5:56 ` genelocated
@ 2018-09-08  5:58 ` genelocated
  2 siblings, 0 replies; 5+ messages in thread
From: genelocated @ 2018-09-08  5:58 UTC (permalink / raw)
  To: Leonardo dos Reis Gama, zsh-users

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

You may like this...
https://github.com/ktr0731/salias



 
---Original---
From: "Leonardo dos Reis Gama"<leonardo.reis.gama@gmail.com>
Date: Sat, Sep 1, 2018 05:55 AM
To: "zsh-users"<zsh-users@zsh.org>;
Subject: Subcommand dispatcher and alias factory


Hi there! I'm new here...

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). Or, if you feel adventurous, you
may want to create your own subcommand. Git, for example, solve both
problems seamlessly with its "git aliases" and by looking for a
"git-myfancysubcommand" executable in your path when confronted with an
unknown subcommand.

Is there any zsh plugin that implements either of these features for *any
command*? I could not find one. If there isn't such a thing, I would be
happy to create it!

Some previous discussions about the issue:
https://unix.stackexchange.com/questions/48862/how-can-i-create-an-alias-for-a-git-action-command-which-includes-spaces
https://www.zsh.org/mla/users//2014/msg01067.html
https://stackoverflow.com/questions/34748747/can-i-alias-a-subcommand-shortening-the-output-of-docker-ps
https://stackoverflow.com/questions/40654352/how-to-write-an-alias-for-two-words
https://eklitzke.org/bash-subcommand-aliases


Thank you for your attention,

Leonardo Gama
[image: https://]about.me/leogama
<https://about.me/leogama>

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-09-08  6:06 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-31 21:54 Subcommand dispatcher and alias factory Leonardo dos Reis Gama
2018-08-31 23:01 ` Bart Schaefer
2018-09-03 14:07   ` Daniel Shahaf
2018-09-08  5:56 ` genelocated
2018-09-08  5:58 ` genelocated

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).