2011-08-12 05:33:45 -04:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
set -e
|
2011-08-09 16:41:35 -04:00
|
|
|
|
2011-08-16 01:01:03 -04:00
|
|
|
# Read the first non-whitespace word from the specified file.
|
2011-08-09 16:41:35 -04:00
|
|
|
read_version_file() {
|
2011-08-16 01:01:03 -04:00
|
|
|
local words version
|
|
|
|
while read -a words; do
|
|
|
|
version="${words[0]}"
|
|
|
|
if [ -n "$version" ]; then
|
|
|
|
echo "$version"
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done < "$1"
|
2011-08-09 16:41:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|