If no RUBY specified for chruby-exec, fall back to .ruby-version file #126
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Great project; thank you so much for maintaining it. Our dev team drove ops insane (well, more insane) by sledgehammering the environment first with RVM, then rbenv. We'd finally caught a breath of uncluttered air with rbfu when it was discontinued in favor of chruby - but that was a welcome change, since we were about to fork rbfu to fix some issues which you've handled even more cleanly.
One thing we do miss about rbfu, however, is the ability for the execution wrapper (
chruby-exec
, in this case) to use a .ruby-version file when no RUBY is specified on the command line. Our thin init scripts did something like this:...and with chruby, that became a bit of a quandary. Sourcing the auto.sh script doesn't work for the exact command above even in a login shell, since the PROMPT_COMMAND obviously won't re-execute after the
&&
- that said, we'd like to avoid the requirement for auto-switching for our deployment user accounts anyway.With chruby-exec, we'd have to do this:
...which, while doable, requires us to source the .ruby-version file in the deployment script, or have duplication of version specification. Therefore, I forked so we could follow our current convention, and figured you might at least want to take a look. Now we can do the following, as long as there's a .ruby-version file in $APPDIR:
I don't know if this goes against your design principles, or if there should at least be a configurable option to allow/disallow hunting for a .ruby-version file using
chruby-exec
, but I figured since it was something we were using extensively with rbfu (a similarly barebones approach to the problem), it might come in handy for other chruby users as well.I'm not an experienced shell programmer, so I may have made some obvious mistakes, but hopefully it's at least close. I thought about DRYing up the hunt for a .ruby-version file so it's not duplicated in auto.sh and the new function I added to chruby-exec, but the refactoring would probably introduce more complexity than it's worth (since auto.sh's is so dependent on the RUBY_VERSION_FILE env variable). Maybe there's a relatively clean way of doing so, but again - shell scripting isn't a forte.
I did also make a small tweak to the chruby-exec test file to reduce false positives depending on developer setup, but possibly a resolution such as that proposed in #95 would render that tweak unnecessary.
Again, thanks for this remarkably sane piece of software, from our dev team and especially our inexplicably-not-completely-bald-yet ops team.