From 50edc451323fb70f225dd02475d799bce17c8cac Mon Sep 17 00:00:00 2001 From: Sorin Ionescu Date: Wed, 27 Nov 2013 12:31:08 -0500 Subject: [PATCH] [Fix #503] Prefix rails aliases with 'bundle exec' --- modules/rails/init.zsh | 64 +++++++++------------------- modules/ruby/README.md | 1 + modules/ruby/functions/ruby-app-root | 19 +++++++++ 3 files changed, 39 insertions(+), 45 deletions(-) create mode 100644 modules/ruby/functions/ruby-app-root diff --git a/modules/rails/init.zsh b/modules/rails/init.zsh index 69f5b88..70f50ce 100644 --- a/modules/rails/init.zsh +++ b/modules/rails/init.zsh @@ -7,56 +7,30 @@ # Sorin Ionescu # +# Load dependencies. +pmodload 'ruby' + # Return if requirements are not found. -if (( ! $+commands[rails] )); then +if (( ! $+commands[bundle] )); then return 1 fi # -# Aliases (Compatible with Rails 2) +# Aliases # -alias ror='rails' -alias rorc='_rails-command console' -alias rordc='_rails-command dbconsole' -alias rordm='rake db:migrate' -alias rordM='rake db:migrate db:test:clone' -alias rordr='rake db:rollback' -alias rorg='_rails-command generate' -alias rorl='tail -f log/development.log' -alias rorlc='rake log:clear' -alias rorp='_rails-command plugin' -alias rorr='_rails-command runner' -alias rors='_rails-command server' -alias rorsd='_rails-command server --debugger' -alias rorx='_rails-command destroy' - -# -# Functions -# - -function _rails-command { - local root_dir="$PWD" - local rails_cmd - - while [[ "$root_dir" != '/' ]]; do - if [[ -d "$root_dir/.bundle" ]]; then - break - fi - root_dir="$root_dir:h" - done - - if [[ -e "$root_dir/bin/rails" ]]; then - rails_cmd='bin/rails' - elif [[ -e "$root_dir/script/rails" ]]; then - rails_cmd='script/rails' - elif [[ -e "$root_dir/script/server" ]]; then - rails_cmd='script/' - else - print "$0: not inside of a Rails application: $PWD" >&2 - return 1 - fi - - (cd "$root_dir" && ruby "$rails_cmd" "$@") -} +alias ror='bundle exec rails' +alias rorc='bundle exec rails console' +alias rordc='bundle exec rails dbconsole' +alias rordm='bundle exec rake db:migrate' +alias rordM='bundle exec rake db:migrate db:test:clone' +alias rordr='bundle exec rake db:rollback' +alias rorg='bundle exec rails generate' +alias rorl='tail -f "$(ruby-app-root)/log/development.log"' +alias rorlc='bundle exec rake log:clear' +alias rorp='bundle exec rails plugin' +alias rorr='bundle exec rails runner' +alias rors='bundle exec rails server' +alias rorsd='bundle exec rails server --debugger' +alias rorx='bundle exec rails destroy' diff --git a/modules/ruby/README.md b/modules/ruby/README.md index 42e63be..e78d757 100644 --- a/modules/ruby/README.md +++ b/modules/ruby/README.md @@ -59,6 +59,7 @@ Aliases Functions --------- + - `ruby-app-root` displays the path to the Ruby application root directory. - `ruby-info` exposes information about the Ruby environment via the `$ruby_info` associative array. diff --git a/modules/ruby/functions/ruby-app-root b/modules/ruby/functions/ruby-app-root new file mode 100644 index 0000000..cff8966 --- /dev/null +++ b/modules/ruby/functions/ruby-app-root @@ -0,0 +1,19 @@ +# +# Displays the path to the Ruby application root directory. +# +# Authors: +# Sorin Ionescu +# + +local root_dir="$PWD" + +while [[ "$root_dir" != '/' ]]; do + if [[ -f "$root_dir/Gemfile" ]]; then + print "$root_dir" + break + fi + root_dir="$root_dir:h" +done + +return 1 +