Rewrite _rails-command to work from app subdirectories

This commit is contained in:
Sorin Ionescu 2013-11-25 16:11:08 -05:00
parent cc4a58bee3
commit 5cfe250e52
1 changed files with 20 additions and 5 deletions

View File

@ -36,12 +36,27 @@ alias rorx='_rails-command destroy'
#
function _rails-command {
if [[ -e "script/server" ]]; then
ruby script/"$@"
elif [[ -e "bin/rails" ]]; then
ruby bin/rails "$@"
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
ruby script/rails "$@"
print "$0: not inside of a Rails application: $PWD" >&2
return 1
fi
(cd "$root_dir" && ruby "$rails_cmd" "$@")
}