I wish to shorten the typing of this:
rails g controller --skip-helper --skip-assets --skip-views --skip-template-engine c6
where c6
is the controller name.
I'd like to be able to type railsgbc c6
# note: gbc=generate basic controller
I've tried:
$ alias railsgc='rails g controller --skip-helper --skip-assets --skip-views --skip-template-engine'
but then when I try to use it I get:
$ railsgc play5
No value provided for required arguments 'name'
which is actually the same as if I type:
$ rails g controller --skip-helper --skip-assets --skip-views --skip-template-engine c6
No value provided for required arguments 'name'
so it seems that I can't put the argument at the end, it needs to be right after controller
...
It is not possible to create an alias supporting a parameter. What you can do is to create a function. Adding it to ~/.bashrc
will make it.
For example, to make backups:
f_bk () {
cp -p $1 $1.$(date "+%Y%m%d")
}
In your case, if you want to add something after the last word, then this could make it:
myrails () {
rails g controller --skip-helper --skip-assets --skip-views --skip-template-engine $1
}
And call it for example with:
myrails c8
Note that $1
will be the first parameter, $2
the second and so on.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.