Skip to content

Commit

Permalink
Intial prototype of auto-switching for chruby (issue #40).
Browse files Browse the repository at this point in the history
  • Loading branch information
postmodern committed Dec 12, 2012
1 parent b077a7d commit 675c558
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions share/chruby/auto.sh
@@ -0,0 +1,17 @@
function chruby_auto() {
local version_file="$PWD/.ruby-version"

if [[ -f "$version_file" ]]; then
chruby $(cat "$version_file")
export RUBY_VERSIONED_DIRECTORY="$PWD"
elif [[ "$PWD" != "$RUBY_VERSIONED_DIRECTORY"/* ]]; then
chruby_reset
unset RUBY_VERSIONED_DIRECTORY
fi
}

if [[ -n "$ZSH_VERSION" ]]; then
chpwd_functions=(${chpwd_functions[@]} "chruby_auto")
else
function cd() { builtin cd "$@" && chruby_auto; }
fi

3 comments on commit 675c558

@ku1ik
Copy link
Contributor

@ku1ik ku1ik commented on 675c558 Dec 13, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand that correctly when you enter directory with .ruby-version your ruby will switch. When you go deeper (like from Rails.root to Rails.root/script/) then it will reset. Right?

Maybe when you go deeper it should not reset? What do you think?

@postmodern
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The elif [[ "$PWD" != "$RUBY_VERSIONED_DIRECTORY"/* ]]; then ensures you are still somewhere within the .ruby-version containing directory. Once you ascend outside of that directory, than it should reset.

@ku1ik
Copy link
Contributor

@ku1ik ku1ik commented on 675c558 Dec 13, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, right. I didn't notice /* at the end. Cool.

Please sign in to comment.