This is great! Here's an alternative to the 2 lines of code in the loop:
ENV.update l.chomp.scan(/^(?:export )?(\w+)\s*=\s*(?:['"])?([^'"]+)/i).to_h
This change also handles .env files that have lines in the format of export FOO=bar.
export FOO=bar
Nice!
I will personally leave out the export stuff because I don't actually need to be compatible with dotenv, but it would be nice for people who do.
How about 3 lines or fairly readable ruby?
#!/usr/bin/env ruby regexp = /^(\w+)=['"]?(.+?)['"]?$/ ENV.update File.read(".env").scan(regexp).to_h if File.exist?(".env") exec(ENV, *ARGV)
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
This is great! Here's an alternative to the 2 lines of code in the loop:
This change also handles .env files that have lines in the format of
export FOO=bar
.Nice!
I will personally leave out the export stuff because I don't actually need to be compatible with dotenv, but it would be nice for people who do.
How about 3 lines or fairly readable ruby?