0

I'm trying to create this alias:

alias mrc="php artisan make:controller $(user_input) --resource"

so that I can just type mrc ControllerName in the terminal to produce:

php artisan make:controller ControllerName --resource

Is there a way to do that?

1 Answer 1

5

From what I found, it is easier to use a shell function. You can simply define a function where $1 refers to the first argument given:

function mrc() { php artisan make:controller "$1" --resource; }

You possibly want to put this in your ~/.zshrc so you don't have to run this every time you open a new terminal.

If the command should be available in a child shell you also want to use:

export -f mrc

Now you should be able to type mrc controllerName and get the desired output.

For reference (as suggested by nohillside) : Make a Bash alias that takes a parameter? There you can find both a single and multi-line example of declaring a shell function.

2
  • If there is any problem with this way of doing it, I'd be happy to find another way and/or resolve the issue.
    – Guchen
    May 13 at 7:14
  • 1
    @Guchen &nohillside Thank you both. The function works without exporting it. May 13 at 7:48

You must log in to answer this question.

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