Last active
December 15, 2015 05:39
-
-
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
This file contains hidden or 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
#!/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 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage:
Enter the project directory and enter:
ruby environ.rb > env.sh