I love git and git auto complete bash shell. I get so used to it that I type TAB TAB key even for cap and rake command. I’ve been frustrated so many times to not have auto complete for those commands, so I spent a few time on reading git code and google for it.

And here is my result, a little script to add to your .bashrc and you will have rake and cap completion! And mix of what I read on different code/articles.

My code is available on github: rake_cap_bash_autocomplete You do not need to download the repository, just copy sheel file and check README for installation.

  1. Copy rake_cap_bash_autocomplete.sh to somewhere (e.g. ~/.rake_cap_bash_autocomplete.sh).
  2. Added the following line to your .bashrc: source ~/.rake_cap_bash_autocomplete.sh

Then, if you test it in an empty rails directory for instance, you will have:


$ rake TAB TAB
db:abort_if_pending_migrations  db:schema:dump                  doc:plugins                     rails:freeze:edge               test:recent
db:charset                      db:schema:load                  doc:rails                       rails:freeze:gems               test:uncommitted
db:collation                    db:sessions:clear               doc:reapp                       rails:unfreeze                  test:units
db:create                       db:sessions:create              doc:rerails                     rails:update                    time:zones:all
db:create:all                   db:structure:dump               gems                            rails:update:configs            time:zones:local
db:drop                         db:test:clone                   gems:build                      rails:update:javascripts        time:zones:us
db:drop:all                     db:test:clone_structure         gems:install                    rails:update:scripts            tmp:cache:clear
db:fixtures:identify            db:test:load                    gems:refresh_specs              routes                          tmp:clear
db:fixtures:load                db:test:prepare                 gems:unpack                     secret                          tmp:create
db:migrate                      db:test:purge                   gems:unpack:dependencies        stats                           tmp:pids:clear
db:migrate:down                 db:version                      log:clear                       test                            tmp:sessions:clear
db:migrate:redo                 doc:app                         notes                           test:benchmark                  tmp:sockets:clear
db:migrate:reset                doc:clobber_app                 notes:custom                    test:functionals                
db:migrate:up                   doc:clobber_plugins             notes:fixme                     test:integration                
db:reset                        doc:clobber_rails               notes:optimize                  test:plugins                    
db:rollback                     doc:guides                      notes:todo                      test:profile                    

And when you begin to enter a task command:

$ rake test: TAB TAB
test:benchmark    test:functionals  test:integration  test:plugins      test:profile      test:recent       test:uncommitted  test:units        

If you have more than 128 commands, you will see
$ rake TAB TAB
Display all 128 possibilities? (y or n)

Same for cap

Enjoy!

A pastis for pastie

September 30th, 2007

If you use pastie service to share code (or may be you are already addicted to it), Samuel Lebeau has released a perfect ruby gems to pastie anything in one command line.

It’s called pastis (if you are French you know what a Pastis:”http://en.wikipedia.org/wiki/Pastis” is :), it’s a great alcohol from south of France).

You can get details on his blog.

The best is you can add a command on TextMate to pastie selected text. When you workk remotely and you want to share code with co-workers it’s a great time saver.

Here is the command taken from his article:

   1  
   2  #!/usr/bin/env ruby
   3  require 'rubygems'
   4  require 'pastis'
   5  
   6  input = ENV['TM_SELECTED_TEXT'] || File.read(ENV['TM_FILEPATH'])
   7  
   8  languages = {
   9    /source\.ruby/ => :ruby,
  10    /text\.html\.basic/ => :html,
  11    /text\.html\.ruby/ => :rhtml,
  12    /source\.js/ => :javascript,
  13    /source\.(c|c\+\+)/ => :c,
  14    /source\.sql/ => :sql,
  15    /source\.diff/ => :diff
  16  }
  17  
  18  language = languages[languages.keys.find { |pattern| ENV['TM_SCOPE'] =~ pattern }] || :plaintext
  19  
  20  paste = Pastis.paste(input, :language => language)
  21  
  22  `open #{paste.url}`
  23