Create useful aliases for Rails development

Ruby on Rails / Development

Sometimes typing long commands very often is quite annoying. There is a very simple solution for this. You can create an alias for given command which means that you can type your own command which would trigger another command.

Let’s say that every time you want to run your test suite you have to execute following code:

bundle exec rspec spec/models spec/controllers spec/helpers --format documentation

it will be a lot faster and easier to run tests by typing just this command:

run_tests

Creating an alias

Create a new file, name it rails_aliases.sh and put the following command there:

alias run_tests='bundle exec rspec spec/models spec/controllers spec/helpers --format documentation'

Reload file in your console:

source rails_aliases.sh

and you can run tests using your new and shorter command.

Of course, you may not want to create such file in main project directory because of other team members or any other reason. Instead of creating a new file you can edit your ~/.bashrc file and put all aliases there.