I know you already have a solution in ruby, but here's one written in bash, which should be a bit faster.
Assuming you're using Bundler:
grep 'rails' 'Gemfile' >/dev/null 2>&1
if [ $? -eq 0 ]; then
echo "It's a Rails project!"
fi
This is what that snippet does:
- Grep the Gemfile in the current directory for 'rails'. Discard grep's output.
- If grep exits with exit code 0, you're in a Rails project
grep 'rails' 'Gemfile'
will return a status code of 2 if a file named 'Gemfile' doesn't exist in the current directory. grep
will return a status code of 1 if the found a 'Gemfile' but it doesn't contain 'rails'.
For Rails 2 without Bundler this should work:
if [ -f script/rails ]; then
echo "It's a Rails 2 project!"
fi
All that does is test if the script/rails file exists.
I hope this helps someone who's hoping to do it bash instead of ruby.