Skip to content

Instantly share code, notes, and snippets.

@jennings
Last active January 28, 2018 04:50
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 jennings/7a4d720836dc8861c99145abd01d5364 to your computer and use it in GitHub Desktop.
Save jennings/7a4d720836dc8861c99145abd01d5364 to your computer and use it in GitHub Desktop.
Executes a command after adding a `.env` file to the environment. This is probably terribly unsafe.
#!/usr/bin/env ruby
# usage: dotenv irb
begin
File.foreach('.env') do |line|
line = line.strip
unless line.start_with?('#')
parts = line.split '=', 2
if parts.length == 2
ENV[parts[0]] = parts[1]
end
end
end
rescue Exception => err
STDERR.puts err
end
exec(*ARGF.argv)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment