Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Intial prototype of auto-switching for chruby (issue #40).
- Loading branch information
1 parent
b077a7d
commit 675c558
Showing
1 changed file
with
17 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
675c558
There was a problem hiding this comment.
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?
675c558
There was a problem hiding this comment.
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.675c558
There was a problem hiding this comment.
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.