Last active
August 29, 2015 14:13
-
-
Save exchgr/ed0d8c575b494ca89821 to your computer and use it in GitHub Desktop.
Fix `~/.irbrc` and `./Gemfile.dev` in `spring`
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
# Read in the bash environment, after an optional command. | |
# Returns Array of key/value pairs. | |
def bash_env(cmd=nil) | |
env = `#{cmd + ';' if cmd} printenv` | |
env.split(/\n/).map {|l| l.split(/=/)} | |
end | |
# Source a given file, and compare environment before and after. | |
# Returns Hash of any keys that have changed. | |
def bash_source(file) | |
Hash[ bash_env(". #{File.realpath file}") - bash_env() ] | |
end | |
# Find variables changed as a result of sourcing the given file, | |
# and update in ENV. | |
def source_env_from(file) | |
bash_source(file).each {|k,v| ENV[k] = v } | |
end | |
source_env_from("#{`pwd`.chomp}/.rbenv-vars") if ENV['BUNDLE_GEMFILE'].nil? | |
irbrc = "~/.irbrc" | |
require File.expand_path(irbrc) if File.exist?(irbrc) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment