Merge pull request #15 from ryanfb/version_origin

Split rbenv-version into rbenv-version-name and rbenv-version-origin
This commit is contained in:
Sam Stephenson 2011-08-09 13:48:20 -07:00
commit 3f3992d95a
6 changed files with 72 additions and 58 deletions

View file

@ -3,7 +3,7 @@
if [ -n "$1" ]; then if [ -n "$1" ]; then
RBENV_VERSION="$1" RBENV_VERSION="$1"
elif [ -z "$RBENV_VERSION" ]; then elif [ -z "$RBENV_VERSION" ]; then
RBENV_VERSION="$(rbenv-version)" RBENV_VERSION="$(rbenv-version-name)"
fi fi
if [ "$RBENV_VERSION" = "system" ]; then if [ "$RBENV_VERSION" = "system" ]; then

View file

@ -1,52 +1,3 @@
#!/usr/bin/env bash -e #!/usr/bin/env bash -e
read_version_file() { echo "$(rbenv-version-name) (set by $(rbenv-version-origin))"
egrep -m 1 '[^[:space:]]' "$1"
}
find_version_file() {
local root="$(pwd)"
while [ -n "$root" ]; do
if [ -e "${root}/.rbenv-version" ]; then
echo "${root}/.rbenv-version"
return 0
fi
root="${root%/*}"
done
return 1
}
DEFAULT_PATH="${HOME}/.rbenv/default"
find_default_version_file() {
if [ -e "$DEFAULT_PATH" ]; then
echo "$DEFAULT_PATH"
return 0
fi
return 1
}
if [ -z "$RBENV_VERSION" ]; then
RBENV_VERSION_FILE="$(find_version_file || find_default_version_file || true)"
if [ -n "$RBENV_VERSION_FILE" ]; then
RBENV_VERSION="$(read_version_file "$RBENV_VERSION_FILE")"
else
echo system > "$DEFAULT_PATH"
RBENV_VERSION=system
fi
fi
if [ "$RBENV_VERSION" = "system" ]; then
echo "$RBENV_VERSION"
exit
fi
RBENV_VERSION_PATH="${HOME}/.rbenv/versions/${RBENV_VERSION}"
if [ -d "$RBENV_VERSION_PATH" ]; then
echo "$RBENV_VERSION"
else
echo "rbenv: version \`$RBENV_VERSION' is not installed" >&2
exit 1
fi

32
libexec/rbenv-version-name Executable file
View file

@ -0,0 +1,32 @@
#!/usr/bin/env bash -e
read_version_file() {
egrep -m 1 '[^[:space:]]' "$1"
}
DEFAULT_PATH="${HOME}/.rbenv/default"
if [ -z "$RBENV_VERSION" ]; then
RBENV_VERSION_FILE="$(rbenv-version-origin)"
if [ -n "$RBENV_VERSION_FILE" ]; then
RBENV_VERSION="$(read_version_file "$RBENV_VERSION_FILE")"
else
echo system > "$DEFAULT_PATH"
RBENV_VERSION=system
fi
fi
if [ "$RBENV_VERSION" = "system" ]; then
echo "$RBENV_VERSION"
exit
fi
RBENV_VERSION_PATH="${HOME}/.rbenv/versions/${RBENV_VERSION}"
if [ -d "$RBENV_VERSION_PATH" ]; then
echo "$RBENV_VERSION"
else
echo "rbenv: version \`$RBENV_VERSION' is not installed" >&2
exit 1
fi

29
libexec/rbenv-version-origin Executable file
View file

@ -0,0 +1,29 @@
#!/usr/bin/env bash -e
find_version_file() {
local root="$(pwd)"
while [ -n "$root" ]; do
if [ -e "${root}/.rbenv-version" ]; then
echo "${root}/.rbenv-version"
return 0
fi
root="${root%/*}"
done
return 1
}
DEFAULT_PATH="${HOME}/.rbenv/default"
find_default_version_file() {
if [ -e "$DEFAULT_PATH" ]; then
echo "$DEFAULT_PATH"
return 0
fi
return 1
}
if [ -z "$RBENV_VERSION" ]; then
find_version_file || find_default_version_file || true
else
echo "RBENV_VERSION environment variable"
fi

View file

@ -1,21 +1,23 @@
#!/usr/bin/env bash -e #!/usr/bin/env bash -e
RBENV_VERSION="$(rbenv-version)" RBENV_VERSION_NAME="$(rbenv-version-name)"
hit_prefix="* "
miss_prefix=" "
if [ "$1" = "--bare" ]; then if [ "$1" = "--bare" ]; then
hit_prefix="" hit_prefix=""
miss_prefix="" miss_prefix=""
print_version="$RBENV_VERSION_NAME"
else
hit_prefix="* "
miss_prefix=" "
print_version="$(rbenv-version)"
fi fi
for path in "${HOME}/.rbenv/versions/"*; do for path in "${HOME}/.rbenv/versions/"*; do
if [ -d "$path" ]; then if [ -d "$path" ]; then
version="${path##*/}" version="${path##*/}"
if [ "$version" == "$RBENV_VERSION" ]; then if [ "$version" == "$RBENV_VERSION_NAME" ]; then
echo "${hit_prefix}${version}" echo "${hit_prefix}${print_version}"
else else
echo "${miss_prefix}${version}" echo "${miss_prefix}${version}"
fi fi

View file

@ -21,7 +21,7 @@ remove_from_path() {
echo "${result%:}" echo "${result%:}"
} }
RBENV_VERSION="$(rbenv-version)" RBENV_VERSION="$(rbenv-version-name)"
RBENV_COMMAND="$1" RBENV_COMMAND="$1"
if [ "$RBENV_VERSION" = "system" ]; then if [ "$RBENV_VERSION" = "system" ]; then