mirror of
https://github.com/pyenv/pyenv.git
synced 2024-12-22 23:10:47 +00:00
41 lines
854 B
Bash
Executable file
41 lines
854 B
Bash
Executable file
#!/usr/bin/env bash
|
|
set -e
|
|
|
|
# Read the first non-whitespace word from the specified file.
|
|
read_version_file() {
|
|
local words version
|
|
while read -a words; do
|
|
version="${words[0]}"
|
|
if [ -n "$version" ]; then
|
|
echo "$version"
|
|
break
|
|
fi
|
|
done < "$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
|