From 02332d78f38d9baef7374841d736331dc5eaff09 Mon Sep 17 00:00:00 2001 From: Brian Olsen Date: Fri, 5 Oct 2012 04:28:25 +0200 Subject: [PATCH 01/11] Added bash support for completion of full command line --- completions/rbenv.bash | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/completions/rbenv.bash b/completions/rbenv.bash index e3276016..fe0784ac 100644 --- a/completions/rbenv.bash +++ b/completions/rbenv.bash @@ -5,8 +5,10 @@ _rbenv() { if [ "$COMP_CWORD" -eq 1 ]; then COMPREPLY=( $(compgen -W "$(rbenv commands)" -- "$word") ) else - local command="${COMP_WORDS[1]}" - local completions="$(rbenv completions "$command")" + local words=("${COMP_WORDS[@]}") + unset words[0] + unset words[$COMP_CWORD] + local completions=$(rbenv completions "${words[@]}") COMPREPLY=( $(compgen -W "$completions" -- "$word") ) fi } From 3060578e3b346fee7429aa4f0f2542693cb765f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohnic=CC=81?= Date: Thu, 13 Dec 2012 06:01:26 +0100 Subject: [PATCH 02/11] use `typeset` instead of `local` in rbenv() function This is to insure portability to ksh. Fixes #205, references #209 --- libexec/rbenv-init | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libexec/rbenv-init b/libexec/rbenv-init index 95b6c403..16916cd5 100755 --- a/libexec/rbenv-init +++ b/libexec/rbenv-init @@ -86,7 +86,8 @@ commands=(`rbenv-commands --sh`) IFS="|" cat < Date: Thu, 13 Dec 2012 11:22:06 -0600 Subject: [PATCH 03/11] Tweak `rbenv --version` output --- libexec/rbenv | 2 +- libexec/rbenv---version | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/libexec/rbenv b/libexec/rbenv index d368d459..76928647 100755 --- a/libexec/rbenv +++ b/libexec/rbenv @@ -60,7 +60,7 @@ shopt -u nullglob command="$1" case "$command" in "" | "-h" | "--help" ) - echo -e "rbenv $(rbenv---version)\n$(rbenv-help)" >&2 + echo -e "$(rbenv---version)\n$(rbenv-help)" >&2 ;; "-v" ) exec rbenv---version diff --git a/libexec/rbenv---version b/libexec/rbenv---version index fcf94d69..aa9b829d 100755 --- a/libexec/rbenv---version +++ b/libexec/rbenv---version @@ -2,9 +2,10 @@ set -e [ -n "$RBENV_DEBUG" ] && set -x -version=v0.3.0 +version=0.3.0 cd "$RBENV_ROOT" git_revision="$(git describe --tags HEAD 2>/dev/null || true)" +git_revision="${git_revision#v}" -echo ${git_revision:-$version} +echo "rbenv ${git_revision:-$version}" From c3fe192243bff9a00866d81af38d9012bfba419a Mon Sep 17 00:00:00 2001 From: Oscar Del Ben Date: Fri, 14 Dec 2012 08:42:10 -0800 Subject: [PATCH 04/11] use ruby-build Fixes #294 --- README.md | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 9b371758..d6b449c4 100644 --- a/README.md +++ b/README.md @@ -128,24 +128,16 @@ easy to fork and contribute any changes back upstream. $ exec $SHELL -l ~~~ -5. Install Ruby versions into `~/.rbenv/versions`. For example, to - manually compile Ruby [from source](https://github.com/ruby/ruby), - 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: +5. Install [ruby-build][], which provides an `rbenv install` + command that simplifies the process of installing new Ruby versions. ~~~ $ 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 a new Ruby binary (for example, when installing a new Ruby version, or when installing a gem that provides a binary). From 6c1fb9ffd062ff04607d2e0f486067eaf6e48d1e Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Thu, 27 Dec 2012 13:39:36 -0600 Subject: [PATCH 05/11] Fall back to $PWD if a local version file can't be found in $RBENV_DIR --- libexec/rbenv-version-file | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/libexec/rbenv-version-file b/libexec/rbenv-version-file index 9b678769..e9451f42 100755 --- a/libexec/rbenv-version-file +++ b/libexec/rbenv-version-file @@ -2,14 +2,19 @@ set -e [ -n "$RBENV_DEBUG" ] && set -x -root="$RBENV_DIR" -while [ -n "$root" ]; do - if [ -e "${root}/.rbenv-version" ]; then - echo "${root}/.rbenv-version" - exit - fi - root="${root%/*}" -done +find_local_version_file() { + local root="$1" + while [ -n "$root" ]; do + if [ -e "${root}/.rbenv-version" ]; then + echo "${root}/.rbenv-version" + exit + fi + root="${root%/*}" + done +} + +find_local_version_file "$RBENV_DIR" +[ "$RBENV_DIR" = "$PWD" ] || find_local_version_file "$PWD" global_version_file="${RBENV_ROOT}/version" From 283e67b57e8ab0bbbe504aab6866729b0035186a Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Thu, 27 Dec 2012 13:41:55 -0600 Subject: [PATCH 06/11] When the ruby shim is invoked with a script, set RBENV_DIR to the script's dirname --- libexec/rbenv-rehash | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/libexec/rbenv-rehash b/libexec/rbenv-rehash index eebc4d3c..2b5ffecc 100755 --- a/libexec/rbenv-rehash +++ b/libexec/rbenv-rehash @@ -37,8 +37,25 @@ create_prototype_shim() { cat > "$PROTOTYPE_SHIM_PATH" < Date: Thu, 27 Dec 2012 13:42:25 -0600 Subject: [PATCH 07/11] Ensure outdated shims are removed first when rehashing --- libexec/rbenv-rehash | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/libexec/rbenv-rehash b/libexec/rbenv-rehash index 2b5ffecc..a5c45756 100755 --- a/libexec/rbenv-rehash +++ b/libexec/rbenv-rehash @@ -60,6 +60,18 @@ SH 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 # registered for installation as a shim. In this way, plugins may call # `make_shims` with a glob to register many shims at once. @@ -146,10 +158,11 @@ remove_stale_shims() { # Change to the shims directory. cd "$SHIM_PATH" +shopt -s nullglob # Create the prototype shim, then register shims for all known binaries. create_prototype_shim -shopt -s nullglob +remove_outdated_shims make_shims ../versions/*/bin/* # Restore the previous working directory. From df9bbd7ab3be2ae44b598b25bd9d49bdf62cd809 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Thu, 27 Dec 2012 17:08:54 -0600 Subject: [PATCH 08/11] Speed up rbenv-rehash with a simpler indexing approach --- libexec/rbenv-rehash | 58 ++++++++++---------------------------------- 1 file changed, 13 insertions(+), 45 deletions(-) diff --git a/libexec/rbenv-rehash b/libexec/rbenv-rehash index eebc4d3c..a1d79864 100755 --- a/libexec/rbenv-rehash +++ b/libexec/rbenv-rehash @@ -55,58 +55,27 @@ make_shims() { 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_index="" # We will keep track of shims registered for installation with the -# global `reigstered_shims` array and with a global variable for each -# shim. The array will let us iterate over all registered shims. The -# global variables will let us quickly check whether a shim with the -# given name has been registered or not. +# global `reigstered_shims` array and with a global search index +# string. The array will let us iterate over all registered shims. The +# index string will let us quickly check whether a shim with the given +# name has been registered or not. register_shim() { local shim="$@" - local var="$(shim_variable_name "$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 Date: Fri, 28 Dec 2012 10:59:10 -0600 Subject: [PATCH 09/11] Run `hash -r` after `rbenv rehash` when shell integration is enabled Fixes #119 --- libexec/rbenv-sh-rehash | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100755 libexec/rbenv-sh-rehash diff --git a/libexec/rbenv-sh-rehash b/libexec/rbenv-sh-rehash new file mode 100755 index 00000000..9cc75265 --- /dev/null +++ b/libexec/rbenv-sh-rehash @@ -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" From f635c8715cd990fa6f066117c67240ac38ef9b46 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Fri, 28 Dec 2012 13:25:24 -0600 Subject: [PATCH 10/11] Add zsh support for completion of full command line --- completions/rbenv.zsh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/completions/rbenv.zsh b/completions/rbenv.zsh index 4739ac10..c439c5aa 100644 --- a/completions/rbenv.zsh +++ b/completions/rbenv.zsh @@ -5,14 +5,13 @@ fi compctl -K _rbenv rbenv _rbenv() { - local word words completions + local words completions read -cA words - word="${words[2]}" if [ "${#words}" -eq 2 ]; then completions="$(rbenv commands)" else - completions="$(rbenv completions "${word}")" + completions="$(rbenv completions ${words[2,-1]})" fi reply=("${(ps:\n:)completions}") From 8ee2f2657a088851d0aa75736c7b0305a10522f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohnic=CC=81?= Date: Sat, 29 Dec 2012 00:17:01 +0100 Subject: [PATCH 11/11] avoid prepending system ruby to PATH System ruby is already on PATH (that's the definition of system ruby) and by duplicating its path by putting it in front, we can break the user's environment. Fixes #275 --- libexec/rbenv-exec | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libexec/rbenv-exec b/libexec/rbenv-exec index 92ecb72b..5c1aacd8 100755 --- a/libexec/rbenv-exec +++ b/libexec/rbenv-exec @@ -7,7 +7,9 @@ if [ "$1" = "--complete" ]; then exec rbenv shims --short fi +export RBENV_VERSION="$(rbenv-version-name)" RBENV_COMMAND="$1" + if [ -z "$RBENV_COMMAND" ]; then echo "usage: rbenv exec COMMAND [arg1 arg2...]" >&2 exit 1 @@ -21,5 +23,7 @@ for script in $(rbenv-hooks exec); do done shift 1 -export PATH="${RBENV_BIN_PATH}:${PATH}" +if [ "$RBENV_VERSION" != "system" ]; then + export PATH="${RBENV_BIN_PATH}:${PATH}" +fi exec -a "$RBENV_COMMAND" "$RBENV_COMMAND_PATH" "$@"