summaryrefslogtreecommitdiff
path: root/lib/importenv.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/importenv.rb')
-rw-r--r--lib/importenv.rb29
1 files changed, 29 insertions, 0 deletions
diff --git a/lib/importenv.rb b/lib/importenv.rb
new file mode 100644
index 0000000..4125376
--- /dev/null
+++ b/lib/importenv.rb
@@ -0,0 +1,29 @@
+# importenv.rb -- imports environment variables as global variables
+#
+# Usage:
+#
+# require 'importenv'
+# p $USER
+# $USER = "matz"
+# p ENV["USER"]
+
+for k,v in ENV
+ next unless /^[a-zA-Z][_a-zA-Z0-9]*/ =~ k
+ eval <<EOS
+ $#{k} = %q!#{v}!
+ trace_var "$#{k}", proc{|v|
+ ENV[%q!#{k}!] = v;
+ $#{k} = %q!#{v}!
+ if v == nil
+ untrace_var "$#{k}"
+ end
+ }
+EOS
+end
+
+p $TERM
+$TERM = nil
+p $TERM
+p ENV["TERM"]
+$TERM = "foo"
+p ENV["TERM"]