Skip to content

lewstherin/rails_completion

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Rails completion

Bash completion support for Ruby on Rails.

The completion routines provide support for completing:

  • rails commands (e.g.: new, server, console, generate, runner, ...)
  • rails generators (e.g.: scaffold, controller, mailer, observer, ...)
  • rails environments
  • rails field's types on generators (e.g.: scaffold, model, migration, ...)
  • common --long-options

Installation

Two-step installation:

  1. Copy the rails.bash file to somewhere (e.g. ~/.rails.bash).

  2. Add the following line to your .bashrc:

    source ~/.rails.bash

Alternatively, on Debian systems, you can just copy the rails.bash file to /etc/bash_completion.d/ directory.

Requirements

  • Rails 4: Though the completions work in Rails 3 app folders also, the options are 4.0.x specific only. Initially I had planned to support both Rails 3 CLI options and Rails 4.0.x but the code was becoming way too messy and the added benefit was miniscule.
  • bash_completion 1.99+ is what I have tested it on. Should work on 1.1+

Current version of bash_completion supports all command-line options available in Rails 4.0.x, if you want to use it with:

Basic Usage

Typical usage is to change into a rails application and get some work.

For example, using rails console is something like:

$ cd rails_app
$ rails c<Tab><Tab>
c console
$ rails c <Tab><Tab>
--debugger   development  production   -s           --sandbox    test
$ rails c p<Tab>
$ rails c production

Choosing the server's environment:

$ rails server -e<Tab><Tab>
-edevelopment  -eproduction   -etest
$ rails server -ep<Tab><Tab>
$ rails server -eproduction

Playing with generators

The generators available for completion are not hard-coded. The rails.bash script lookup for generators in your Rails application. In this way, generators provided by thrid-party plugins declared in your Gemfile also will be available for completion. Moreover, for the sake of performance, the rails.bash script saves the list of generators available in a cache file, named .rails_generators~. But, if the Gemfile file is modified the cache file will be updated on next completion event.

In the following example, I use the 'devise' plugin on Gemfile:

$ rails g <Tab><Tab>
active_record:devise  generator             model                 resource
controller            helper                mongoid:devise        scaffold
devise                integration_test      observer              scaffold_controller
devise:install        mailer                performance_test      session_migration
devise:views          migration             plugin                stylesheets

In some generators (scaffold, model, resource and migration), you can declare fields to be generated using the syntax field:type. The rails.bash script also provides support for field's type completion. For this, just type the field name followed by a colon (:) and hit <Tab><Tab>:

$ rails g model Blog title:<Tab><Tab>
title:binary     title:datetime   title:integer    title:time
title:boolean    title:decimal    title:string     title:timestamp
title:date       title:float      title:text
$ rails g model Blog title:s<Tab>
$ rails g model Blog title:string
...

For more details, use it and have fun!

Bugs and Feedback

If you discover any bugs or have some idea, feel free to create an issue on GitHub:

https://github.com/jweslley/rails_completion/issues

License

Copyright (c) 2011 Jonhnny Weslley

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License, version 3, as published by the Free Software Foundation.

About

Bash completion support for Ruby on Rails.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Shell 100.0%