Merge branch 'master' into help

This commit is contained in:
Sam Stephenson 2012-12-29 11:23:23 -06:00
commit ef44b4ccac
10 changed files with 93 additions and 78 deletions

View File

@ -128,24 +128,16 @@ easy to fork and contribute any changes back upstream.
$ exec $SHELL -l $ exec $SHELL -l
~~~ ~~~
5. Install Ruby versions into `~/.rbenv/versions`. For example, to 5. Install [ruby-build][], which provides an `rbenv install`
manually compile Ruby [from source](https://github.com/ruby/ruby), command that simplifies the process of installing new Ruby versions.
download it and run:
~~~ sh
$ [ -f ./configure ] || autoconf
$ ./configure --prefix=$HOME/.rbenv/versions/1.9.3-p327
$ make
$ make install
~~~
The [ruby-build][] project, however, provides an `rbenv install`
command that simplifies the process of installing new Ruby versions:
~~~ ~~~
$ rbenv install 1.9.3-p327 $ rbenv install 1.9.3-p327
~~~ ~~~
As an alternative, you can download and compile Ruby yourself into
`~/.rbenv/versions/`.
6. Rebuild the shim binaries. You should do this any time you install 6. Rebuild the shim binaries. You should do this any time you install
a new Ruby binary (for example, when installing a new Ruby version, a new Ruby binary (for example, when installing a new Ruby version,
or when installing a gem that provides a binary). or when installing a gem that provides a binary).

View File

@ -5,8 +5,10 @@ _rbenv() {
if [ "$COMP_CWORD" -eq 1 ]; then if [ "$COMP_CWORD" -eq 1 ]; then
COMPREPLY=( $(compgen -W "$(rbenv commands)" -- "$word") ) COMPREPLY=( $(compgen -W "$(rbenv commands)" -- "$word") )
else else
local command="${COMP_WORDS[1]}" local words=("${COMP_WORDS[@]}")
local completions="$(rbenv completions "$command")" unset words[0]
unset words[$COMP_CWORD]
local completions=$(rbenv completions "${words[@]}")
COMPREPLY=( $(compgen -W "$completions" -- "$word") ) COMPREPLY=( $(compgen -W "$completions" -- "$word") )
fi fi
} }

View File

@ -5,14 +5,13 @@ fi
compctl -K _rbenv rbenv compctl -K _rbenv rbenv
_rbenv() { _rbenv() {
local word words completions local words completions
read -cA words read -cA words
word="${words[2]}"
if [ "${#words}" -eq 2 ]; then if [ "${#words}" -eq 2 ]; then
completions="$(rbenv commands)" completions="$(rbenv commands)"
else else
completions="$(rbenv completions "${word}")" completions="$(rbenv completions ${words[2,-1]})"
fi fi
reply=("${(ps:\n:)completions}") reply=("${(ps:\n:)completions}")

View File

@ -60,7 +60,7 @@ shopt -u nullglob
command="$1" command="$1"
case "$command" in case "$command" in
"" | "-h" | "--help" ) "" | "-h" | "--help" )
echo -e "rbenv $(rbenv---version)\n$(rbenv-help)" >&2 echo -e "$(rbenv---version)\n$(rbenv-help)" >&2
;; ;;
"-v" ) "-v" )
exec rbenv---version exec rbenv---version

View File

@ -2,9 +2,10 @@
set -e set -e
[ -n "$RBENV_DEBUG" ] && set -x [ -n "$RBENV_DEBUG" ] && set -x
version=v0.3.0 version=0.3.0
cd "$RBENV_ROOT" cd "$RBENV_ROOT"
git_revision="$(git describe --tags HEAD 2>/dev/null || true)" git_revision="$(git describe --tags HEAD 2>/dev/null || true)"
git_revision="${git_revision#v}"
echo ${git_revision:-$version} echo "rbenv ${git_revision:-$version}"

View File

@ -7,7 +7,9 @@ if [ "$1" = "--complete" ]; then
exec rbenv shims --short exec rbenv shims --short
fi fi
export RBENV_VERSION="$(rbenv-version-name)"
RBENV_COMMAND="$1" RBENV_COMMAND="$1"
if [ -z "$RBENV_COMMAND" ]; then if [ -z "$RBENV_COMMAND" ]; then
echo "usage: rbenv exec COMMAND [arg1 arg2...]" >&2 echo "usage: rbenv exec COMMAND [arg1 arg2...]" >&2
exit 1 exit 1
@ -21,5 +23,7 @@ for script in $(rbenv-hooks exec); do
done done
shift 1 shift 1
if [ "$RBENV_VERSION" != "system" ]; then
export PATH="${RBENV_BIN_PATH}:${PATH}" export PATH="${RBENV_BIN_PATH}:${PATH}"
fi
exec -a "$RBENV_COMMAND" "$RBENV_COMMAND_PATH" "$@" exec -a "$RBENV_COMMAND" "$RBENV_COMMAND_PATH" "$@"

View File

@ -86,7 +86,8 @@ commands=(`rbenv-commands --sh`)
IFS="|" IFS="|"
cat <<EOS cat <<EOS
rbenv() { rbenv() {
local command="\$1" typeset command
command="\$1"
if [ "\$#" -gt 0 ]; then if [ "\$#" -gt 0 ]; then
shift shift
fi fi

View File

@ -39,12 +39,41 @@ create_prototype_shim() {
cat > "$PROTOTYPE_SHIM_PATH" <<SH cat > "$PROTOTYPE_SHIM_PATH" <<SH
#!/usr/bin/env bash #!/usr/bin/env bash
set -e set -e
[ -n "\$RBENV_DEBUG" ] && set -x
program="\${0##*/}"
if [ "\$program" = "ruby" ]; then
for arg; do
case "\$arg" in
-e* | -- ) break ;;
*/* )
if [ -f "\$arg" ]; then
export RBENV_DIR="\${arg%/*}"
break
fi
;;
esac
done
fi
export RBENV_ROOT="$RBENV_ROOT" export RBENV_ROOT="$RBENV_ROOT"
exec rbenv exec "\${0##*/}" "\$@" exec rbenv exec "\$program" "\$@"
SH SH
chmod +x "$PROTOTYPE_SHIM_PATH" chmod +x "$PROTOTYPE_SHIM_PATH"
} }
# If the contents of the prototype shim file differ from the contents
# of the first shim in the shims directory, assume rbenv has been
# upgraded and the existing shims need to be removed.
remove_outdated_shims() {
for shim in *; do
if ! diff "$PROTOTYPE_SHIM_PATH" "$shim" >/dev/null 2>&1; then
for shim in *; do rm -f "$shim"; done
fi
break
done
}
# The basename of each argument passed to `make_shims` will be # The basename of each argument passed to `make_shims` will be
# registered for installation as a shim. In this way, plugins may call # registered for installation as a shim. In this way, plugins may call
# `make_shims` with a glob to register many shims at once. # `make_shims` with a glob to register many shims at once.
@ -57,58 +86,27 @@ make_shims() {
done done
} }
# Create an empty array for the list of registered shims. # Create an empty array for the list of registered shims and an empty
# string to use as a search index.
registered_shims=() registered_shims=()
registered_shims_index=""
# We will keep track of shims registered for installation with the # We will keep track of shims registered for installation with the
# global `reigstered_shims` array and with a global variable for each # global `reigstered_shims` array and with a global search index
# shim. The array will let us iterate over all registered shims. The # string. The array will let us iterate over all registered shims. The
# global variables will let us quickly check whether a shim with the # index string will let us quickly check whether a shim with the given
# given name has been registered or not. # name has been registered or not.
register_shim() { register_shim() {
local shim="$@" local shim="$@"
local var="$(shim_variable_name "$shim")" registered_shims["${#registered_shims[@]}"]="$shim"
registered_shims_index="$registered_shims_index/$shim/"
if [ -z "${!var}" ]; then
registered_shims[${#registered_shims[*]}]="$shim"
eval "${var}=1"
fi
}
# To compute the global variable name for a given shim we must first
# escape any non-alphanumeric characters. If the shim name is
# alphanumeric (including a hyphen or underscore) we can take a
# shorter path. Otherwise, we must iterate over each character and
# escape the non-alphanumeric ones using `printf`.
shim_variable_name() {
local shim="$1"
local result="_shim_"
if [[ ! "$shim" =~ [^[:alnum:]_-] ]]; then
shim="${shim//_/_5f}"
shim="${shim//-/_2d}"
result="$result$shim"
else
local length="${#shim}"
local char i
for ((i=0; i<length; i++)); do
char="${shim:$i:1}"
if [[ "$char" =~ [[:alnum:]] ]]; then
result="$result$char"
else
result="$result$(printf "_%02x" \'"$char")"
fi
done
fi
echo "$result"
} }
# To install all the registered shims, we iterate over the # To install all the registered shims, we iterate over the
# `registered_shims` array and create a link if one does not already # `registered_shims` array and create a link if one does not already
# exist. # exist.
install_registered_shims() { install_registered_shims() {
local shim
for shim in "${registered_shims[@]}"; do for shim in "${registered_shims[@]}"; do
[ -e "$shim" ] || ln -f "$PROTOTYPE_SHIM_PATH" "$shim" [ -e "$shim" ] || ln -f "$PROTOTYPE_SHIM_PATH" "$shim"
done done
@ -119,10 +117,9 @@ install_registered_shims() {
# in the directory but has not been registered as a shim should be # in the directory but has not been registered as a shim should be
# removed. # removed.
remove_stale_shims() { remove_stale_shims() {
local var local shim
for shim in *; do for shim in *; do
var="$(shim_variable_name "$shim")" if [[ "$registered_shims_index" != *"/$shim/"* ]]; then
if [ -z "${!var}" ]; then
rm -f "$shim" rm -f "$shim"
fi fi
done done
@ -131,10 +128,11 @@ remove_stale_shims() {
# Change to the shims directory. # Change to the shims directory.
cd "$SHIM_PATH" cd "$SHIM_PATH"
shopt -s nullglob
# Create the prototype shim, then register shims for all known binaries. # Create the prototype shim, then register shims for all known binaries.
create_prototype_shim create_prototype_shim
shopt -s nullglob remove_outdated_shims
make_shims ../versions/*/bin/* make_shims ../versions/*/bin/*
# Restore the previous working directory. # Restore the previous working directory.

13
libexec/rbenv-sh-rehash Executable file
View File

@ -0,0 +1,13 @@
#!/usr/bin/env bash
set -e
[ -n "$RBENV_DEBUG" ] && set -x
# Provide rbenv completions
if [ "$1" = "--complete" ]; then
exec rbenv-rehash --complete
fi
# When rbenv shell integration is enabled, delegate to rbenv-rehash,
# then tell the shell to empty its command lookup cache.
rbenv-rehash
echo "hash -r"

View File

@ -2,7 +2,8 @@
set -e set -e
[ -n "$RBENV_DEBUG" ] && set -x [ -n "$RBENV_DEBUG" ] && set -x
root="$RBENV_DIR" find_local_version_file() {
local root="$1"
while [ -n "$root" ]; do while [ -n "$root" ]; do
if [ -e "${root}/.rbenv-version" ]; then if [ -e "${root}/.rbenv-version" ]; then
echo "${root}/.rbenv-version" echo "${root}/.rbenv-version"
@ -10,6 +11,10 @@ while [ -n "$root" ]; do
fi fi
root="${root%/*}" root="${root%/*}"
done done
}
find_local_version_file "$RBENV_DIR"
[ "$RBENV_DIR" = "$PWD" ] || find_local_version_file "$PWD"
global_version_file="${RBENV_ROOT}/version" global_version_file="${RBENV_ROOT}/version"