Closed tomeon closed 6 years ago
Note that we cannot use associated arrays, as they are a Bash 4 feature and OSX still ships Bash 3. Perhaps a better way would be to store the switching history as the arguments passed to chruby
in a regular indexed Array?
I like the idea of undoing changes, but we lack a good way of display the change history. How far back should we track chruby switches? Also, is this feature really needed or will it add more cognitive overhead to the user?
The Vagrant changes should be a separate PR. I'm open to replacing Vagrant with schroot or shudder even Docker.
This PR alters how
chruby
handles environment variables in order to make sure thatchruby_reset
undoes only those changes thatchruby
itself has made. Right now, whenchruby
cleans up after itself, it does a pretty thorough reaving ofPATH
,GEM_HOME
, etc., which can lead to situations like this:I.e.,
chruby_reset
scrubs all occurrences of/usr/bin
fromPATH
, not just those added inchruby_use
.The code added in this PR caches the pre-
chruby_use
state of various environment variables, along with other values that represent the changes made bychruby_use
. These values are used withinchruby_reset
toPATH
orGEM_HOME
) have occurred sincechruby_use
was last invoked, andIf
chruby
can't be sure that its cleanup logic will restore the shell environment to its earlier state, it will print a warning to that effect and fall back to default cleanup logic.Because this PR violates the contributors' guide's prohibition on new environment variables, I will also open a PR for an alternate implementation that uses a function rather than the
CHRUBY_CACHE
global associative array as the oracle for assessing the correctness of the shell environment.However, the function-based approach is not as reliable as the approach taken here: less state is maintained between
chruby_use
andchruby_reset
, so the cleanup logic has to do some guesswork about the preexisting shell environment that isn't necessary when the relevant attributes of that previous environment are maintained inCHRUBY_CACHE
.I also think that
CHRUBY_CACHE
represents minimal environment pollution -- for instance, it won't show up inenv
/printenv
nor be inherited by any non-bash/zsh child processes. Maybe it is okay to make an exception in this case?Also included in this PR:
travis-ruby
Docker machine, andtest/opt/rubies
in case the rvm download failed. Because the Makefile only runs the setup script if thetest/opt/rubies
target doesn't exist, an extant-but-empty directory doesn't trigger a build failure -- instead, thetest
target fails somewhere downstream when the absence of the test Ruby installation causeschruby
to carp about anunknown Ruby
.