0

Hello I'm trying to make an alias in zsh for the following command:

gcloud compute instances delete CONTAINER_NAME --zone=x --quiet

How can I make an alias that would fit my parameter in the CONTAINER_NAME ?

Monterey 12.2

2
  • 1
    Might be better to define a shell function for this.
    – nohillside
    Mar 14, 2022 at 7:11
  • 2
    You don't. An alias does not take parameters. Mar 14, 2022 at 8:12

2 Answers 2

1

zsh supports functions, so you can put the following into the appropriate startup file

function gcloud_delete() {
    gcloud compute instances delete "$1" --zone=x --quiet
}

and then (after sourcing that file) run

gcloud_delete CONTAINER
0

Have a look at oh-my-zsh project.

You have a plugin called aliases. With it, you're able to define aliases using arguments.

To edit the aliases file: code ~/.oh-my-zsh/custom/plugins/aliases/aliases.plugin.zsh

In that file you can create an alias like this:

gcInstanceDelete="gcloud compute instances delete $1 --zone=x --quiet"

And call the alias with:
gcInstanceDelete CONTAINER_NAME

1
  • How do you find documentation on that plugin. ie a URL so that you can see what it does before installing.
    – mmmmmm
    Jul 14, 2022 at 14:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .