1
0
mirror of https://github.com/dcarrillo/prezto.git synced 2024-12-22 13:58:00 +00:00

[Fix #503] Prefix rails aliases with 'bundle exec'

This commit is contained in:
Sorin Ionescu 2013-11-27 12:31:08 -05:00
parent b1abe7a845
commit 50edc45132
3 changed files with 39 additions and 45 deletions

View File

@ -7,56 +7,30 @@
# Sorin Ionescu <sorin.ionescu@gmail.com> # Sorin Ionescu <sorin.ionescu@gmail.com>
# #
# Load dependencies.
pmodload 'ruby'
# Return if requirements are not found. # Return if requirements are not found.
if (( ! $+commands[rails] )); then if (( ! $+commands[bundle] )); then
return 1 return 1
fi fi
# #
# Aliases (Compatible with Rails 2) # Aliases
# #
alias ror='rails' alias ror='bundle exec rails'
alias rorc='_rails-command console' alias rorc='bundle exec rails console'
alias rordc='_rails-command dbconsole' alias rordc='bundle exec rails dbconsole'
alias rordm='rake db:migrate' alias rordm='bundle exec rake db:migrate'
alias rordM='rake db:migrate db:test:clone' alias rordM='bundle exec rake db:migrate db:test:clone'
alias rordr='rake db:rollback' alias rordr='bundle exec rake db:rollback'
alias rorg='_rails-command generate' alias rorg='bundle exec rails generate'
alias rorl='tail -f log/development.log' alias rorl='tail -f "$(ruby-app-root)/log/development.log"'
alias rorlc='rake log:clear' alias rorlc='bundle exec rake log:clear'
alias rorp='_rails-command plugin' alias rorp='bundle exec rails plugin'
alias rorr='_rails-command runner' alias rorr='bundle exec rails runner'
alias rors='_rails-command server' alias rors='bundle exec rails server'
alias rorsd='_rails-command server --debugger' alias rorsd='bundle exec rails server --debugger'
alias rorx='_rails-command destroy' alias rorx='bundle exec rails 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" "$@")
}

View File

@ -59,6 +59,7 @@ Aliases
Functions 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` exposes information about the Ruby environment via the
`$ruby_info` associative array. `$ruby_info` associative array.

View File

@ -0,0 +1,19 @@
#
# Displays the path to the Ruby application root directory.
#
# Authors:
# Sorin Ionescu <sorin.ionescu@gmail.com>
#
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