+4

Using zsh shell for Rails application

It's a pleasure to use zsh for last several months and being quite impressed about its efficiency. I specially use zsh for my rails development. In this post how it can be used for rails development will be discussed.

For basic information like what is zsh, how to install etc. this post will be very helpful.

Required Plugins for Rails Development

First we need to make sure to have rails, git, ruby and bundler plugins are installed, so that we can use them in shell. To install them we need to change the hidden file ~/.zshrc (it's normally in home directory in ubuntu). Open the hidden file ~/.zshrc and edit the plugins line it like this:

Selection_003.png

Choosing Theme

More than 140 themes are available for zsh shell. We can choose from them from here. This page shows the preview of every themes available.

For example I found this theme user friendly. Its name Honukai. Theme Preview:

Selection_004.png


To install it again we need to edit in the ~/.zshrc file `ZSH_THEME` line like this:

Selection_006.png

Aliases in Rails development

Using alias is one of the main purposes for using zsh. It makes our command very short which increase efficiency.

For example:

  • to open rails server the command is rs
  • rails console: rc
  • to generate model user rg model User, for controller rg controller users

Rake commands

  • to create db: rdc
  • migrate: rdm
  • drop: rdd
  • see routes: rr

For Bundler

  • for bundle install: bi
  • bundle update: bu

Here the complete set of rails and rake command aliases:

Rails aliases

Selection_008.png


Rake aliases

Selection_009.png


Git Aliases

A version controlling system like Git is used almost all kind of development works. Zsh provides a great amount of git aliases which makes the programmer job much easier. As the developer need to use it frequently long git command can be annoying. Think of a git command those are replaced like this:

  • git push origin $(current_branch) with this ggpush $(current_branch)
  • git pull repository_name brach_name with gl repo_name branch_name
  • git status with gst
  • git checkout $(branch) with gco $(branch)
  • git reset HEAD --hard with grhh

Here is complete set git aliases for zsh. Some sample given below:

Selection_007.png


I hope this post will help you for your rails development. This [link](https://github.com/robbyrussell/oh-my-zsh/wiki/Plugins) will be helpful for other development purposes. Thanks for reading.

All rights reserved

Viblo
Hãy đăng ký một tài khoản Viblo để nhận được nhiều bài viết thú vị hơn.
Đăng kí