1
0
mirror of https://github.com/pyenv/pyenv.git synced 2025-11-16 07:13:53 -05:00

Merge remote-tracking branch 'origin/master' into version-hooks

This commit is contained in:
Mislav Marohnić
2015-12-23 17:22:43 +01:00
25 changed files with 347 additions and 103 deletions

View File

@@ -12,39 +12,42 @@ if [ -n "$RBENV_DEBUG" ]; then
set -x
fi
if enable -f "${0%/*}"/../libexec/rbenv-realpath.dylib realpath 2>/dev/null; then
abort() {
{ if [ "$#" -eq 0 ]; then cat -
else echo "rbenv: $*"
fi
} >&2
exit 1
}
if enable -f "${BASH_SOURCE%/*}"/../libexec/rbenv-realpath.dylib realpath 2>/dev/null; then
abs_dirname() {
local path="$(realpath "$1")"
echo "${path%/*}"
}
else
if [ -n "$RBENV_NATIVE_EXT" ]; then
echo "rbenv: failed to load \`realpath' builtin" >&2
exit 1
fi
READLINK=$(type -p greadlink readlink | head -1)
if [ -z "$READLINK" ]; then
echo "rbenv: cannot find readlink - are you missing GNU coreutils?" >&2
exit 1
fi
[ -z "$RBENV_NATIVE_EXT" ] || abort "failed to load \`realpath' builtin"
resolve_link() {
$READLINK "$1"
}
READLINK=$(type -p greadlink readlink | head -1)
[ -n "$READLINK" ] || abort "cannot find readlink - are you missing GNU coreutils?"
abs_dirname() {
local cwd="$(pwd)"
local path="$1"
resolve_link() {
$READLINK "$1"
}
while [ -n "$path" ]; do
cd "${path%/*}"
local name="${path##*/}"
path="$(resolve_link "$name" || true)"
done
abs_dirname() {
local cwd="$PWD"
local path="$1"
pwd
cd "$cwd"
}
while [ -n "$path" ]; do
cd "${path%/*}"
local name="${path##*/}"
path="$(resolve_link "$name" || true)"
done
pwd
cd "$cwd"
}
fi
if [ -z "${RBENV_ROOT}" ]; then
@@ -55,13 +58,10 @@ fi
export RBENV_ROOT
if [ -z "${RBENV_DIR}" ]; then
RBENV_DIR="$(pwd)"
RBENV_DIR="$PWD"
else
cd "$RBENV_DIR" 2>/dev/null || {
echo "rbenv: cannot change working directory to \`$RBENV_DIR'"
exit 1
} >&2
RBENV_DIR="$(pwd)"
cd "$RBENV_DIR" 2>/dev/null || abort "cannot change working directory to \`$RBENV_DIR'"
RBENV_DIR="$PWD"
cd "$OLDPWD"
fi
export RBENV_DIR
@@ -91,20 +91,26 @@ shopt -u nullglob
command="$1"
case "$command" in
"" | "-h" | "--help" )
echo -e "$(rbenv---version)\n$(rbenv-help)" >&2
"" )
{ rbenv---version
rbenv-help
} | abort
;;
"-v" )
-v | --version )
exec rbenv---version
;;
-h | --help )
exec rbenv-help
;;
* )
command_path="$(command -v "rbenv-$command" || true)"
if [ -z "$command_path" ]; then
echo "rbenv: no such command \`$command'" >&2
exit 1
fi
[ -n "$command_path" ] || abort "no such command \`$command'"
shift 1
exec "$command_path" "$@"
if [ "$1" = --help ]; then
exec rbenv-help "$command"
else
exec "$command_path" "$@"
fi
;;
esac

View File

@@ -13,10 +13,14 @@ set -e
[ -n "$RBENV_DEBUG" ] && set -x
version="0.4.0"
git_revision=""
if cd "$RBENV_ROOT" 2>/dev/null; then
git_revision="$(git describe --tags HEAD 2>/dev/null || true)"
git_revision="${git_revision#v}"
fi
for source_dir in "${BASH_SOURCE%/*}" "$RBENV_ROOT"; do
if cd "$source_dir" 2>/dev/null && git remote -v 2>/dev/null | grep -q rbenv; then
git_revision="$(git describe --tags HEAD 2>/dev/null || true)"
git_revision="${git_revision#v}"
[ -z "$git_revision" ] || break
fi
done
echo "rbenv ${git_revision:-$version}"

View File

@@ -10,7 +10,16 @@ if [ -z "$COMMAND" ]; then
exit 1
fi
# Provide rbenv completions
if [ "$COMMAND" = "--complete" ]; then
exec rbenv-commands
fi
COMMAND_PATH="$(command -v "rbenv-$COMMAND" || command -v "rbenv-sh-$COMMAND")"
# --help is provided automatically
echo --help
if grep -iE "^([#%]|--|//) provide rbenv completions" "$COMMAND_PATH" >/dev/null; then
shift
exec "$COMMAND_PATH" --complete "$@"

View File

@@ -15,6 +15,12 @@
set -e
[ -n "$RBENV_DEBUG" ] && set -x
# Provide rbenv completions
if [ "$1" = "--complete" ]; then
echo --usage
exec rbenv-commands
fi
command_path() {
local command="$1"
command -v rbenv-"$command" || command -v rbenv-sh-"$command" || true
@@ -146,7 +152,7 @@ if [ -z "$1" ] || [ "$1" == "rbenv" ]; then
print_summaries commands local global shell install uninstall rehash version versions which whence
echo
echo "See \`rbenv help <command>' for information on a specific command."
echo "For full documentation, see: https://github.com/sstephenson/rbenv#readme"
echo "For full documentation, see: https://github.com/rbenv/rbenv#readme"
else
command="$1"
if [ -n "$(command_path "$command")" ]; then

View File

@@ -37,16 +37,17 @@ resolve_link() {
}
realpath() {
local cwd="$(pwd)"
local cwd="$PWD"
local path="$1"
local name
while [ -n "$path" ]; do
cd "${path%/*}"
local name="${path##*/}"
name="${path##*/}"
[ "$name" = "$path" ] || cd "${path%/*}"
path="$(resolve_link "$name" || true)"
done
echo "$(pwd)/$name"
echo "${PWD}/$name"
cd "$cwd"
}
fi

View File

@@ -5,6 +5,17 @@
set -e
[ -n "$RBENV_DEBUG" ] && set -x
# Provide rbenv completions
if [ "$1" = "--complete" ]; then
echo -
echo --no-rehash
echo bash
echo fish
echo ksh
echo zsh
exit
fi
print=""
no_rehash=""
for args in "$@"
@@ -25,7 +36,8 @@ if [ -z "$shell" ]; then
shell="$(ps c -p "$PPID" -o 'ucomm=' 2>/dev/null || true)"
shell="${shell##-}"
shell="${shell%% *}"
shell="$(basename "${shell:-$SHELL}")"
shell="${shell:-$SHELL}"
shell="${shell##*/}"
fi
root="${0%/*}/.."
@@ -33,7 +45,11 @@ root="${0%/*}/.."
if [ -z "$print" ]; then
case "$shell" in
bash )
profile='~/.bash_profile'
if [ -f "${HOME}/.bashrc" ] && [ ! -f "${HOME}/.bash_profile" ]; then
profile='~/.bashrc'
else
profile='~/.bash_profile'
fi
;;
zsh )
profile='~/.zshrc'
@@ -49,7 +65,7 @@ if [ -z "$print" ]; then
;;
esac
{ echo "# Load rbenv automatically by adding"
{ echo "# Load rbenv automatically by appending"
echo "# the following to ${profile}:"
echo
case "$shell" in
@@ -88,7 +104,7 @@ if [ -r "$completion" ]; then
fi
if [ -z "$no_rehash" ]; then
echo 'rbenv rehash 2>/dev/null'
echo 'command rbenv rehash 2>/dev/null'
fi
commands=(`rbenv-commands --sh`)
@@ -101,7 +117,7 @@ function rbenv
switch "\$command"
case ${commands[*]}
eval (rbenv "sh-\$command" \$argv)
. (rbenv "sh-\$command" \$argv|psub)
case '*'
command rbenv "\$command" \$argv
end
@@ -132,7 +148,7 @@ cat <<EOS
case "\$command" in
${commands[*]})
eval "\`rbenv "sh-\$command" "\$@"\`";;
eval "\$(rbenv "sh-\$command" "\$@")";;
*)
command rbenv "\$command" "\$@";;
esac

View File

@@ -81,9 +81,12 @@ remove_outdated_shims() {
# List basenames of executables for every Ruby version
list_executable_names() {
local file
for file in "$RBENV_ROOT"/versions/*/bin/*; do
echo "${file##*/}"
local version file
rbenv-versions --bare --skip-aliases | \
while read version; do
for file in "${RBENV_ROOT}/versions/${version}/bin/"*; do
echo "${file##*/}"
done
done
}
@@ -110,7 +113,7 @@ install_registered_shims() {
local shim file
for shim in $registered_shims; do
file="${SHIM_PATH}/${shim}"
[ -e "$file" ] || ln -f "$PROTOTYPE_SHIM_PATH" "$file"
[ -e "$file" ] || cp "$PROTOTYPE_SHIM_PATH" "$file"
done
}

View File

@@ -5,7 +5,8 @@ set -e
find_local_version_file() {
local root="$1"
while [ -n "$root" ]; do
while true; do
[[ "$root" =~ ^//[^/]*$ ]] && break
if [ -e "${root}/.ruby-version" ]; then
echo "${root}/.ruby-version"
exit
@@ -13,6 +14,7 @@ find_local_version_file() {
echo "${root}/.rbenv-version"
exit
fi
[ -n "$root" ] || break
root="${root%/*}"
done
}

View File

@@ -30,6 +30,6 @@ if version_exists "$RBENV_VERSION"; then
elif version_exists "${RBENV_VERSION#ruby-}"; then
echo "${RBENV_VERSION#ruby-}"
else
echo "rbenv: version \`$RBENV_VERSION' is not installed" >&2
echo "rbenv: version \`$RBENV_VERSION' is not installed (set by $(rbenv-version-origin))" >&2
exit 1
fi

View File

@@ -1,13 +1,69 @@
#!/usr/bin/env bash
# Summary: List all Ruby versions available to rbenv
# Usage: rbenv versions [--bare]
# Usage: rbenv versions [--bare] [--skip-aliases]
#
# Lists all Ruby versions found in `$RBENV_ROOT/versions/*'.
set -e
[ -n "$RBENV_DEBUG" ] && set -x
if [ "$1" = "--bare" ]; then
unset bare
unset skip_aliases
# Provide rbenv completions
for arg; do
case "$arg" in
--complete )
echo --bare
echo --skip-aliases
exit ;;
--bare ) bare=1 ;;
--skip-aliases ) skip_aliases=1 ;;
* )
rbenv-help --usage versions >&2
exit 1
;;
esac
done
versions_dir="${RBENV_ROOT}/versions"
if ! enable -f "${BASH_SOURCE%/*}"/../libexec/rbenv-realpath.dylib realpath 2>/dev/null; then
if [ -n "$RBENV_NATIVE_EXT" ]; then
echo "rbenv: failed to load \`realpath' builtin" >&2
exit 1
fi
READLINK=$(type -p greadlink readlink | head -1)
if [ -z "$READLINK" ]; then
echo "rbenv: cannot find readlink - are you missing GNU coreutils?" >&2
exit 1
fi
resolve_link() {
$READLINK "$1"
}
realpath() {
local cwd="$PWD"
local path="$1"
local name
while [ -n "$path" ]; do
name="${path##*/}"
[ "$name" = "$path" ] || cd "${path%/*}"
path="$(resolve_link "$name" || true)"
done
echo "${PWD}/$name"
cd "$cwd"
}
fi
if [ -d "$versions_dir" ]; then
versions_dir="$(realpath "$versions_dir")"
fi
if [ -n "$bare" ]; then
hit_prefix=""
miss_prefix=""
current_version=""
@@ -36,8 +92,12 @@ if [ -n "$include_system" ] && RBENV_VERSION=system rbenv-which ruby >/dev/null
fi
shopt -s nullglob
for path in "${RBENV_ROOT}/versions/"*; do
for path in "$versions_dir"/*; do
if [ -d "$path" ]; then
if [ -n "$skip_aliases" ] && [ -L "$path" ]; then
target="$(realpath "$path")"
[ "${target%/*}" != "$versions_dir" ] || continue
fi
print_version "${path##*/}"
fi
done

View File

@@ -23,7 +23,8 @@ remove_from_path() {
path_before="$result"
result="${result//:$path_to_remove:/:}"
done
echo "${result%:}"
result="${result%:}"
echo "${result#:}"
}
RBENV_COMMAND="$1"
@@ -51,8 +52,8 @@ done
if [ -x "$RBENV_COMMAND_PATH" ]; then
echo "$RBENV_COMMAND_PATH"
elif ! [ -d "${RBENV_ROOT}/versions/${RBENV_VERSION}" ]; then
echo "rbenv: version \`$RBENV_VERSION' is not installed" >&2
elif [ "$RBENV_VERSION" != "system" ] && [ ! -d "${RBENV_ROOT}/versions/${RBENV_VERSION}" ]; then
echo "rbenv: version \`$RBENV_VERSION' is not installed (set by $(rbenv-version-origin))" >&2
exit 1
else
echo "rbenv: $RBENV_COMMAND: command not found" >&2