Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Perform an ascending search for .ruby-version (issue #40).
* Added @wilmoore's test case.
- Loading branch information
1 parent
88b79c8
commit 0a333ac
Showing
2 changed files
with
28 additions
and
12 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 |
---|---|---|
@@ -1,13 +1,28 @@ | ||
function chruby_auto() { | ||
if [[ -f .ruby-version ]]; then | ||
chruby $(cat .ruby-version) && export RUBY_VERSIONED_DIR="$PWD" | ||
elif [[ "$PWD" != "$RUBY_VERSIONED_DIR"/* ]]; then | ||
chruby_reset; unset RUBY_VERSIONED_DIR | ||
if [[ -n "$RUBY_VERSIONED_DIR" ]]; then | ||
if [[ "$PWD" != "$RUBY_VERSIONED_DIR"/* ]]; then | ||
chruby_reset | ||
unset RUBY_VERSIONED_DIR | ||
fi | ||
else | ||
local dir="$PWD" | ||
local version_file | ||
|
||
until [[ "$dir" == / ]]; do | ||
version_file="$dir/.ruby-version" | ||
|
||
if [[ -f "$version_file" ]]; then | ||
chruby $(cat "$version_file") || return 1 | ||
|
||
export RUBY_VERSIONED_DIR="$dir" | ||
break | ||
fi | ||
|
||
dir=$(dirname "$dir") | ||
done | ||
fi | ||
} | ||
|
||
if [[ -n "$ZSH_VERSION" ]]; then | ||
precmd_functions+=("chruby_auto") | ||
else | ||
PROMPT_COMMAND="chruby_auto; $PROMPT_COMMAND" | ||
if [[ -n "$ZSH_VERSION" ]]; then precmd_functions+=("chruby_auto") | ||
else PROMPT_COMMAND="chruby_auto; $PROMPT_COMMAND" | ||
fi |
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