Last active
October 7, 2016 23:27
-
-
Save sauron/b11ea2955d5ca69c7e6985c9806ed477 to your computer and use it in GitHub Desktop.
My updated version of https://github.com/postmodern/chruby so it always set the gem_home as the directory where there is a .ruby-version file. Line 14 contains the "super hack"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unset RUBY_AUTO_VERSION | |
function chruby_auto() { | |
local dir="$PWD/" version | |
until [[ -z "$dir" ]]; do | |
dir="${dir%/*}" | |
if { read -r version <"$dir/.ruby-version"; } 2>/dev/null || [[ -n "$version" ]]; then | |
if [[ "$version" == "$RUBY_AUTO_VERSION" ]]; then return | |
else | |
RUBY_AUTO_VERSION="$version" | |
chruby "$version" | |
gem_home $dir | |
return $? | |
fi | |
fi | |
done | |
if [[ -n "$RUBY_AUTO_VERSION" ]]; then | |
chruby_reset | |
unset RUBY_AUTO_VERSION | |
fi | |
} | |
if [[ -n "$ZSH_VERSION" ]]; then | |
if [[ ! "$preexec_functions" == *chruby_auto* ]]; then | |
preexec_functions+=("chruby_auto") | |
fi | |
elif [[ -n "$BASH_VERSION" ]]; then | |
trap '[[ "$BASH_COMMAND" != "$PROMPT_COMMAND" ]] && chruby_auto' DEBUG | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment