Skip to content

Instantly share code, notes, and snippets.

@exchgr
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save exchgr/ed0d8c575b494ca89821 to your computer and use it in GitHub Desktop.
Save exchgr/ed0d8c575b494ca89821 to your computer and use it in GitHub Desktop.
Fix `~/.irbrc` and `./Gemfile.dev` in `spring`
# 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