Skip to content

Instantly share code, notes, and snippets.

@killme2008
Last active December 15, 2015 05:39
Show Gist options
  • Save killme2008/5211094 to your computer and use it in GitHub Desktop.
Save killme2008/5211094 to your computer and use it in GitHub Desktop.
A ruby script to scan all environment variables using environ lib and print the result in bash format.Environ is a Clojure library for managing environment settings from a number of different sources.https://github.com/weavejester/environ
#!/bin/ruby
if __FILE__ == $0
vars = {}
Dir.glob("**/*") do |name|
if File.file? name and name =~ /\.clj$/
File.open(name,"r") do |f|
content = f.read
if content =~ /environ.core/
content.scan(/\(env :([a-zA-Z\-]+) ("([^\)]+)")?\)/).each do |matches|
$stderr.puts "Duplicated var #{matches[0]} in #{name}:current #{vars[matches[0]]},found:#{matches[2]}" if vars[matches[0]]
vars[matches[0]]= matches[2]
end
end
end
end
end
vars.each do |k,v|
puts "export #{k.gsub(/\-/,"_").upcase}=#{v.gsub(/\$/,"\\$")}"
end
end
@killme2008
Copy link
Author

Usage:
Enter the project directory and enter:
ruby environ.rb > env.sh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment