Rewrite _rails-command to work from app subdirectories
This commit is contained in:
parent
cc4a58bee3
commit
5cfe250e52
|
@ -36,12 +36,27 @@ alias rorx='_rails-command destroy'
|
||||||
#
|
#
|
||||||
|
|
||||||
function _rails-command {
|
function _rails-command {
|
||||||
if [[ -e "script/server" ]]; then
|
local root_dir="$PWD"
|
||||||
ruby script/"$@"
|
local rails_cmd
|
||||||
elif [[ -e "bin/rails" ]]; then
|
|
||||||
ruby bin/rails "$@"
|
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
|
else
|
||||||
ruby script/rails "$@"
|
print "$0: not inside of a Rails application: $PWD" >&2
|
||||||
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
(cd "$root_dir" && ruby "$rails_cmd" "$@")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue