postmodern / chruby

Changes the current Ruby
MIT License
2.88k stars 189 forks source link

Don't override RUBIES #252

Open sirupsen opened 10 years ago

sirupsen commented 10 years ago

If RUBIES is already set, is it intentional we are overriding it?

sirupsen commented 10 years ago

This is an issue e.g. if you source chruby twice, but only set RUBIES before sourcing it the first time.

postmodern commented 10 years ago

This is a good question. Since RUBIES is an Array variable it cannot be exported, so it will never be passed to a sub-shell.

sirupsen commented 10 years ago

Is there any way to prevent that from happening?

postmodern commented 10 years ago

@Sirupsen I don't think we could easily pass RUBIES between shells. We could however add a simple empty check, in case chruby is loaded twice or the user defines RUBIES before hand.

sirupsen commented 10 years ago

That sounds great.

postmodern commented 10 years ago

Should we still auto-populate RUBIES with /opt/rubies/* or ~/.rubies/*, or should we assume the user has explicitly set RUBIES.

sirupsen commented 10 years ago

I'm not entirely familiar with how bash works in this case, but to me the expected behaviour would be that chruby made sure /opt/rubies/* and ~/rubies/* is always in RUBIES. But however many times you source chruby afterwards (say you source it in /etc/profile.d/chruby.sh and a user on the system sources it too when importing his dotfiles), these will still be in RUBIES, in addition to whatever has been appended to RUBIES in /etc/profile.d/* or ~/.bashrc.

booch commented 10 years ago

Since RUBIES is only used in the chruby function, we could leave it unset at the global level, and have the chruby function copy it to another variable if it's set, or set that other variable to the default otherwise.