chruby icon indicating copy to clipboard operation
chruby copied to clipboard

Don't override RUBIES

Open sirupsen opened this issue 10 years ago • 8 comments

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

sirupsen avatar Feb 20 '14 18:02 sirupsen

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

sirupsen avatar Feb 20 '14 19:02 sirupsen

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.

postmodern avatar Feb 21 '14 01:02 postmodern

Is there any way to prevent that from happening?

sirupsen avatar Feb 21 '14 03:02 sirupsen

@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.

postmodern avatar Feb 21 '14 03:02 postmodern

That sounds great.

sirupsen avatar Feb 21 '14 03:02 sirupsen

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

postmodern avatar Feb 21 '14 04:02 postmodern

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.

sirupsen avatar Feb 21 '14 13:02 sirupsen

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.

booch avatar May 25 '14 03:05 booch