-
-
Save benpickles/261940 to your computer and use it in GitHub Desktop.
Framework-aware console/server/database scripts.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'pathname' | |
require 'yaml' | |
conf = Pathname.new(Dir.pwd).join('config', 'database.yml') | |
if conf.exist? | |
env = ARGV.first || ENV['RAILS_ENV'] || 'development' | |
yaml = YAML.load(conf.read) | |
config = yaml[env] || yaml[env.to_sym] | |
database = config['database'] || config[:database] | |
username = config['username'] || config[:username] | |
password = config['password'] || config[:password] | |
cmd = "mysql -u#{username} " | |
cmd << "-p#{password} " if password | |
cmd << database | |
puts "Opening database #{database}" | |
exec cmd | |
end | |
puts "Couldn't detect database" | |
exit 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'pathname' | |
pwd = Pathname.new(Dir.pwd) | |
bin = if pwd.join('script', 'rails').exist? | |
'./script/rails console' | |
elsif pwd.join('script', 'console').exist? | |
'./script/console' | |
elsif pwd.join('schema', 'schema.rb').exist? | |
'merb -i' | |
elsif pwd.join('config.ru').exist? | |
if `which racksh`.chomp == '' | |
puts 'Use racksh to a console to any Rack app:' | |
puts ' gem install racksh --source http://gemcutter.org' | |
exit | |
else | |
'racksh' | |
end | |
else | |
puts "Couldn't detect framework" | |
exit 1 | |
end | |
bin = "bundle exec #{bin}" if pwd.join('Gemfile').exist? | |
command = "#{bin} #{ARGV.join(' ')}" | |
puts command | |
exec command |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'pathname' | |
pwd = Pathname.new(Dir.pwd) | |
bin = if pwd.join('script', 'rails').exist? | |
'./script/rails server' | |
elsif pwd.join('script', 'server').exist? | |
'./script/server' | |
elsif pwd.join('config.ru').exist? | |
'rackup -p 3000' | |
elsif pwd.join('schema', 'schema.rb').exist? | |
'merb' | |
else | |
if `which thin`.chomp == '' | |
puts 'Use Thin to quickly serve static files:' | |
puts ' gem install thin' | |
exit 1 | |
else | |
puts 'No framework detected, using Thin to quickly serve static files.' | |
'thin start -A file -p 8080' | |
end | |
end | |
bin = "bundle exec #{bin}" if pwd.join('Gemfile').exist? | |
command = "#{bin} #{ARGV.join(' ')}" | |
puts command | |
exec command |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment