Skip to content

Instantly share code, notes, and snippets.

@markjeee
Created August 21, 2010 12:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markjeee/542217 to your computer and use it in GitHub Desktop.
Save markjeee/542217 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
require 'yaml'
ROOT_PATH = File.expand_path(File.join(File.dirname(__FILE__), '..'))
ENV_DEFAULTS = {
'ruby_path' => (r = `which ruby`.strip).empty? ? '/usr/bin/ruby' : r,
'env_path' => (r = `which env`.strip).empty? ? '/usr/bin/env' : r,
'cwd' => ROOT_PATH
}
env_config_file = File.join(ROOT_PATH, 'config/env.yml')
if File.exists?(env_config_file)
env_config = ENV_DEFAULTS.merge(YAML.load_file(env_config_file) || { })
else
env_config = ENV_DEFAULTS.merge({ })
end
env_vars = [ ]
argv = ARGV.clone.delete_if { |a| if a =~ /.+\=.+/; env_vars.push(a); true; else; false; end }
cmd = "#{env_config['env_path']} #{env_vars.join(' ')} #{env_config['ruby_path']} #{argv.join(' ')}"
#puts "Found root path at: #{ROOT_PATH}"
#puts "env_config: #{env_config.inspect}"
#puts "cmd: #{cmd}"
unless env_config['cwd'].nil?
Dir.chdir(env_config['cwd'])
end
exec(cmd)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment