mirror of
https://github.com/pyenv/pyenv.git
synced 2024-11-21 20:47:00 -05:00
Extract rbenv-version-file{,-read,-write}
This commit is contained in:
parent
1d5c6531a2
commit
506bc3634f
7 changed files with 70 additions and 70 deletions
|
@ -1,16 +1,11 @@
|
|||
#!/usr/bin/env bash -e
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
RBENV_VERSION="$1"
|
||||
VERSION_FILE="${HOME}/.rbenv/default"
|
||||
if [ -z "$RBENV_VERSION" ]; then
|
||||
if [[ -e "$VERSION_FILE" ]]; then
|
||||
cat "$VERSION_FILE"
|
||||
else
|
||||
echo "No default version configured - set with: rbenv default <version>"
|
||||
fi
|
||||
else
|
||||
# Make sure the specified version is installed
|
||||
rbenv-prefix "$RBENV_VERSION" >/dev/null
|
||||
RBENV_VERSION_FILE="${HOME}/.rbenv/default"
|
||||
|
||||
echo "$RBENV_VERSION" > "$VERSION_FILE"
|
||||
if [ -n "$RBENV_VERSION" ]; then
|
||||
rbenv-version-file-write "$RBENV_VERSION_FILE" "$RBENV_VERSION"
|
||||
else
|
||||
rbenv-version-file-read "$RBENV_VERSION_FILE" || echo system
|
||||
fi
|
||||
|
|
|
@ -1,17 +1,14 @@
|
|||
#!/usr/bin/env bash -e
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
RBENV_VERSION="$1"
|
||||
VERSION_FILE=".rbenv-version"
|
||||
if [ -z "$RBENV_VERSION" ]; then
|
||||
if [[ -e "$VERSION_FILE" ]]; then
|
||||
cat "$VERSION_FILE"
|
||||
else
|
||||
echo "No local version configured - set with: rbenv local <version>"
|
||||
fi
|
||||
else
|
||||
# Make sure the specified version is installed
|
||||
rbenv-prefix "$RBENV_VERSION" >/dev/null
|
||||
RBENV_VERSION_FILE=".rbenv-version"
|
||||
|
||||
echo "$RBENV_VERSION" > "$VERSION_FILE"
|
||||
if [ -n "$RBENV_VERSION" ]; then
|
||||
rbenv-version-file-write "$RBENV_VERSION_FILE" "$RBENV_VERSION"
|
||||
else
|
||||
rbenv-version-file-read "$RBENV_VERSION_FILE" ||
|
||||
{ echo "rbenv: no local version configured for this directory"
|
||||
exit 1
|
||||
} >&2
|
||||
fi
|
||||
|
||||
|
|
15
libexec/rbenv-version-file
Executable file
15
libexec/rbenv-version-file
Executable file
|
@ -0,0 +1,15 @@
|
|||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
DEFAULT_PATH="${HOME}/.rbenv/default"
|
||||
|
||||
root="$(pwd)"
|
||||
while [ -n "$root" ]; do
|
||||
if [ -e "${root}/.rbenv-version" ]; then
|
||||
echo "${root}/.rbenv-version"
|
||||
exit
|
||||
fi
|
||||
root="${root%/*}"
|
||||
done
|
||||
|
||||
echo "$DEFAULT_PATH"
|
18
libexec/rbenv-version-file-read
Executable file
18
libexec/rbenv-version-file-read
Executable file
|
@ -0,0 +1,18 @@
|
|||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
VERSION_FILE="$1"
|
||||
|
||||
if [ -e "$VERSION_FILE" ]; then
|
||||
# Read and print the first non-whitespace word from the specified
|
||||
# version file.
|
||||
while read -a words; do
|
||||
version="${words[0]}"
|
||||
if [ -n "$version" ]; then
|
||||
echo "$version"
|
||||
break
|
||||
fi
|
||||
done < "$VERSION_FILE"
|
||||
else
|
||||
exit 1
|
||||
fi
|
15
libexec/rbenv-version-file-write
Executable file
15
libexec/rbenv-version-file-write
Executable file
|
@ -0,0 +1,15 @@
|
|||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
RBENV_VERSION_FILE="$1"
|
||||
RBENV_VERSION="$2"
|
||||
|
||||
if [ -z "$RBENV_VERSION" ] || [ -z "$RBENV_VERSION_FILE" ]; then
|
||||
echo "usage: rbenv write-version-file filename version" >&2
|
||||
fi
|
||||
|
||||
# Make sure the specified version is installed.
|
||||
rbenv-prefix "$RBENV_VERSION" >/dev/null
|
||||
|
||||
# Write the version out to disk.
|
||||
echo "$RBENV_VERSION" > "$RBENV_VERSION_FILE"
|
|
@ -1,29 +1,11 @@
|
|||
#!/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
|
||||
RBENV_VERSION_FILE="$(rbenv-version-file)"
|
||||
RBENV_VERSION="$(rbenv-version-file-read "$RBENV_VERSION_FILE" || true)"
|
||||
fi
|
||||
|
||||
if [ "$RBENV_VERSION" = "system" ]; then
|
||||
|
|
|
@ -1,30 +1,8 @@
|
|||
#!/usr/bin/env bash
|
||||
set -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
|
||||
if [ -n "$RBENV_VERSION" ]; then
|
||||
echo "RBENV_VERSION environment variable"
|
||||
else
|
||||
rbenv-version-file
|
||||
fi
|
||||
|
|
Loading…
Reference in a new issue