zsh-users
 help / color / mirror / code / Atom feed
* Alias command /and/ flags
@ 2016-11-22 18:31 Yuri D'Elia
  2016-11-22 21:11 ` Bart Schaefer
  0 siblings, 1 reply; 3+ messages in thread
From: Yuri D'Elia @ 2016-11-22 18:31 UTC (permalink / raw)
  To: zsh-users

Let's imagine I want to alias the specific invocation of "cmd flag" with
"cmd2 flag2". Is it possible to alias commands with arguments (that is,
only in command position and *not* global replacements)?

I'm of course looking for an *exact* match of the positional parameters,
no more.

I can think of a way by defining a "cmd" function and do the checking on
the arguments myself, which is definitely more generalizable, although
seems a bit overkill for a simple scenario I had in mind.

Any reason:

  alias "cmd flag"="cmd2 flag2"

shouldn't work at least in principle?


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

* Re: Alias command /and/ flags
  2016-11-22 18:31 Alias command /and/ flags Yuri D'Elia
@ 2016-11-22 21:11 ` Bart Schaefer
  2016-11-23 10:12   ` Yuri D'Elia
  0 siblings, 1 reply; 3+ messages in thread
From: Bart Schaefer @ 2016-11-22 21:11 UTC (permalink / raw)
  To: Zsh Users; +Cc: Yuri D'Elia

On Tue, Nov 22, 2016 at 10:31 AM, Yuri D'Elia <wavexx@thregr.org> wrote:
>
> Any reason:
>
>   alias "cmd flag"="cmd2 flag2"
>
> shouldn't work at least in principle?

Sorry, no.  Aliases (even "alias -g" global ones) operate on shell
syntax words, which in the most straightforward case means strings of
non-whitespace separated by whitespace.  You can't create an alias for
something that has any word-delimiting space in the middle of it.

> I can think of a way by defining a "cmd" function and do the checking on
> the arguments myself

This is probably going to be the simplest option that will cover your
requirements.  There are also various ways to attack this through
custom ZLE widgets but that would get even more esoteric.


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

* Re: Alias command /and/ flags
  2016-11-22 21:11 ` Bart Schaefer
@ 2016-11-23 10:12   ` Yuri D'Elia
  0 siblings, 0 replies; 3+ messages in thread
From: Yuri D'Elia @ 2016-11-23 10:12 UTC (permalink / raw)
  To: zsh-users

On Tue, Nov 22 2016, Bart Schaefer wrote:
>> I can think of a way by defining a "cmd" function and do the checking on
>> the arguments myself
>
> This is probably going to be the simplest option that will cover your
> requirements.  There are also various ways to attack this through
> custom ZLE widgets but that would get even more esoteric.

The function approach is fine for me, it was mostly a curiosity.



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

end of thread, other threads:[~2016-11-23 10:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-11-22 18:31 Alias command /and/ flags Yuri D'Elia
2016-11-22 21:11 ` Bart Schaefer
2016-11-23 10:12   ` Yuri D'Elia

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