postmodern / chruby

Changes the current Ruby
MIT License
2.86k stars 190 forks source link

It would be nice to call chruby_auto without enabling auto-switching #310

Closed DavidEGrayson closed 9 years ago

DavidEGrayson commented 9 years ago

Today I changed a project from using RVM to using chruby. I had to replace the following line in a shell script:

rvm rvmrc load

with this line:

chruby $(cat ../.ruby-version)

The unpleasant thing about this is that I had to hardcode the path to the .ruby-version file, so the shell script will be more likely to break in the future, and if it gets copied to a different directory then that line would have to be modified.

Really what I would like to do is call some chruby function that searches up the directory tree for a .ruby-version file and then uses it. That's what the chruby_auto function does. I would suggest that the chruby_auto function should be moved from auto.sh to chruby.sh so it can be called without forcing the user to enable the auto-switching feature.

It would be even better if there were a function available in chruby.sh that was like chruby_auto but also emitted an error if it fails to find the .ruby-version file and switch rubies.

postmodern commented 9 years ago

It's already noted in the README that auto.sh and chruby.sh are separate for those that do not want/need auto-switching.

If you're already requiring chruby and need auto-switching, then simply require that the user enables it? OTOH, chruby's auto-switching is designed to be unobtrusive and just work everywhere; provided it's loaded into the shell. Instead of explicitly calling chruby_auto, why not just use a .ruby-version file and allow the user's preferred Ruby Switcher to detect it?

DavidEGrayson commented 9 years ago

I didn't want true auto-switching to be enabled because it would automatically make changes to the environment and it would likely be incompatible with other Ruby switchers. Still, I wanted to be able to run a command that is equivalent to "rvm rvmrc load" in my scripts when I need it.

pdg137 commented 9 years ago

I second David's suggestion. There are lots of times you wouldn't want to load auto.sh but still want to do a one-time load of an environment specified by .ruby-version. For example, on a production server, having that trap running after every Bash command might be too much of a risk.