zsh-users
 help / color / mirror / Atom feed
* Make a function name an alias for another function
@ 2021-09-04 16:21 Eric Smith
  2021-09-04 16:24 ` Roman Perepelitsa
  0 siblings, 1 reply; 4+ messages in thread
From: Eric Smith @ 2021-09-04 16:21 UTC (permalink / raw)
  To: zsh-users

Hey zsh-ers,

I would like to have a function defined in one place.

POST()    {curl --silent -X $0 -H "Content-Type: application/json"  http://admin:3/api/$@ | jq '.'}
GET()     {curl --silent -X $0 -H "Content-Type: application/json"  http://admin:3/api/$@ | jq '.'}
DELETE()  {curl --silent -X $0 -H "Content-Type: application/json"  http://admin:3/api/$@ | jq '.'}

Not three like this.
How can I make like
POST() = GET()
Then I can call GET() and it will run the same function but return of cause an alternate $0

Thanks for any tips.

Best wishes
Eric


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

* Re: Make a function name an alias for another function
  2021-09-04 16:21 Make a function name an alias for another function Eric Smith
@ 2021-09-04 16:24 ` Roman Perepelitsa
  2021-09-05  5:00   ` Make a function name an alias for another function [SOLVED] Eric Smith
  0 siblings, 1 reply; 4+ messages in thread
From: Roman Perepelitsa @ 2021-09-04 16:24 UTC (permalink / raw)
  To: Eric Smith; +Cc: Zsh Users

On Sat, Sep 4, 2021 at 6:22 PM Eric Smith <es@fruitcom.com> wrote:
>
> How can I make like
> POST() = GET()
> Then I can call GET() and it will run the same function but return of cause an alternate $0

Like this:

    POST GET DELETE() { cur --silent -X "$0" ... }

Roman.


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

* Re: Make a function name an alias for another function [SOLVED]
  2021-09-04 16:24 ` Roman Perepelitsa
@ 2021-09-05  5:00   ` Eric Smith
  2021-09-05 19:01     ` Bart Schaefer
  0 siblings, 1 reply; 4+ messages in thread
From: Eric Smith @ 2021-09-05  5:00 UTC (permalink / raw)
  To: zsh-users


Masterful!

$  vim .zshrc;source .zshrc
$  POST user/using/9
{
  "message": "Active organization changed"
}
$  GET org
{
  "id": 9,
  "name": "oxxxxxxxxxxxxxxonmail.com",
}

Roman Perepelitsa previously_wrote on Sat-04-Sep 21  6:24PM
> On Sat, Sep 4, 2021 at 6:22 PM Eric Smith <es@fruitcom.com> wrote:
> >
> > How can I make like
> > POST() = GET()
> > Then I can call GET() and it will run the same function but return of cause an alternate $0
> 
> Like this:
> 
>     POST GET DELETE() { cur --silent -X "$0" ... }
> 
> Roman.
> 


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

* Re: Make a function name an alias for another function [SOLVED]
  2021-09-05  5:00   ` Make a function name an alias for another function [SOLVED] Eric Smith
@ 2021-09-05 19:01     ` Bart Schaefer
  0 siblings, 0 replies; 4+ messages in thread
From: Bart Schaefer @ 2021-09-05 19:01 UTC (permalink / raw)
  To: Eric Smith; +Cc: Zsh Users

On Sat, Sep 4, 2021 at 10:00 PM Eric Smith <es@trustfood.org> wrote:
>
> Masterful!
>
> $  POST user/using/9

Just a word of caution ... if you have perl LWP::UserAgent installed,
it will also add perl scripts named HEAD GET POST etc. to your path.


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

end of thread, other threads:[~2021-09-05 19:02 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-04 16:21 Make a function name an alias for another function Eric Smith
2021-09-04 16:24 ` Roman Perepelitsa
2021-09-05  5:00   ` Make a function name an alias for another function [SOLVED] Eric Smith
2021-09-05 19:01     ` Bart Schaefer

zsh-users

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://inbox.vuxu.org/zsh-users

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 zsh-users zsh-users/ https://inbox.vuxu.org/zsh-users \
		zsh-users@zsh.org
	public-inbox-index zsh-users

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.vuxu.org/vuxu.archive.zsh.users


code repositories for the project(s) associated with this inbox:

	https://git.vuxu.org/mirror/zsh/

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git