From 99035a49a9c55d4a5ee67bdc7e372cc9221756c9 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Mon, 1 Aug 2011 15:50:26 -0500 Subject: [PATCH 001/384] Initial commit --- bin/rbenv | 18 ++++++++++++++++ bin/rbenv-exec | 14 +++++++++++++ bin/rbenv-rehash | 10 +++++++++ bin/rbenv-set-default | 15 ++++++++++++++ bin/rbenv-shim | 5 +++++ bin/rbenv-version | 48 +++++++++++++++++++++++++++++++++++++++++++ bin/rbenv-versions | 15 ++++++++++++++ bin/rbenv-which | 14 +++++++++++++ 8 files changed, 139 insertions(+) create mode 100755 bin/rbenv create mode 100755 bin/rbenv-exec create mode 100755 bin/rbenv-rehash create mode 100755 bin/rbenv-set-default create mode 100755 bin/rbenv-shim create mode 100755 bin/rbenv-version create mode 100755 bin/rbenv-versions create mode 100755 bin/rbenv-which diff --git a/bin/rbenv b/bin/rbenv new file mode 100755 index 00000000..6f3faab0 --- /dev/null +++ b/bin/rbenv @@ -0,0 +1,18 @@ +#!/bin/bash + +set -e + +command="$1" +if [ -z "$command" ]; then + echo "rbenv 0.1.0" >&2 + +else + command_path="$(command -v "rbenv-$command" || true)" + if [ -z "$command_path" ]; then + echo "rbenv: no such command \`$command'" >&2 + exit 1 + fi + + shift 1 + exec "$command_path" $* +fi diff --git a/bin/rbenv-exec b/bin/rbenv-exec new file mode 100755 index 00000000..77de1dec --- /dev/null +++ b/bin/rbenv-exec @@ -0,0 +1,14 @@ +#!/bin/bash + +set -e + +RBENV_COMMAND="$1" +if [ -z "$RBENV_COMMAND" ]; then + echo "usage: rbenv exec COMMAND [arg1 arg2...]" >&2 + exit 1 +fi + +RBENV_COMMAND_PATH="$(rbenv-which "$RBENV_COMMAND")" + +shift 1 +exec -a "$RBENV_COMMAND" "$RBENV_COMMAND_PATH" $* diff --git a/bin/rbenv-rehash b/bin/rbenv-rehash new file mode 100755 index 00000000..56cb8bd0 --- /dev/null +++ b/bin/rbenv-rehash @@ -0,0 +1,10 @@ +#!/bin/bash + +set -e + +cd "$HOME/.rbenv/shims" +rm * + +for file in ../versions/*/bin/*; do + ln -fs ../bin/rbenv-shim "${file##*/}" +done diff --git a/bin/rbenv-set-default b/bin/rbenv-set-default new file mode 100755 index 00000000..8567778e --- /dev/null +++ b/bin/rbenv-set-default @@ -0,0 +1,15 @@ +#!/bin/bash + +RBENV_VERSION="$1" +if [ -z "$RBENV_VERSION" ]; then + echo "usage: rbenv set-default VERSION" >&2 + exit 1 +fi + +RBENV_VERSION_PATH="${HOME}/.rbenv/versions/${RBENV_VERSION}" +if [ ! -d "$RBENV_VERSION_PATH" ]; then + echo "rbenv: version \`${RBENV_VERSION}' not installed" >&2 + exit 1 +fi + +echo "$RBENV_VERSION" > "${HOME}/.rbenv/default" diff --git a/bin/rbenv-shim b/bin/rbenv-shim new file mode 100755 index 00000000..36b2fc6e --- /dev/null +++ b/bin/rbenv-shim @@ -0,0 +1,5 @@ +#!/bin/bash + +set -e + +exec rbenv-exec "${0##*/}" $* diff --git a/bin/rbenv-version b/bin/rbenv-version new file mode 100755 index 00000000..b4366688 --- /dev/null +++ b/bin/rbenv-version @@ -0,0 +1,48 @@ +#!/bin/bash + +set -e + +read_version_file() { + egrep -m 1 '[^[:space:]]' "$1" +} + +find_version_file() { + root="$(pwd)" + while [ -n "$root" ]; do + if [ -e "${root}/.rbenv-version" ]; then + echo "${root}/.rbenv-version" + return 0 + fi + root="${root%/*}" + done + return 1 +} + +find_default_version_file() { + default_path="$HOME/.rbenv/default" + if [ -e "$default_path" ]; then + echo "$default_path" + return 0 + fi + return 1 +} + +if [ -z "$RBENV_VERSION" ]; then + RBENV_VERSION_FILE="$(find_version_file || find_default_version_file || true)" + + if [ -n "$RBENV_VERSION_FILE" ]; then + RBENV_VERSION="$(read_version_file "$RBENV_VERSION_FILE")" + else + echo "rbenv: no default version specified" >&2 + exit 1 + fi +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 diff --git a/bin/rbenv-versions b/bin/rbenv-versions new file mode 100755 index 00000000..2ae67e78 --- /dev/null +++ b/bin/rbenv-versions @@ -0,0 +1,15 @@ +#!/bin/bash + +RBENV_VERSION="$(rbenv-version)" + +for path in ~/.rbenv/versions/*; do + if [ -d "$path" ]; then + version="${path##*/}" + + if [ "$version" == "$RBENV_VERSION" ]; then + echo "* ${version##*/}" + else + echo " ${version##*/}" + fi + fi +done diff --git a/bin/rbenv-which b/bin/rbenv-which new file mode 100755 index 00000000..c14134e2 --- /dev/null +++ b/bin/rbenv-which @@ -0,0 +1,14 @@ +#!/bin/bash + +set -e + +RBENV_VERSION="$(rbenv-version)" +RBENV_COMMAND="$1" +RBENV_COMMAND_PATH="${HOME}/.rbenv/versions/${RBENV_VERSION}/bin/${RBENV_COMMAND}" + +if [ -x "$RBENV_COMMAND_PATH" ]; then + echo "$RBENV_COMMAND_PATH" +else + echo "rbenv: $1: command not found" >&2 + exit 127 +fi From 1da746543f3d774c27a7f1f5b2805d07c8626c73 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Mon, 1 Aug 2011 15:56:52 -0500 Subject: [PATCH 002/384] Add missing `set -e` --- bin/rbenv-set-default | 2 ++ bin/rbenv-versions | 2 ++ 2 files changed, 4 insertions(+) diff --git a/bin/rbenv-set-default b/bin/rbenv-set-default index 8567778e..6c0b7298 100755 --- a/bin/rbenv-set-default +++ b/bin/rbenv-set-default @@ -1,5 +1,7 @@ #!/bin/bash +set -e + RBENV_VERSION="$1" if [ -z "$RBENV_VERSION" ]; then echo "usage: rbenv set-default VERSION" >&2 diff --git a/bin/rbenv-versions b/bin/rbenv-versions index 2ae67e78..0a2b5a0b 100755 --- a/bin/rbenv-versions +++ b/bin/rbenv-versions @@ -1,5 +1,7 @@ #!/bin/bash +set -e + RBENV_VERSION="$(rbenv-version)" for path in ~/.rbenv/versions/*; do From af6b06743bd05512385480d0cac9fa9beceb3226 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Mon, 1 Aug 2011 16:22:26 -0500 Subject: [PATCH 003/384] Extract rbenv-path --- bin/rbenv-path | 15 +++++++++++++++ bin/rbenv-set-default | 7 ++----- 2 files changed, 17 insertions(+), 5 deletions(-) create mode 100755 bin/rbenv-path diff --git a/bin/rbenv-path b/bin/rbenv-path new file mode 100755 index 00000000..aefb3eba --- /dev/null +++ b/bin/rbenv-path @@ -0,0 +1,15 @@ +#!/bin/bash + +if [ -n "$1" ]; then + RBENV_VERSION="$1" +elif [ -z "$RBENV_VERSION" ]; then + RBENV_VERSION="$(rbenv-version)" +fi + +RBENV_VERSION_PATH="${HOME}/.rbenv/versions/${RBENV_VERSION}" +if [ ! -d "$RBENV_VERSION_PATH" ]; then + echo "rbenv: version \`${RBENV_VERSION}' not installed" >&2 + exit 1 +fi + +echo "$RBENV_VERSION_PATH" diff --git a/bin/rbenv-set-default b/bin/rbenv-set-default index 6c0b7298..0632747a 100755 --- a/bin/rbenv-set-default +++ b/bin/rbenv-set-default @@ -8,10 +8,7 @@ if [ -z "$RBENV_VERSION" ]; then exit 1 fi -RBENV_VERSION_PATH="${HOME}/.rbenv/versions/${RBENV_VERSION}" -if [ ! -d "$RBENV_VERSION_PATH" ]; then - echo "rbenv: version \`${RBENV_VERSION}' not installed" >&2 - exit 1 -fi +# Make sure the specified version is installed +rbenv-path "$RBENV_VERSION" >/dev/null echo "$RBENV_VERSION" > "${HOME}/.rbenv/default" From 6ec91083d878bfbf84733c0054e319596adb936b Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Mon, 1 Aug 2011 16:22:35 -0500 Subject: [PATCH 004/384] Add rbenv-set-local --- bin/rbenv-set-local | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100755 bin/rbenv-set-local diff --git a/bin/rbenv-set-local b/bin/rbenv-set-local new file mode 100755 index 00000000..0f2a1bf5 --- /dev/null +++ b/bin/rbenv-set-local @@ -0,0 +1,14 @@ +#!/bin/bash + +set -e + +RBENV_VERSION="$1" +if [ -z "$RBENV_VERSION" ]; then + echo "usage: rbenv set-local VERSION" >&2 + exit 1 +fi + +# Make sure the specified version is installed +rbenv-path "$RBENV_VERSION" >/dev/null + +echo "$RBENV_VERSION" > .rbenv-version From b5d030bee7083cb18469c4d82aa2e2d808db0bd6 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Mon, 1 Aug 2011 16:39:00 -0500 Subject: [PATCH 005/384] -e --- bin/rbenv-path | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bin/rbenv-path b/bin/rbenv-path index aefb3eba..ba77369b 100755 --- a/bin/rbenv-path +++ b/bin/rbenv-path @@ -1,5 +1,7 @@ #!/bin/bash +set -e + if [ -n "$1" ]; then RBENV_VERSION="$1" elif [ -z "$RBENV_VERSION" ]; then From 0c66f62c17bd661f5153d6d8f288978560576606 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Mon, 1 Aug 2011 16:43:19 -0500 Subject: [PATCH 006/384] Style --- bin/rbenv-rehash | 2 +- bin/rbenv-versions | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bin/rbenv-rehash b/bin/rbenv-rehash index 56cb8bd0..33b3fc19 100755 --- a/bin/rbenv-rehash +++ b/bin/rbenv-rehash @@ -2,7 +2,7 @@ set -e -cd "$HOME/.rbenv/shims" +cd "${HOME}/.rbenv/shims" rm * for file in ../versions/*/bin/*; do diff --git a/bin/rbenv-versions b/bin/rbenv-versions index 0a2b5a0b..97f217c2 100755 --- a/bin/rbenv-versions +++ b/bin/rbenv-versions @@ -9,9 +9,9 @@ for path in ~/.rbenv/versions/*; do version="${path##*/}" if [ "$version" == "$RBENV_VERSION" ]; then - echo "* ${version##*/}" + echo "* $version" else - echo " ${version##*/}" + echo " $version" fi fi done From 4acefd6ef95701c6e2a00022ee152d8730c251cf Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Tue, 2 Aug 2011 09:38:36 -0500 Subject: [PATCH 007/384] Properly quote arguments with spaces --- bin/rbenv-exec | 2 +- bin/rbenv-shim | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/rbenv-exec b/bin/rbenv-exec index 77de1dec..59a122b8 100755 --- a/bin/rbenv-exec +++ b/bin/rbenv-exec @@ -11,4 +11,4 @@ fi RBENV_COMMAND_PATH="$(rbenv-which "$RBENV_COMMAND")" shift 1 -exec -a "$RBENV_COMMAND" "$RBENV_COMMAND_PATH" $* +exec -a "$RBENV_COMMAND" "$RBENV_COMMAND_PATH" "$@" diff --git a/bin/rbenv-shim b/bin/rbenv-shim index 36b2fc6e..b2341800 100755 --- a/bin/rbenv-shim +++ b/bin/rbenv-shim @@ -2,4 +2,4 @@ set -e -exec rbenv-exec "${0##*/}" $* +exec rbenv-exec "${0##*/}" "$@" From fb31290b9d74ae61feb37632ea65c3e3c304e5a7 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Tue, 2 Aug 2011 12:21:09 -0500 Subject: [PATCH 008/384] More argument quoting --- bin/rbenv | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/rbenv b/bin/rbenv index 6f3faab0..c9519604 100755 --- a/bin/rbenv +++ b/bin/rbenv @@ -14,5 +14,5 @@ else fi shift 1 - exec "$command_path" $* + exec "$command_path" "$@" fi From 8246dc8d8a227dd86f3dfce2de71411d9dc814a8 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Tue, 2 Aug 2011 12:21:30 -0500 Subject: [PATCH 009/384] Avoid globals --- bin/rbenv-version | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/rbenv-version b/bin/rbenv-version index b4366688..605c7552 100755 --- a/bin/rbenv-version +++ b/bin/rbenv-version @@ -7,7 +7,7 @@ read_version_file() { } find_version_file() { - root="$(pwd)" + local root="$(pwd)" while [ -n "$root" ]; do if [ -e "${root}/.rbenv-version" ]; then echo "${root}/.rbenv-version" @@ -19,7 +19,7 @@ find_version_file() { } find_default_version_file() { - default_path="$HOME/.rbenv/default" + local default_path="$HOME/.rbenv/default" if [ -e "$default_path" ]; then echo "$default_path" return 0 From 355e7c1c969aa662a3c40d67e5f04b5ae1c40bb1 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Tue, 2 Aug 2011 15:23:26 -0500 Subject: [PATCH 010/384] Create ~/.rbenv/shims if it doesn't exist --- bin/rbenv-rehash | 1 + 1 file changed, 1 insertion(+) diff --git a/bin/rbenv-rehash b/bin/rbenv-rehash index 33b3fc19..f0435238 100755 --- a/bin/rbenv-rehash +++ b/bin/rbenv-rehash @@ -2,6 +2,7 @@ set -e +mkdir -p "${HOME}/.rbenv/shims" cd "${HOME}/.rbenv/shims" rm * From e9881119d833dae7d73b2e07c200df0d455a6e34 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Tue, 2 Aug 2011 15:25:37 -0500 Subject: [PATCH 011/384] Ignore local files --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..3c6bb8d9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/versions +/shims +/default From 41c5ac5a33ec8b67578c972ae884a0e463116d4d Mon Sep 17 00:00:00 2001 From: Jamis Buck Date: Wed, 3 Aug 2011 04:25:23 +0800 Subject: [PATCH 012/384] the initial case has an empty directory, so force rm to avoid errors --- bin/rbenv-rehash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/rbenv-rehash b/bin/rbenv-rehash index f0435238..692cfacc 100755 --- a/bin/rbenv-rehash +++ b/bin/rbenv-rehash @@ -4,7 +4,7 @@ set -e mkdir -p "${HOME}/.rbenv/shims" cd "${HOME}/.rbenv/shims" -rm * +rm -f * for file in ../versions/*/bin/*; do ln -fs ../bin/rbenv-shim "${file##*/}" From c957d83b3a7b0f07afc64f9c8157e159883ae06f Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 2 Aug 2011 17:43:43 -0500 Subject: [PATCH 013/384] Shebang -e flag --- bin/rbenv | 4 +--- bin/rbenv-exec | 4 +--- bin/rbenv-path | 4 +--- bin/rbenv-rehash | 4 +--- bin/rbenv-set-default | 4 +--- bin/rbenv-set-local | 4 +--- bin/rbenv-shim | 4 +--- bin/rbenv-version | 4 +--- bin/rbenv-versions | 4 +--- bin/rbenv-which | 4 +--- 10 files changed, 10 insertions(+), 30 deletions(-) diff --git a/bin/rbenv b/bin/rbenv index c9519604..30f1a189 100755 --- a/bin/rbenv +++ b/bin/rbenv @@ -1,6 +1,4 @@ -#!/bin/bash - -set -e +#!/bin/bash -e command="$1" if [ -z "$command" ]; then diff --git a/bin/rbenv-exec b/bin/rbenv-exec index 59a122b8..16039d85 100755 --- a/bin/rbenv-exec +++ b/bin/rbenv-exec @@ -1,6 +1,4 @@ -#!/bin/bash - -set -e +#!/bin/bash -e RBENV_COMMAND="$1" if [ -z "$RBENV_COMMAND" ]; then diff --git a/bin/rbenv-path b/bin/rbenv-path index ba77369b..a37c9edc 100755 --- a/bin/rbenv-path +++ b/bin/rbenv-path @@ -1,6 +1,4 @@ -#!/bin/bash - -set -e +#!/bin/bash -e if [ -n "$1" ]; then RBENV_VERSION="$1" diff --git a/bin/rbenv-rehash b/bin/rbenv-rehash index 692cfacc..8bbd53b6 100755 --- a/bin/rbenv-rehash +++ b/bin/rbenv-rehash @@ -1,6 +1,4 @@ -#!/bin/bash - -set -e +#!/bin/bash -e mkdir -p "${HOME}/.rbenv/shims" cd "${HOME}/.rbenv/shims" diff --git a/bin/rbenv-set-default b/bin/rbenv-set-default index 0632747a..a36f2319 100755 --- a/bin/rbenv-set-default +++ b/bin/rbenv-set-default @@ -1,6 +1,4 @@ -#!/bin/bash - -set -e +#!/bin/bash -e RBENV_VERSION="$1" if [ -z "$RBENV_VERSION" ]; then diff --git a/bin/rbenv-set-local b/bin/rbenv-set-local index 0f2a1bf5..59512db1 100755 --- a/bin/rbenv-set-local +++ b/bin/rbenv-set-local @@ -1,6 +1,4 @@ -#!/bin/bash - -set -e +#!/bin/bash -e RBENV_VERSION="$1" if [ -z "$RBENV_VERSION" ]; then diff --git a/bin/rbenv-shim b/bin/rbenv-shim index b2341800..0acca18f 100755 --- a/bin/rbenv-shim +++ b/bin/rbenv-shim @@ -1,5 +1,3 @@ -#!/bin/bash - -set -e +#!/bin/bash -e exec rbenv-exec "${0##*/}" "$@" diff --git a/bin/rbenv-version b/bin/rbenv-version index 605c7552..1337e367 100755 --- a/bin/rbenv-version +++ b/bin/rbenv-version @@ -1,6 +1,4 @@ -#!/bin/bash - -set -e +#!/bin/bash -e read_version_file() { egrep -m 1 '[^[:space:]]' "$1" diff --git a/bin/rbenv-versions b/bin/rbenv-versions index 97f217c2..b3faad6f 100755 --- a/bin/rbenv-versions +++ b/bin/rbenv-versions @@ -1,6 +1,4 @@ -#!/bin/bash - -set -e +#!/bin/bash -e RBENV_VERSION="$(rbenv-version)" diff --git a/bin/rbenv-which b/bin/rbenv-which index c14134e2..cb63d8d5 100755 --- a/bin/rbenv-which +++ b/bin/rbenv-which @@ -1,6 +1,4 @@ -#!/bin/bash - -set -e +#!/bin/bash -e RBENV_VERSION="$(rbenv-version)" RBENV_COMMAND="$1" From 43624943eec6576a4824d2ef0ad15167ce75688a Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 2 Aug 2011 18:01:46 -0500 Subject: [PATCH 014/384] Move subcommands into libexec/ --- bin/rbenv | 17 +-------------- libexec/rbenv | 34 ++++++++++++++++++++++++++++++ {bin => libexec}/rbenv-exec | 0 {bin => libexec}/rbenv-path | 0 {bin => libexec}/rbenv-rehash | 0 {bin => libexec}/rbenv-set-default | 0 {bin => libexec}/rbenv-set-local | 0 {bin => libexec}/rbenv-shim | 0 {bin => libexec}/rbenv-version | 0 {bin => libexec}/rbenv-versions | 0 {bin => libexec}/rbenv-which | 0 11 files changed, 35 insertions(+), 16 deletions(-) mode change 100755 => 120000 bin/rbenv create mode 100755 libexec/rbenv rename {bin => libexec}/rbenv-exec (100%) rename {bin => libexec}/rbenv-path (100%) rename {bin => libexec}/rbenv-rehash (100%) rename {bin => libexec}/rbenv-set-default (100%) rename {bin => libexec}/rbenv-set-local (100%) rename {bin => libexec}/rbenv-shim (100%) rename {bin => libexec}/rbenv-version (100%) rename {bin => libexec}/rbenv-versions (100%) rename {bin => libexec}/rbenv-which (100%) diff --git a/bin/rbenv b/bin/rbenv deleted file mode 100755 index 30f1a189..00000000 --- a/bin/rbenv +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash -e - -command="$1" -if [ -z "$command" ]; then - echo "rbenv 0.1.0" >&2 - -else - command_path="$(command -v "rbenv-$command" || true)" - if [ -z "$command_path" ]; then - echo "rbenv: no such command \`$command'" >&2 - exit 1 - fi - - shift 1 - exec "$command_path" "$@" -fi diff --git a/bin/rbenv b/bin/rbenv new file mode 120000 index 00000000..f1e9c5f4 --- /dev/null +++ b/bin/rbenv @@ -0,0 +1 @@ +../libexec/rbenv \ No newline at end of file diff --git a/libexec/rbenv b/libexec/rbenv new file mode 100755 index 00000000..253d08bc --- /dev/null +++ b/libexec/rbenv @@ -0,0 +1,34 @@ +#!/bin/bash -e + +abs_dirname() { + orig_dir=`pwd` + path="$1" + while [ -n "$path" ]; do + cd `dirname "$path"` + name=`basename "$path"` + path=`readlink "$name" || true` + done + unset name path + + pwd + cd "$orig_dir" + unset orig_dir +} + +bindir=`abs_dirname $0` +export PATH="$bindir:$PATH" + +command="$1" +if [ -z "$command" ]; then + echo "rbenv 0.1.0" >&2 + +else + command_path="$(command -v "rbenv-$command" || true)" + if [ -z "$command_path" ]; then + echo "rbenv: no such command \`$command'" >&2 + exit 1 + fi + + shift 1 + exec "$command_path" "$@" +fi diff --git a/bin/rbenv-exec b/libexec/rbenv-exec similarity index 100% rename from bin/rbenv-exec rename to libexec/rbenv-exec diff --git a/bin/rbenv-path b/libexec/rbenv-path similarity index 100% rename from bin/rbenv-path rename to libexec/rbenv-path diff --git a/bin/rbenv-rehash b/libexec/rbenv-rehash similarity index 100% rename from bin/rbenv-rehash rename to libexec/rbenv-rehash diff --git a/bin/rbenv-set-default b/libexec/rbenv-set-default similarity index 100% rename from bin/rbenv-set-default rename to libexec/rbenv-set-default diff --git a/bin/rbenv-set-local b/libexec/rbenv-set-local similarity index 100% rename from bin/rbenv-set-local rename to libexec/rbenv-set-local diff --git a/bin/rbenv-shim b/libexec/rbenv-shim similarity index 100% rename from bin/rbenv-shim rename to libexec/rbenv-shim diff --git a/bin/rbenv-version b/libexec/rbenv-version similarity index 100% rename from bin/rbenv-version rename to libexec/rbenv-version diff --git a/bin/rbenv-versions b/libexec/rbenv-versions similarity index 100% rename from bin/rbenv-versions rename to libexec/rbenv-versions diff --git a/bin/rbenv-which b/libexec/rbenv-which similarity index 100% rename from bin/rbenv-which rename to libexec/rbenv-which From ad2c605d3f4c4f6857157175c0ef674cd4457c13 Mon Sep 17 00:00:00 2001 From: Peter Aronoff Date: Tue, 2 Aug 2011 19:11:41 -0400 Subject: [PATCH 015/384] Use /usr/bin/env rather than /bin/bash --- bin/rbenv | 2 +- bin/rbenv-exec | 2 +- bin/rbenv-path | 2 +- bin/rbenv-rehash | 2 +- bin/rbenv-set-default | 2 +- bin/rbenv-set-local | 2 +- bin/rbenv-shim | 2 +- bin/rbenv-version | 2 +- bin/rbenv-versions | 2 +- bin/rbenv-which | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/bin/rbenv b/bin/rbenv index 30f1a189..11e9bdc3 100755 --- a/bin/rbenv +++ b/bin/rbenv @@ -1,4 +1,4 @@ -#!/bin/bash -e +#!/usr/bin/env bash -e command="$1" if [ -z "$command" ]; then diff --git a/bin/rbenv-exec b/bin/rbenv-exec index 16039d85..ffd911b9 100755 --- a/bin/rbenv-exec +++ b/bin/rbenv-exec @@ -1,4 +1,4 @@ -#!/bin/bash -e +#!/usr/bin/env bash -e RBENV_COMMAND="$1" if [ -z "$RBENV_COMMAND" ]; then diff --git a/bin/rbenv-path b/bin/rbenv-path index a37c9edc..a60c806b 100755 --- a/bin/rbenv-path +++ b/bin/rbenv-path @@ -1,4 +1,4 @@ -#!/bin/bash -e +#!/usr/bin/env bash -e if [ -n "$1" ]; then RBENV_VERSION="$1" diff --git a/bin/rbenv-rehash b/bin/rbenv-rehash index 8bbd53b6..854bd050 100755 --- a/bin/rbenv-rehash +++ b/bin/rbenv-rehash @@ -1,4 +1,4 @@ -#!/bin/bash -e +#!/usr/bin/env bash -e mkdir -p "${HOME}/.rbenv/shims" cd "${HOME}/.rbenv/shims" diff --git a/bin/rbenv-set-default b/bin/rbenv-set-default index a36f2319..a1922a76 100755 --- a/bin/rbenv-set-default +++ b/bin/rbenv-set-default @@ -1,4 +1,4 @@ -#!/bin/bash -e +#!/usr/bin/env bash -e RBENV_VERSION="$1" if [ -z "$RBENV_VERSION" ]; then diff --git a/bin/rbenv-set-local b/bin/rbenv-set-local index 59512db1..38406232 100755 --- a/bin/rbenv-set-local +++ b/bin/rbenv-set-local @@ -1,4 +1,4 @@ -#!/bin/bash -e +#!/usr/bin/env bash -e RBENV_VERSION="$1" if [ -z "$RBENV_VERSION" ]; then diff --git a/bin/rbenv-shim b/bin/rbenv-shim index 0acca18f..1c0bc525 100755 --- a/bin/rbenv-shim +++ b/bin/rbenv-shim @@ -1,3 +1,3 @@ -#!/bin/bash -e +#!/usr/bin/env bash -e exec rbenv-exec "${0##*/}" "$@" diff --git a/bin/rbenv-version b/bin/rbenv-version index 1337e367..01c1afdf 100755 --- a/bin/rbenv-version +++ b/bin/rbenv-version @@ -1,4 +1,4 @@ -#!/bin/bash -e +#!/usr/bin/env bash -e read_version_file() { egrep -m 1 '[^[:space:]]' "$1" diff --git a/bin/rbenv-versions b/bin/rbenv-versions index b3faad6f..6b848c07 100755 --- a/bin/rbenv-versions +++ b/bin/rbenv-versions @@ -1,4 +1,4 @@ -#!/bin/bash -e +#!/usr/bin/env bash -e RBENV_VERSION="$(rbenv-version)" diff --git a/bin/rbenv-which b/bin/rbenv-which index cb63d8d5..0e05c81b 100755 --- a/bin/rbenv-which +++ b/bin/rbenv-which @@ -1,4 +1,4 @@ -#!/bin/bash -e +#!/usr/bin/env bash -e RBENV_VERSION="$(rbenv-version)" RBENV_COMMAND="$1" From 06228d3583e24b5057516f357f7d0ae802153007 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 2 Aug 2011 18:50:44 -0500 Subject: [PATCH 016/384] Copies bins into shims/ instead of symlinking Fixes #6 --- bin/rbenv-rehash | 7 ++++++- bin/rbenv-shim | 3 --- 2 files changed, 6 insertions(+), 4 deletions(-) delete mode 100755 bin/rbenv-shim diff --git a/bin/rbenv-rehash b/bin/rbenv-rehash index 8bbd53b6..7344a687 100755 --- a/bin/rbenv-rehash +++ b/bin/rbenv-rehash @@ -5,5 +5,10 @@ cd "${HOME}/.rbenv/shims" rm -f * for file in ../versions/*/bin/*; do - ln -fs ../bin/rbenv-shim "${file##*/}" + shim="${file##*/}" + cat > "$shim" < Date: Tue, 2 Aug 2011 18:55:14 -0500 Subject: [PATCH 017/384] Use $shim var --- bin/rbenv-rehash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/rbenv-rehash b/bin/rbenv-rehash index 7344a687..7f1e9918 100755 --- a/bin/rbenv-rehash +++ b/bin/rbenv-rehash @@ -8,7 +8,7 @@ for file in ../versions/*/bin/*; do shim="${file##*/}" cat > "$shim" < Date: Tue, 2 Aug 2011 19:37:18 -0500 Subject: [PATCH 018/384] Quote `$@` --- bin/rbenv-rehash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) mode change 100755 => 100644 bin/rbenv-rehash diff --git a/bin/rbenv-rehash b/bin/rbenv-rehash old mode 100755 new mode 100644 index 7f1e9918..1d42bce9 --- a/bin/rbenv-rehash +++ b/bin/rbenv-rehash @@ -8,7 +8,7 @@ for file in ../versions/*/bin/*; do shim="${file##*/}" cat > "$shim" < Date: Tue, 2 Aug 2011 19:49:41 -0500 Subject: [PATCH 019/384] Fix permissions on rehash --- bin/rbenv-rehash | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 bin/rbenv-rehash diff --git a/bin/rbenv-rehash b/bin/rbenv-rehash old mode 100644 new mode 100755 From 735a2bc4e734257df9fdc5e3c398484d98eee0cc Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Tue, 2 Aug 2011 23:05:24 -0500 Subject: [PATCH 020/384] Consistent style --- libexec/rbenv | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/libexec/rbenv b/libexec/rbenv index 16e57108..31a2d242 100755 --- a/libexec/rbenv +++ b/libexec/rbenv @@ -1,22 +1,21 @@ #!/usr/bin/env bash -e abs_dirname() { - orig_dir=`pwd` - path="$1" + local cwd="$(pwd)" + local path="$1" + while [ -n "$path" ]; do - cd `dirname "$path"` - name=`basename "$path"` - path=`readlink "$name" || true` + cd "$(dirname "$path")" + local name="$(basename "$path")" + path="$(readlink "$name" || true)" done - unset name path pwd - cd "$orig_dir" - unset orig_dir + cd "$cwd" } -bindir=`abs_dirname $0` -export PATH="$bindir:$PATH" +libexec_path="$(abs_dirname "$0")" +export PATH="${libexec_path}:${PATH}" command="$1" if [ -z "$command" ]; then From 86362408f106f99e9da382a9d5abe26ca5256d9f Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Tue, 2 Aug 2011 23:11:10 -0500 Subject: [PATCH 021/384] rbenv-path -> rbenv-prefix --- libexec/{rbenv-path => rbenv-prefix} | 6 +++--- libexec/rbenv-set-default | 2 +- libexec/rbenv-set-local | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) rename libexec/{rbenv-path => rbenv-prefix} (62%) diff --git a/libexec/rbenv-path b/libexec/rbenv-prefix similarity index 62% rename from libexec/rbenv-path rename to libexec/rbenv-prefix index a60c806b..f2823b31 100755 --- a/libexec/rbenv-path +++ b/libexec/rbenv-prefix @@ -6,10 +6,10 @@ elif [ -z "$RBENV_VERSION" ]; then RBENV_VERSION="$(rbenv-version)" fi -RBENV_VERSION_PATH="${HOME}/.rbenv/versions/${RBENV_VERSION}" -if [ ! -d "$RBENV_VERSION_PATH" ]; then +RBENV_PREFIX_PATH="${HOME}/.rbenv/versions/${RBENV_VERSION}" +if [ ! -d "$RBENV_PREFIX_PATH" ]; then echo "rbenv: version \`${RBENV_VERSION}' not installed" >&2 exit 1 fi -echo "$RBENV_VERSION_PATH" +echo "$RBENV_PREFIX_PATH" diff --git a/libexec/rbenv-set-default b/libexec/rbenv-set-default index a1922a76..e1d65e2d 100755 --- a/libexec/rbenv-set-default +++ b/libexec/rbenv-set-default @@ -7,6 +7,6 @@ if [ -z "$RBENV_VERSION" ]; then fi # Make sure the specified version is installed -rbenv-path "$RBENV_VERSION" >/dev/null +rbenv-prefix "$RBENV_VERSION" >/dev/null echo "$RBENV_VERSION" > "${HOME}/.rbenv/default" diff --git a/libexec/rbenv-set-local b/libexec/rbenv-set-local index 38406232..a051c709 100755 --- a/libexec/rbenv-set-local +++ b/libexec/rbenv-set-local @@ -7,6 +7,6 @@ if [ -z "$RBENV_VERSION" ]; then fi # Make sure the specified version is installed -rbenv-path "$RBENV_VERSION" >/dev/null +rbenv-prefix "$RBENV_VERSION" >/dev/null echo "$RBENV_VERSION" > .rbenv-version From 652135db7fc64377b6c0eef0e50ad1c7d8924553 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Tue, 2 Aug 2011 23:19:37 -0500 Subject: [PATCH 022/384] Add --bare option to rbenv-versions --- libexec/rbenv-versions | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/libexec/rbenv-versions b/libexec/rbenv-versions index 6b848c07..e69c751f 100755 --- a/libexec/rbenv-versions +++ b/libexec/rbenv-versions @@ -2,14 +2,22 @@ RBENV_VERSION="$(rbenv-version)" -for path in ~/.rbenv/versions/*; do +hit_prefix="* " +miss_prefix=" " + +if [ "$1" = "--bare" ]; then + hit_prefix="" + miss_prefix="" +fi + +for path in "${HOME}/.rbenv/versions/"*; do if [ -d "$path" ]; then version="${path##*/}" if [ "$version" == "$RBENV_VERSION" ]; then - echo "* $version" + echo "${hit_prefix}${version}" else - echo " $version" + echo "${miss_prefix}${version}" fi fi done From d257b562e54393ad37c5f58a39fe7512cc1abcb0 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Tue, 2 Aug 2011 23:31:19 -0500 Subject: [PATCH 023/384] Add rbenv-whence to show you which versions of Ruby have a given command --- libexec/rbenv-whence | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100755 libexec/rbenv-whence diff --git a/libexec/rbenv-whence b/libexec/rbenv-whence new file mode 100755 index 00000000..30613eed --- /dev/null +++ b/libexec/rbenv-whence @@ -0,0 +1,22 @@ +#!/usr/bin/env bash -e + +if [ "$1" = "--path" ]; then + print_paths="1" + shift +else + print_paths="" +fi + +whence() { + local command="$1" + rbenv-versions --bare | while read version; do + path="$(rbenv-prefix "$version")/bin/${command}" + if [ -x "$path" ]; then + [ "$print_paths" ] && echo "$path" || echo "$version" + fi + done +} + +RBENV_COMMAND="$1" +result="$(whence "$RBENV_COMMAND")" +[ -n "$result" ] && echo "$result" From a62bd23ba2c66f296ea4fc344dfc41486d290e1c Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Tue, 2 Aug 2011 23:53:23 -0500 Subject: [PATCH 024/384] Show which versions of Ruby have a command installed when rbenv-which fails --- libexec/rbenv-which | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/libexec/rbenv-which b/libexec/rbenv-which index 0e05c81b..7f308e2d 100755 --- a/libexec/rbenv-which +++ b/libexec/rbenv-which @@ -7,6 +7,16 @@ RBENV_COMMAND_PATH="${HOME}/.rbenv/versions/${RBENV_VERSION}/bin/${RBENV_COMMAND if [ -x "$RBENV_COMMAND_PATH" ]; then echo "$RBENV_COMMAND_PATH" else - echo "rbenv: $1: command not found" >&2 + echo "rbenv: $RBENV_COMMAND: command not found" >&2 + + versions="$(rbenv-whence "$RBENV_COMMAND" || true)" + if [ -n "$versions" ]; then + { echo + echo "The \`$1' command exists in these Ruby versions:" + echo "$versions" | sed 's/^/ /g' + echo + } >&2 + fi + exit 127 fi From 4668a2e2ed8c8dfcd935247a4e5dcf26a35f63ac Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Wed, 3 Aug 2011 00:06:23 -0500 Subject: [PATCH 025/384] rbenv-whence requires a command argument --- libexec/rbenv-whence | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libexec/rbenv-whence b/libexec/rbenv-whence index 30613eed..b6809a56 100755 --- a/libexec/rbenv-whence +++ b/libexec/rbenv-whence @@ -18,5 +18,10 @@ whence() { } RBENV_COMMAND="$1" +if [ -z "$RBENV_COMMAND" ]; then + echo "usage: rbenv whence [--path] COMMAND" >&2 + exit 1 +fi + result="$(whence "$RBENV_COMMAND")" [ -n "$result" ] && echo "$result" From a9837f3a066f6a2a7898ddb281a5ff34e1750df1 Mon Sep 17 00:00:00 2001 From: Jamis Buck Date: Wed, 3 Aug 2011 07:28:50 -0600 Subject: [PATCH 026/384] look for plugin scripts to extend functionality --- libexec/rbenv-exec | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libexec/rbenv-exec b/libexec/rbenv-exec index ffd911b9..5bd4e8c5 100755 --- a/libexec/rbenv-exec +++ b/libexec/rbenv-exec @@ -8,5 +8,13 @@ fi RBENV_COMMAND_PATH="$(rbenv-which "$RBENV_COMMAND")" +shopt -s nullglob +RBENV_EXEC_PLUGINS=(/etc/rbenv.d/exec/*.bash ${HOME}/.rbenv/rbenv.d/exec/*.bash) +shopt -u nullglob + +for script in $RBENV_EXEC_PLUGINS; do + source $script +done + shift 1 exec -a "$RBENV_COMMAND" "$RBENV_COMMAND_PATH" "$@" From e0e2d936393e04550647419b8c6da7c633887244 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Wed, 3 Aug 2011 08:39:56 -0500 Subject: [PATCH 027/384] Add support for RBENV_VERSION=system --- libexec/rbenv-prefix | 6 ++++++ libexec/rbenv-version | 5 +++++ libexec/rbenv-which | 29 ++++++++++++++++++++++++++++- 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/libexec/rbenv-prefix b/libexec/rbenv-prefix index f2823b31..9d17ee42 100755 --- a/libexec/rbenv-prefix +++ b/libexec/rbenv-prefix @@ -6,6 +6,12 @@ elif [ -z "$RBENV_VERSION" ]; then RBENV_VERSION="$(rbenv-version)" fi +if [ "$RBENV_VERSION" = "system" ]; then + RUBY_PATH="$(rbenv-which ruby)" + echo "${RUBY_PATH%/*}" + exit +fi + RBENV_PREFIX_PATH="${HOME}/.rbenv/versions/${RBENV_VERSION}" if [ ! -d "$RBENV_PREFIX_PATH" ]; then echo "rbenv: version \`${RBENV_VERSION}' not installed" >&2 diff --git a/libexec/rbenv-version b/libexec/rbenv-version index 01c1afdf..2c9cae13 100755 --- a/libexec/rbenv-version +++ b/libexec/rbenv-version @@ -36,6 +36,11 @@ if [ -z "$RBENV_VERSION" ]; then 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 diff --git a/libexec/rbenv-which b/libexec/rbenv-which index 7f308e2d..42dde049 100755 --- a/libexec/rbenv-which +++ b/libexec/rbenv-which @@ -1,8 +1,35 @@ #!/usr/bin/env bash -e +expand_path() { + local cwd="$(pwd)" + cd "$1" + pwd + cd "$cwd" +} + +remove_from_path() { + local path_to_remove="$(expand_path "$1")" + local result="" + + for path in ${PATH//:/$'\n'}; do + path="$(expand_path "$path" || true)" + if [ "$path" != "$path_to_remove" ]; then + result="${result}${path}:" + fi + done + + echo "${result%:}" +} + RBENV_VERSION="$(rbenv-version)" RBENV_COMMAND="$1" -RBENV_COMMAND_PATH="${HOME}/.rbenv/versions/${RBENV_VERSION}/bin/${RBENV_COMMAND}" + +if [ "$RBENV_VERSION" = "system" ]; then + PATH="$(remove_from_path "${HOME}/.rbenv/shims")" + RBENV_COMMAND_PATH="$(command -v "$RBENV_COMMAND")" +else + RBENV_COMMAND_PATH="${HOME}/.rbenv/versions/${RBENV_VERSION}/bin/${RBENV_COMMAND}" +fi if [ -x "$RBENV_COMMAND_PATH" ]; then echo "$RBENV_COMMAND_PATH" From b6ebc2f08bd36a8eeaac93719b6b1b3bae7d0f00 Mon Sep 17 00:00:00 2001 From: Jamis Buck Date: Wed, 3 Aug 2011 11:17:28 -0600 Subject: [PATCH 028/384] look for plugins to extend rehash and which --- libexec/rbenv-rehash | 28 +++++++++++++++++++++------- libexec/rbenv-which | 8 ++++++++ 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/libexec/rbenv-rehash b/libexec/rbenv-rehash index c0096616..96305478 100755 --- a/libexec/rbenv-rehash +++ b/libexec/rbenv-rehash @@ -1,14 +1,28 @@ #!/usr/bin/env bash -e +make_shims() { + local glob="$@" + + for file in $glob; do + local shim="${file##*/}" + cat > "$shim" < "$shim" < Date: Wed, 3 Aug 2011 20:04:42 -0400 Subject: [PATCH 029/384] Use parameter expansion for basename + dirname These are built-ins, and they're used elsewhere in the code. --- libexec/rbenv | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libexec/rbenv b/libexec/rbenv index 31a2d242..66d8c438 100755 --- a/libexec/rbenv +++ b/libexec/rbenv @@ -5,8 +5,8 @@ abs_dirname() { local path="$1" while [ -n "$path" ]; do - cd "$(dirname "$path")" - local name="$(basename "$path")" + cd "${path%/*}" + local name="${path##*/}" path="$(readlink "$name" || true)" done From 2099355ad5babc9facf83586eb9ddac96125ac1a Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Wed, 3 Aug 2011 20:41:06 -0500 Subject: [PATCH 030/384] Pull in @telemachus' Bash autocompletion defintion from https://gist.github.com/1122379 --- completions/rbenv.bash | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 completions/rbenv.bash diff --git a/completions/rbenv.bash b/completions/rbenv.bash new file mode 100644 index 00000000..804ac2f2 --- /dev/null +++ b/completions/rbenv.bash @@ -0,0 +1,41 @@ +_commands() +{ + local cur commands + COMPREPLY=() + cur="${COMP_WORDS[COMP_CWORD]}" + commands="exec prefix rehash set-default set-local version versions\ + whence which" + + COMPREPLY=( $( compgen -W "${commands}" -- ${cur} ) ) +} + +_rubies() +{ + local cur rubies + local ROOT=$HOME/.rbenv/versions + COMPREPLY=() + cur=${COMP_WORDS[COMP_CWORD]} + rubies=($ROOT/*) + # remove all but the final part of the name + rubies="${rubies[@]##*/}" + + COMPREPLY=( $( compgen -W "${rubies}" -- ${cur} ) ) +} + +_rbenv() +{ + local cur prev + COMPREPLY=() + cur="${COMP_WORDS[COMP_CWORD]}" + prev="${COMP_WORDS[COMP_CWORD-1]}" + + if [[ "${prev}" == set-default ]]; then + _rubies + else + _commands + fi +} + +complete -F _rbenv rbenv + +# vim: set ts=4 sw=4 tw=75 filetype=sh: \ No newline at end of file From 4e79ba15f760284850fa42c4341eef2b87709c24 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Wed, 3 Aug 2011 20:44:29 -0500 Subject: [PATCH 031/384] Match style --- completions/rbenv.bash | 57 +++++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 31 deletions(-) diff --git a/completions/rbenv.bash b/completions/rbenv.bash index 804ac2f2..7843f6b4 100644 --- a/completions/rbenv.bash +++ b/completions/rbenv.bash @@ -1,41 +1,36 @@ -_commands() -{ - local cur commands - COMPREPLY=() - cur="${COMP_WORDS[COMP_CWORD]}" - commands="exec prefix rehash set-default set-local version versions\ - whence which" +_commands() { + local cur commands + COMPREPLY=() + cur="${COMP_WORDS[COMP_CWORD]}" + commands="exec prefix rehash set-default set-local version versions\ + whence which" - COMPREPLY=( $( compgen -W "${commands}" -- ${cur} ) ) + COMPREPLY=( $( compgen -W "$commands" -- $cur ) ) } -_rubies() -{ - local cur rubies - local ROOT=$HOME/.rbenv/versions - COMPREPLY=() - cur=${COMP_WORDS[COMP_CWORD]} - rubies=($ROOT/*) - # remove all but the final part of the name - rubies="${rubies[@]##*/}" +_rubies() { + local cur rubies + local ROOT="${HOME}/.rbenv/versions" + COMPREPLY=() + cur=${COMP_WORDS[COMP_CWORD]} + rubies=($ROOT/*) + # remove all but the final part of the name + rubies="${rubies[@]##*/}" - COMPREPLY=( $( compgen -W "${rubies}" -- ${cur} ) ) + COMPREPLY=( $( compgen -W "$rubies" -- $cur ) ) } -_rbenv() -{ - local cur prev - COMPREPLY=() - cur="${COMP_WORDS[COMP_CWORD]}" - prev="${COMP_WORDS[COMP_CWORD-1]}" +_rbenv() { + local cur prev + COMPREPLY=() + cur="${COMP_WORDS[COMP_CWORD]}" + prev="${COMP_WORDS[COMP_CWORD-1]}" - if [[ "${prev}" == set-default ]]; then - _rubies - else - _commands - fi + if [ "$prev" = "set-default" ]; then + _rubies + else + _commands + fi } complete -F _rbenv rbenv - -# vim: set ts=4 sw=4 tw=75 filetype=sh: \ No newline at end of file From f7c463bed96a04ec5ecf12897f9fdf6aac6163db Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Wed, 3 Aug 2011 21:43:40 -0500 Subject: [PATCH 032/384] Rename helpers --- completions/rbenv.bash | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/completions/rbenv.bash b/completions/rbenv.bash index 7843f6b4..438f5f14 100644 --- a/completions/rbenv.bash +++ b/completions/rbenv.bash @@ -1,4 +1,4 @@ -_commands() { +_rbenv_commands() { local cur commands COMPREPLY=() cur="${COMP_WORDS[COMP_CWORD]}" @@ -8,16 +8,16 @@ _commands() { COMPREPLY=( $( compgen -W "$commands" -- $cur ) ) } -_rubies() { - local cur rubies +_rbenv_versions() { + local cur versions local ROOT="${HOME}/.rbenv/versions" COMPREPLY=() cur=${COMP_WORDS[COMP_CWORD]} - rubies=($ROOT/*) + versions=($ROOT/*) # remove all but the final part of the name - rubies="${rubies[@]##*/}" + versions="${versions[@]##*/}" - COMPREPLY=( $( compgen -W "$rubies" -- $cur ) ) + COMPREPLY=( $( compgen -W "$versions" -- $cur ) ) } _rbenv() { @@ -27,9 +27,9 @@ _rbenv() { prev="${COMP_WORDS[COMP_CWORD-1]}" if [ "$prev" = "set-default" ]; then - _rubies + _rbenv_versions else - _commands + _rbenv_commands fi } From df034f5d354d0bab5e70294c1d8694bb3f4da6da Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Wed, 3 Aug 2011 21:50:03 -0500 Subject: [PATCH 033/384] Defer to `rbenv versions` instead of reading ~/.rbenv/versions manually --- completions/rbenv.bash | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/completions/rbenv.bash b/completions/rbenv.bash index 438f5f14..de53fc69 100644 --- a/completions/rbenv.bash +++ b/completions/rbenv.bash @@ -9,13 +9,10 @@ _rbenv_commands() { } _rbenv_versions() { - local cur versions - local ROOT="${HOME}/.rbenv/versions" COMPREPLY=() - cur=${COMP_WORDS[COMP_CWORD]} - versions=($ROOT/*) - # remove all but the final part of the name - versions="${versions[@]##*/}" + local cur=${COMP_WORDS[COMP_CWORD]} + local versions=(system $(rbenv versions --bare)) + versions="${versions[@]}" COMPREPLY=( $( compgen -W "$versions" -- $cur ) ) } From 5d8c40444de21e54fcf248055f3f184e8ef485a1 Mon Sep 17 00:00:00 2001 From: Jamis Buck Date: Wed, 3 Aug 2011 20:55:03 -0600 Subject: [PATCH 034/384] iterate over all matching plugins, not just the first --- libexec/rbenv-exec | 2 +- libexec/rbenv-rehash | 2 +- libexec/rbenv-which | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libexec/rbenv-exec b/libexec/rbenv-exec index 5bd4e8c5..ca8d7755 100755 --- a/libexec/rbenv-exec +++ b/libexec/rbenv-exec @@ -12,7 +12,7 @@ shopt -s nullglob RBENV_EXEC_PLUGINS=(/etc/rbenv.d/exec/*.bash ${HOME}/.rbenv/rbenv.d/exec/*.bash) shopt -u nullglob -for script in $RBENV_EXEC_PLUGINS; do +for script in ${RBENV_EXEC_PLUGINS[@]}; do source $script done diff --git a/libexec/rbenv-rehash b/libexec/rbenv-rehash index 96305478..c57eab6d 100755 --- a/libexec/rbenv-rehash +++ b/libexec/rbenv-rehash @@ -23,6 +23,6 @@ shopt -s nullglob RBENV_REHASH_PLUGINS=(/etc/rbenv.d/rehash/*.bash ${HOME}/.rbenv/rbenv.d/rehash/*.bash) shopt -u nullglob -for script in $RBENV_REHASH_PLUGINS; do +for script in ${RBENV_REHASH_PLUGINS[@]}; do source $script done diff --git a/libexec/rbenv-which b/libexec/rbenv-which index 34ea534e..74572f47 100755 --- a/libexec/rbenv-which +++ b/libexec/rbenv-which @@ -8,7 +8,7 @@ shopt -s nullglob RBENV_WHICH_PLUGINS=(/etc/rbenv.d/which/*.bash ${HOME}/.rbenv/rbenv.d/which/*.bash) shopt -u nullglob -for script in $RBENV_WHICH_PLUGINS; do +for script in ${RBENV_WHICH_PLUGINS[@]}; do source $script done From 3b13dc9c144b62641ee04872b9090580000f242f Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Wed, 3 Aug 2011 22:20:01 -0500 Subject: [PATCH 035/384] Add rbenv-commands --- libexec/rbenv-commands | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100755 libexec/rbenv-commands diff --git a/libexec/rbenv-commands b/libexec/rbenv-commands new file mode 100755 index 00000000..49ba268b --- /dev/null +++ b/libexec/rbenv-commands @@ -0,0 +1,11 @@ +#!/usr/bin/env bash -e + +shopt -s nullglob + +{ for path in ${PATH//:/$'\n'}; do + for command in "${path}/rbenv-"*; do + echo "${command##*rbenv-}" + done + done +} | sort | uniq + From e4a040f1e092a29f42099482e20ba5017b7e09e2 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Wed, 3 Aug 2011 22:20:25 -0500 Subject: [PATCH 036/384] Defer to `rbenv commands` --- completions/rbenv.bash | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/completions/rbenv.bash b/completions/rbenv.bash index de53fc69..539c05bf 100644 --- a/completions/rbenv.bash +++ b/completions/rbenv.bash @@ -1,11 +1,7 @@ _rbenv_commands() { - local cur commands COMPREPLY=() - cur="${COMP_WORDS[COMP_CWORD]}" - commands="exec prefix rehash set-default set-local version versions\ - whence which" - - COMPREPLY=( $( compgen -W "$commands" -- $cur ) ) + local cur="${COMP_WORDS[COMP_CWORD]}" + COMPREPLY=( $( compgen -W "$(rbenv commands)" -- $cur ) ) } _rbenv_versions() { From ccf7c29fc4f460129376fcb6b812e52cd292d4bf Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Wed, 3 Aug 2011 22:22:45 -0500 Subject: [PATCH 037/384] Simplify _rbenv_versions --- completions/rbenv.bash | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/completions/rbenv.bash b/completions/rbenv.bash index 539c05bf..91107085 100644 --- a/completions/rbenv.bash +++ b/completions/rbenv.bash @@ -6,10 +6,8 @@ _rbenv_commands() { _rbenv_versions() { COMPREPLY=() - local cur=${COMP_WORDS[COMP_CWORD]} - local versions=(system $(rbenv versions --bare)) - versions="${versions[@]}" - + local cur="${COMP_WORDS[COMP_CWORD]}" + local versions="$(echo system; rbenv versions --bare)" COMPREPLY=( $( compgen -W "$versions" -- $cur ) ) } From f904d1b92f6588efac620e16579453727760b5aa Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Wed, 3 Aug 2011 22:28:30 -0500 Subject: [PATCH 038/384] Complete versions for `rbenv set-local` and `rbenv prefix` too --- completions/rbenv.bash | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/completions/rbenv.bash b/completions/rbenv.bash index 91107085..0e8a383d 100644 --- a/completions/rbenv.bash +++ b/completions/rbenv.bash @@ -12,16 +12,18 @@ _rbenv_versions() { } _rbenv() { - local cur prev COMPREPLY=() - cur="${COMP_WORDS[COMP_CWORD]}" - prev="${COMP_WORDS[COMP_CWORD-1]}" + local cur="${COMP_WORDS[COMP_CWORD]}" + local prev="${COMP_WORDS[COMP_CWORD-1]}" - if [ "$prev" = "set-default" ]; then + case "$prev" in + set-* | prefix ) _rbenv_versions - else + ;; + * ) _rbenv_commands - fi + ;; + esac } complete -F _rbenv rbenv From fffb29d695141ef84b7517bc0922c8c103456588 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Wed, 3 Aug 2011 22:57:27 -0500 Subject: [PATCH 039/384] Speed up rbenv-rehash by using hard links --- libexec/rbenv-rehash | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/libexec/rbenv-rehash b/libexec/rbenv-rehash index c57eab6d..6254d0aa 100755 --- a/libexec/rbenv-rehash +++ b/libexec/rbenv-rehash @@ -1,15 +1,19 @@ #!/usr/bin/env bash -e +create_prototype_shim() { + cat > .rbenv-shim < "$shim" < Date: Wed, 3 Aug 2011 23:16:28 -0500 Subject: [PATCH 040/384] Add init command --- libexec/rbenv-init | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100755 libexec/rbenv-init diff --git a/libexec/rbenv-init b/libexec/rbenv-init new file mode 100755 index 00000000..e75595b3 --- /dev/null +++ b/libexec/rbenv-init @@ -0,0 +1,31 @@ +#!/usr/bin/env bash -e + +shell=$1 + +if [ -z "$shell" ]; then + shell=$(basename $SHELL) +fi + +abs_dirname() { + local cwd="$(pwd)" + local path="$1" + + while [ -n "$path" ]; do + cd "${path%/*}" + local name="${path##*/}" + path="$(readlink "$name" || true)" + done + + pwd + cd "$cwd" +} +root="$(abs_dirname "$0")/.." + +if [ -d "$HOME/.rbenv/shims" ]; then + rbenv-rehash + echo 'PATH="$HOME/.rbenv/shims:$PATH"' +fi + +if [ "$shell" = "bash" ]; then + echo "source $root/completions/rbenv.bash" +fi From 70e1f613371dbf178ac68b02e7fe5dab9b6d19e9 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Wed, 3 Aug 2011 23:20:19 -0500 Subject: [PATCH 041/384] Quote path --- libexec/rbenv-init | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libexec/rbenv-init b/libexec/rbenv-init index e75595b3..0e0a36ec 100755 --- a/libexec/rbenv-init +++ b/libexec/rbenv-init @@ -27,5 +27,5 @@ if [ -d "$HOME/.rbenv/shims" ]; then fi if [ "$shell" = "bash" ]; then - echo "source $root/completions/rbenv.bash" + echo "source \"$root/completions/rbenv.bash\"" fi From 271bfea97d5ef3e56e7de0ae6b440bd5ef89d42e Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Wed, 3 Aug 2011 23:26:37 -0500 Subject: [PATCH 042/384] Don't rehash on init for now --- libexec/rbenv-init | 1 - 1 file changed, 1 deletion(-) diff --git a/libexec/rbenv-init b/libexec/rbenv-init index 0e0a36ec..06a2500e 100755 --- a/libexec/rbenv-init +++ b/libexec/rbenv-init @@ -22,7 +22,6 @@ abs_dirname() { root="$(abs_dirname "$0")/.." if [ -d "$HOME/.rbenv/shims" ]; then - rbenv-rehash echo 'PATH="$HOME/.rbenv/shims:$PATH"' fi From 917b3687cbfd41bb48495f960e3343884d1da643 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Wed, 3 Aug 2011 23:46:24 -0500 Subject: [PATCH 043/384] Export $PATH on init --- libexec/rbenv-init | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libexec/rbenv-init b/libexec/rbenv-init index 06a2500e..dfd718b1 100755 --- a/libexec/rbenv-init +++ b/libexec/rbenv-init @@ -22,7 +22,7 @@ abs_dirname() { root="$(abs_dirname "$0")/.." if [ -d "$HOME/.rbenv/shims" ]; then - echo 'PATH="$HOME/.rbenv/shims:$PATH"' + echo 'export PATH="$HOME/.rbenv/shims:$PATH"' fi if [ "$shell" = "bash" ]; then From 00b8b4db338f9b6feb84cbeb40253ecedcb5992f Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Wed, 3 Aug 2011 23:53:52 -0500 Subject: [PATCH 044/384] Don't need to test if the shims directory is present since rbenv-rehash creates it --- libexec/rbenv-init | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/libexec/rbenv-init b/libexec/rbenv-init index dfd718b1..d8a4a0bc 100755 --- a/libexec/rbenv-init +++ b/libexec/rbenv-init @@ -21,9 +21,7 @@ abs_dirname() { } root="$(abs_dirname "$0")/.." -if [ -d "$HOME/.rbenv/shims" ]; then - echo 'export PATH="$HOME/.rbenv/shims:$PATH"' -fi +echo 'export PATH="$HOME/.rbenv/shims:$PATH"' if [ "$shell" = "bash" ]; then echo "source \"$root/completions/rbenv.bash\"" From 4ee92fca43805a3d4a04f453e79a06e85b9810e9 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Thu, 4 Aug 2011 00:45:40 -0500 Subject: [PATCH 045/384] Bare `rbenv init` prints a message; `rbenv init -` prints the init script --- libexec/rbenv-init | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/libexec/rbenv-init b/libexec/rbenv-init index d8a4a0bc..43e1339d 100755 --- a/libexec/rbenv-init +++ b/libexec/rbenv-init @@ -1,9 +1,14 @@ #!/usr/bin/env bash -e -shell=$1 +print="" +if [ "$1" = "-" ]; then + print=1 + shift +fi +shell="$1" if [ -z "$shell" ]; then - shell=$(basename $SHELL) + shell="$(basename "$SHELL")" fi abs_dirname() { @@ -19,9 +24,33 @@ abs_dirname() { pwd cd "$cwd" } + root="$(abs_dirname "$0")/.." -echo 'export PATH="$HOME/.rbenv/shims:$PATH"' +if [ -z "$print" ]; then + case "$shell" in + bash ) + profile='~/.bash_profile' + ;; + zsh ) + profile='~/.zshrc' + ;; + * ) + profile='your profile' + ;; + esac + + { echo "# Load rbenv automatically by adding" + echo "# the following to ${profile}:" + echo + echo 'eval "$(rbenv init -)"' + echo + } >&2 + + exit 1 +fi + +echo 'export PATH="${HOME}/.rbenv/shims:${PATH}"' if [ "$shell" = "bash" ]; then echo "source \"$root/completions/rbenv.bash\"" From f84dc27c5807257a6dae8501183d79e6563226f8 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Thu, 4 Aug 2011 00:48:37 -0500 Subject: [PATCH 046/384] Autocreate ~/.rbenv skeleton in rbenv-init --- libexec/rbenv-init | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libexec/rbenv-init b/libexec/rbenv-init index 43e1339d..9569e93f 100755 --- a/libexec/rbenv-init +++ b/libexec/rbenv-init @@ -50,6 +50,9 @@ if [ -z "$print" ]; then exit 1 fi +mkdir -p "${HOME}/.rbenv/{shims,versions}" +[ -e "${HOME}/.rbenv/default" ] || echo system > "${HOME}/.rbenv/default" + echo 'export PATH="${HOME}/.rbenv/shims:${PATH}"' if [ "$shell" = "bash" ]; then From 1235cbd0ef5f775bddbdac466a2c2391626359b2 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Thu, 4 Aug 2011 01:00:08 -0500 Subject: [PATCH 047/384] rbenv-versions doesn't require a default to be present --- libexec/rbenv-versions | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libexec/rbenv-versions b/libexec/rbenv-versions index e69c751f..10c823be 100755 --- a/libexec/rbenv-versions +++ b/libexec/rbenv-versions @@ -1,6 +1,6 @@ #!/usr/bin/env bash -e -RBENV_VERSION="$(rbenv-version)" +RBENV_VERSION="$(rbenv-version || true)" hit_prefix="* " miss_prefix=" " From cd244950458ec133993de2744539b097baa8ef51 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Thu, 4 Aug 2011 01:02:04 -0500 Subject: [PATCH 048/384] Silence the warning, too --- libexec/rbenv-versions | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libexec/rbenv-versions b/libexec/rbenv-versions index 10c823be..94b878ea 100755 --- a/libexec/rbenv-versions +++ b/libexec/rbenv-versions @@ -1,6 +1,6 @@ #!/usr/bin/env bash -e -RBENV_VERSION="$(rbenv-version || true)" +RBENV_VERSION="$(rbenv-version 2>/dev/null || true)" hit_prefix="* " miss_prefix=" " From 9f18fe50319fae43b1952664b40c6ec8ceab807e Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Thu, 4 Aug 2011 01:08:47 -0500 Subject: [PATCH 049/384] Automatically create a default of system if it's missing instead of raising an error --- libexec/rbenv-init | 1 - libexec/rbenv-version | 11 ++++++----- libexec/rbenv-versions | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/libexec/rbenv-init b/libexec/rbenv-init index 9569e93f..f9de2858 100755 --- a/libexec/rbenv-init +++ b/libexec/rbenv-init @@ -51,7 +51,6 @@ if [ -z "$print" ]; then fi mkdir -p "${HOME}/.rbenv/{shims,versions}" -[ -e "${HOME}/.rbenv/default" ] || echo system > "${HOME}/.rbenv/default" echo 'export PATH="${HOME}/.rbenv/shims:${PATH}"' diff --git a/libexec/rbenv-version b/libexec/rbenv-version index 2c9cae13..5e7e9940 100755 --- a/libexec/rbenv-version +++ b/libexec/rbenv-version @@ -16,10 +16,11 @@ find_version_file() { return 1 } +DEFAULT_PATH="${HOME}/.rbenv/default" + find_default_version_file() { - local default_path="$HOME/.rbenv/default" - if [ -e "$default_path" ]; then - echo "$default_path" + if [ -e "$DEFAULT_PATH" ]; then + echo "$DEFAULT_PATH" return 0 fi return 1 @@ -31,8 +32,8 @@ if [ -z "$RBENV_VERSION" ]; then if [ -n "$RBENV_VERSION_FILE" ]; then RBENV_VERSION="$(read_version_file "$RBENV_VERSION_FILE")" else - echo "rbenv: no default version specified" >&2 - exit 1 + echo system > "$DEFAULT_PATH" + RBENV_VERSION=system fi fi diff --git a/libexec/rbenv-versions b/libexec/rbenv-versions index 94b878ea..e69c751f 100755 --- a/libexec/rbenv-versions +++ b/libexec/rbenv-versions @@ -1,6 +1,6 @@ #!/usr/bin/env bash -e -RBENV_VERSION="$(rbenv-version 2>/dev/null || true)" +RBENV_VERSION="$(rbenv-version)" hit_prefix="* " miss_prefix=" " From 2fa743206067034aa5a68d7d730b6cbbb3db8124 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Thu, 4 Aug 2011 01:16:16 -0500 Subject: [PATCH 050/384] Fix expansion quoting --- libexec/rbenv-init | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libexec/rbenv-init b/libexec/rbenv-init index f9de2858..6b9765f2 100755 --- a/libexec/rbenv-init +++ b/libexec/rbenv-init @@ -50,7 +50,7 @@ if [ -z "$print" ]; then exit 1 fi -mkdir -p "${HOME}/.rbenv/{shims,versions}" +mkdir -p "${HOME}/.rbenv/"{shims,versions} echo 'export PATH="${HOME}/.rbenv/shims:${PATH}"' From 2a495dc9ac842f745239bb7bb6402a8d8c168992 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Fri, 5 Aug 2011 10:12:58 -0500 Subject: [PATCH 051/384] Prepend $PATH with the command's dirname before execing for compatibility with ruby -S --- libexec/rbenv-exec | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libexec/rbenv-exec b/libexec/rbenv-exec index ca8d7755..a538a52f 100755 --- a/libexec/rbenv-exec +++ b/libexec/rbenv-exec @@ -7,6 +7,7 @@ if [ -z "$RBENV_COMMAND" ]; then fi RBENV_COMMAND_PATH="$(rbenv-which "$RBENV_COMMAND")" +RBENV_BIN_PATH="${RBENV_COMMAND_PATH%/*}" shopt -s nullglob RBENV_EXEC_PLUGINS=(/etc/rbenv.d/exec/*.bash ${HOME}/.rbenv/rbenv.d/exec/*.bash) @@ -17,4 +18,5 @@ for script in ${RBENV_EXEC_PLUGINS[@]}; do done shift 1 +export PATH="${RBENV_BIN_PATH}:${PATH}" exec -a "$RBENV_COMMAND" "$RBENV_COMMAND_PATH" "$@" From bd0e1a73f95201c9243e1c3a2880e79b88e6fe1e Mon Sep 17 00:00:00 2001 From: Ryan Baumann Date: Tue, 9 Aug 2011 16:41:35 -0400 Subject: [PATCH 052/384] Split rbenv-version into rbenv-version-name and rbenv-version-origin, update versions, prefix, and which appropriately --- libexec/rbenv-prefix | 2 +- libexec/rbenv-version | 51 +----------------------------------- libexec/rbenv-version-name | 32 ++++++++++++++++++++++ libexec/rbenv-version-origin | 29 ++++++++++++++++++++ libexec/rbenv-versions | 14 +++++----- libexec/rbenv-which | 2 +- 6 files changed, 72 insertions(+), 58 deletions(-) create mode 100755 libexec/rbenv-version-name create mode 100755 libexec/rbenv-version-origin diff --git a/libexec/rbenv-prefix b/libexec/rbenv-prefix index 9d17ee42..f65701f6 100755 --- a/libexec/rbenv-prefix +++ b/libexec/rbenv-prefix @@ -3,7 +3,7 @@ if [ -n "$1" ]; then RBENV_VERSION="$1" elif [ -z "$RBENV_VERSION" ]; then - RBENV_VERSION="$(rbenv-version)" + RBENV_VERSION="$(rbenv-version-name)" fi if [ "$RBENV_VERSION" = "system" ]; then diff --git a/libexec/rbenv-version b/libexec/rbenv-version index 5e7e9940..1143c70d 100755 --- a/libexec/rbenv-version +++ b/libexec/rbenv-version @@ -1,52 +1,3 @@ #!/usr/bin/env bash -e -read_version_file() { - egrep -m 1 '[^[:space:]]' "$1" -} - -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 - RBENV_VERSION_FILE="$(find_version_file || find_default_version_file || true)" - - 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 +echo "$(rbenv-version-name) (set by $(rbenv-version-origin))" diff --git a/libexec/rbenv-version-name b/libexec/rbenv-version-name new file mode 100755 index 00000000..fd2f1665 --- /dev/null +++ b/libexec/rbenv-version-name @@ -0,0 +1,32 @@ +#!/usr/bin/env bash -e + +read_version_file() { + egrep -m 1 '[^[:space:]]' "$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 diff --git a/libexec/rbenv-version-origin b/libexec/rbenv-version-origin new file mode 100755 index 00000000..38e4f3d5 --- /dev/null +++ b/libexec/rbenv-version-origin @@ -0,0 +1,29 @@ +#!/usr/bin/env bash -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 + echo "RBENV_VERSION environment variable" +fi diff --git a/libexec/rbenv-versions b/libexec/rbenv-versions index e69c751f..32b56c5b 100755 --- a/libexec/rbenv-versions +++ b/libexec/rbenv-versions @@ -1,21 +1,23 @@ #!/usr/bin/env bash -e -RBENV_VERSION="$(rbenv-version)" - -hit_prefix="* " -miss_prefix=" " +RBENV_VERSION_NAME="$(rbenv-version-name)" if [ "$1" = "--bare" ]; then hit_prefix="" miss_prefix="" + print_version="$RBENV_VERSION_NAME" +else + hit_prefix="* " + miss_prefix=" " + print_version="$(rbenv-version)" fi for path in "${HOME}/.rbenv/versions/"*; do if [ -d "$path" ]; then version="${path##*/}" - if [ "$version" == "$RBENV_VERSION" ]; then - echo "${hit_prefix}${version}" + if [ "$version" == "$RBENV_VERSION_NAME" ]; then + echo "${hit_prefix}${print_version}" else echo "${miss_prefix}${version}" fi diff --git a/libexec/rbenv-which b/libexec/rbenv-which index f38bba61..d6360b0b 100755 --- a/libexec/rbenv-which +++ b/libexec/rbenv-which @@ -21,7 +21,7 @@ remove_from_path() { echo "${result%:}" } -RBENV_VERSION="$(rbenv-version)" +RBENV_VERSION="$(rbenv-version-name)" RBENV_COMMAND="$1" if [ "$RBENV_VERSION" = "system" ]; then From f2f8ef88a50f0edadd9fec139777a9220035687e Mon Sep 17 00:00:00 2001 From: Ryan Baumann Date: Wed, 10 Aug 2011 09:53:24 -0400 Subject: [PATCH 053/384] Implement some basic command line help --- libexec/rbenv | 2 +- libexec/rbenv-help | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100755 libexec/rbenv-help diff --git a/libexec/rbenv b/libexec/rbenv index 66d8c438..74ab8928 100755 --- a/libexec/rbenv +++ b/libexec/rbenv @@ -19,7 +19,7 @@ export PATH="${libexec_path}:${PATH}" command="$1" if [ -z "$command" ]; then - echo "rbenv 0.1.0" >&2 + echo -e "rbenv 0.1.0\n$(rbenv-help)" >&2 else command_path="$(command -v "rbenv-$command" || true)" diff --git a/libexec/rbenv-help b/libexec/rbenv-help new file mode 100755 index 00000000..dcf671ac --- /dev/null +++ b/libexec/rbenv-help @@ -0,0 +1,43 @@ +#!/usr/bin/env bash -e + +print_set_version() { + echo " should be a string matching the installed Ruby name known by rbenv. + +For your install, this is currently one of: + +$(rbenv-versions --bare) + +The special version string 'system' will use your default system Ruby." +} + +case "$1" in +"") echo "usage: rbenv [] + +Some useful rbenv commands are: + commands List all commands + rehash Rehash rbenv shims, use after installing binaries + set-default Set global default Ruby + set-local Set local directory default Ruby + version Show Ruby version being used + versions List Ruby versions known by rbenv + +See 'rbenv help ' for more information on a specific command. +For a quick guide to rbenv, see: https://gist.github.com/1120938" +;; +set-default) echo "usage: rbenv set-default + +Sets the global default Ruby. + +$(print_set_version)" +;; +set-local) echo "usage: rbenv set-local + +Sets the local directory default Ruby, by writing the version to a file +named '.rbenv-version'. rbenv will search for this file up the directory +tree from the current working directory each time its shims are executed, +so this default will affect subdirectories. + +$(print_set_version)" +;; +*) echo "No command arguments needed or invalid/undocumented command." +esac From 5394347500e7a55b09e4921aba31af2228be8b2f Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Wed, 10 Aug 2011 09:23:43 -0500 Subject: [PATCH 054/384] A few tweaks to the help text --- libexec/rbenv-help | 41 ++++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/libexec/rbenv-help b/libexec/rbenv-help index dcf671ac..ad44e9ee 100755 --- a/libexec/rbenv-help +++ b/libexec/rbenv-help @@ -1,13 +1,18 @@ #!/usr/bin/env bash -e print_set_version() { - echo " should be a string matching the installed Ruby name known by rbenv. + echo " should be a string matching a Ruby version known by rbenv." -For your install, this is currently one of: + local versions="$(rbenv-versions --bare)" + if [ -z "$versions" ]; then + echo "There are currently no Ruby versions installed for rbenv." + else + echo "The currently installed Ruby versions are:" + echo "$versions" | sed 's/^/ /' + fi -$(rbenv-versions --bare) - -The special version string 'system' will use your default system Ruby." + echo + echo "The special version string 'system' will use your default system Ruby." } case "$1" in @@ -15,27 +20,33 @@ case "$1" in Some useful rbenv commands are: commands List all commands - rehash Rehash rbenv shims, use after installing binaries - set-default Set global default Ruby - set-local Set local directory default Ruby - version Show Ruby version being used - versions List Ruby versions known by rbenv + rehash Rehash rbenv shims (run this after installing binaries) + set-default Set the default Ruby version + set-local Set a local directory-specific Ruby version + version Show the current Ruby version + versions List all Ruby versions known by rbenv See 'rbenv help ' for more information on a specific command. For a quick guide to rbenv, see: https://gist.github.com/1120938" ;; set-default) echo "usage: rbenv set-default -Sets the global default Ruby. +Sets the default Ruby version. You can override the default at any time +by setting a directory-specific version with \`rbenv set-default' or by +setting the RBENV_VERSION environment variable. $(print_set_version)" ;; set-local) echo "usage: rbenv set-local -Sets the local directory default Ruby, by writing the version to a file -named '.rbenv-version'. rbenv will search for this file up the directory -tree from the current working directory each time its shims are executed, -so this default will affect subdirectories. +Sets the local directory-specific Ruby version by writing the version +name to a file named '.rbenv-version'. + +When you run a Ruby command, rbenv will look for an '.rbenv-version' +file in the current directory and each parent directory. If no such +file is found in the tree, rbenv will use the default Ruby version +specified with \`rbenv set-default', or the version specified in the +RBENV_VERSION environment variable. $(print_set_version)" ;; From 71493e806580aa9895d5250bc71f432440c4c0f9 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Wed, 10 Aug 2011 09:31:53 -0500 Subject: [PATCH 055/384] Typo --- libexec/rbenv-help | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libexec/rbenv-help b/libexec/rbenv-help index ad44e9ee..105eeee4 100755 --- a/libexec/rbenv-help +++ b/libexec/rbenv-help @@ -32,7 +32,7 @@ For a quick guide to rbenv, see: https://gist.github.com/1120938" set-default) echo "usage: rbenv set-default Sets the default Ruby version. You can override the default at any time -by setting a directory-specific version with \`rbenv set-default' or by +by setting a directory-specific version with \`rbenv set-local' or by setting the RBENV_VERSION environment variable. $(print_set_version)" From a804b5eb21d6623b91a13ccf3281276d65ba45d6 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Thu, 11 Aug 2011 12:51:35 -0500 Subject: [PATCH 056/384] Add LICENSE and README.md --- LICENSE | 20 +++++++++ README.md | 124 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 144 insertions(+) create mode 100644 LICENSE create mode 100644 README.md diff --git a/LICENSE b/LICENSE new file mode 100644 index 00000000..63c11cb6 --- /dev/null +++ b/LICENSE @@ -0,0 +1,20 @@ +Copyright (c) 2011 Sam Stephenson + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 00000000..ae67d397 --- /dev/null +++ b/README.md @@ -0,0 +1,124 @@ +# Simple Ruby Version Management: rbenv + +rbenv lets you easily switch between multiple versions of Ruby. It's simple, unobtrusive, understandable, and follows in the Unix tradition of single-purpose tools that do one thing well. + +### rbenv _does_… + +* Let you **change the default Ruby version** on a per-user basis. +* Provide support for **per-project Ruby versions**. +* Allow you to **override the Ruby version** with an environment variable. + +### rbenv _does not_… + +* **Need to be loaded into your shell.** Instead, rbenv's shim approach works by adding a directory to your `$PATH`. +* **Override shell commands like `cd`.** That's just obnoxious! +* **Have a configuration file.** There's nothing to configure except which version of Ruby you want to use. +* **Install Ruby.** You can build and install Ruby yourself, or use [ruby-build](https://github.com/sstephenson/ruby-build.git) to automate the process. +* **Manage gemsets.** [Bundler](http://gembundler.com/) is a better way to manage application dependencies. If you have projects that are not yet using Bundler you can install the [rbenv-gemset](https://github.com/jamis/rbenv-gemset) plugin. +* **Require changes to Ruby libraries for compatibility.** The simplicity of rbenv means as long as it's in your `$PATH`, [nothing](https://rvm.beginrescueend.com/integration/bundler/) [else](https://rvm.beginrescueend.com/integration/capistrano/) needs to know about it. +* **Prompt you with warnings when you switch to a project.** Instead of executing arbitrary code, rbenv reads just the version name from each project. There's nothing to "trust." + +## How It Works + +rbenv operates on the per-user directory `~/.rbenv`. Version names in rbenv correspond to subdirectories of `~/.rbenv/versions`. For example, you might have `~/.rbenv/versions/1.8.7-p354` and `~/.rbenv/versions/1.9.3-preview1`. + +Each version is a working tree with its own binaries, like `~/.rbenv/versions/1.8.7-p354/bin/ruby` and `~/.rbenv/versions/1.9.3-preview1/irb`. rbenv makes _shim binaries_ for every such binary across all installed versions of Ruby. + +These shims are simple wrapper scripts that live in `~/.rbenv/shims` and detect which Ruby version you want to use. They insert the directory for the selected version at the beginning of your `$PATH` and then execute the corresponding binary. + +Because of the simplicity of the shim approach, all you need to use rbenv is `~/.rbenv/shims` in your `$PATH`. + +## Installation + +rbenv is a young project, so for now you must install it from source. + +1. Check out rbenv into `~/.rbenv`. + + $ cd + $ git clone git://github.com/sstephenson/rbenv.git .rbenv + +2. Add `~/.rbenv/bin` to your `$PATH` for access to the `rbenv` command-line utility. + + $ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> .bash_profile + +3. Add rbenv's shims directory to your `$PATH` and set up Bash autocompletion. (If you prefer not to load rbenv in your shell, you can manually add `$HOME/.rbenv/shims` to your path in step 2.) + + $ echo 'eval "$(rbenv init -)"' >> .bash_profile + +4. Restart your shell. You can now begin using rbenv. + + $ exec $SHELL + +5. Install Ruby versions into `~/.rbenv/versions`. For example, to install Ruby 1.9.2-p290, download and unpack the source, then run: + + $ ./configure --prefix=~/.rbenv/versions/1.9.2-p290 + $ make + $ make install + + The [ruby-build](https://github.com/sstephenson/ruby-build) project simplifies this process to a single command: + + $ ruby-build 1.9.2-p290 ~/.rbenv/versions/1.9.2-p290 + +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). + + $ rbenv rehash + +## Usage + +Like `git`, the `rbenv` command delegates to subcommands based on its first argument. The most common subcommands are: + +* **set-default** — sets the default version of Ruby to be used in all shells by writing the version name to the `~/.rbenv/default` file. This version can be overridden by a per-project `.rbenv-version` file, or by setting the `RBENV_VERSION` environment variable. + + $ rbenv set-default 1.9.2-p290 + + The special version name `system` tells rbenv to use the system Ruby (detected by searching your `$PATH`). + +* **set-local** — sets a local per-project Ruby version by writing the version name to an `.rbenv-version` file in the current directory. This version overrides the default, and can be overridden itself by setting the `RBENV_VERSION` environment variable. + + $ rbenv set-local rbx-1.2.4 + +* **versions** — lists all Ruby versions known to rbenv, and shows an asterisk next to the currently active version. + + $ rbenv versions + 1.8.7-p352 + 1.9.2-p290 + * 1.9.3-preview1 (set by /Users/sam/.rbenv/default) + jruby-1.6.3 + rbx-1.2.4 + ree-1.8.7-2011.03 + +* **version** — displays the currently active Ruby version, along with information on how it was set. + + $ rbenv version + 1.8.7-p352 (set by /Volumes/37signals/basecamp/.rbenv-version) + +## Contributing + +The rbenv source code is [hosted on GitHub](https://github.com/sstephenson/rbenv). It's clean, modular, and easy to understand, even if you're not a shell hacker. + +Please feel free to submit pull requests and file bugs on the [issue tracker](https://github.com/sstephenson/rbenv/issues). + +## License + +(The MIT license) + +Copyright (c) 2011 Sam Stephenson + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file From e8d010f33cb1b553f82fb2b7e26d8c477f6e511d Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Thu, 11 Aug 2011 12:53:20 -0500 Subject: [PATCH 057/384] Fix italics --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ae67d397..d3488569 100644 --- a/README.md +++ b/README.md @@ -2,13 +2,13 @@ rbenv lets you easily switch between multiple versions of Ruby. It's simple, unobtrusive, understandable, and follows in the Unix tradition of single-purpose tools that do one thing well. -### rbenv _does_… +### rbenv _does…_ * Let you **change the default Ruby version** on a per-user basis. * Provide support for **per-project Ruby versions**. * Allow you to **override the Ruby version** with an environment variable. -### rbenv _does not_… +### rbenv _does not…_ * **Need to be loaded into your shell.** Instead, rbenv's shim approach works by adding a directory to your `$PATH`. * **Override shell commands like `cd`.** That's just obnoxious! @@ -121,4 +121,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. From b4a91648eb45fad9aadc4f428683d7dc7f06a23f Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Thu, 11 Aug 2011 13:11:37 -0500 Subject: [PATCH 058/384] Hard-wrap --- README.md | 100 ++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 74 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index d3488569..df320c20 100644 --- a/README.md +++ b/README.md @@ -1,32 +1,58 @@ # Simple Ruby Version Management: rbenv -rbenv lets you easily switch between multiple versions of Ruby. It's simple, unobtrusive, understandable, and follows in the Unix tradition of single-purpose tools that do one thing well. +rbenv lets you easily switch between multiple versions of Ruby. It's +simple, unobtrusive, understandable, and follows in the Unix tradition +of single-purpose tools that do one thing well. ### rbenv _does…_ * Let you **change the default Ruby version** on a per-user basis. * Provide support for **per-project Ruby versions**. -* Allow you to **override the Ruby version** with an environment variable. +* Allow you to **override the Ruby version** with an environment + variable. ### rbenv _does not…_ -* **Need to be loaded into your shell.** Instead, rbenv's shim approach works by adding a directory to your `$PATH`. +* **Need to be loaded into your shell.** Instead, rbenv's shim + approach works by adding a directory to your `$PATH`. * **Override shell commands like `cd`.** That's just obnoxious! -* **Have a configuration file.** There's nothing to configure except which version of Ruby you want to use. -* **Install Ruby.** You can build and install Ruby yourself, or use [ruby-build](https://github.com/sstephenson/ruby-build.git) to automate the process. -* **Manage gemsets.** [Bundler](http://gembundler.com/) is a better way to manage application dependencies. If you have projects that are not yet using Bundler you can install the [rbenv-gemset](https://github.com/jamis/rbenv-gemset) plugin. -* **Require changes to Ruby libraries for compatibility.** The simplicity of rbenv means as long as it's in your `$PATH`, [nothing](https://rvm.beginrescueend.com/integration/bundler/) [else](https://rvm.beginrescueend.com/integration/capistrano/) needs to know about it. -* **Prompt you with warnings when you switch to a project.** Instead of executing arbitrary code, rbenv reads just the version name from each project. There's nothing to "trust." +* **Have a configuration file.** There's nothing to configure except + which version of Ruby you want to use. +* **Install Ruby.** You can build and install Ruby yourself, or use + [ruby-build](https://github.com/sstephenson/ruby-build.git) to + automate the process. +* **Manage gemsets.** [Bundler](http://gembundler.com/) is a better + way to manage application dependencies. If you have projects that + are not yet using Bundler you can install the + [rbenv-gemset](https://github.com/jamis/rbenv-gemset) plugin. +* **Require changes to Ruby libraries for compatibility.** The + simplicity of rbenv means as long as it's in your `$PATH`, + [nothing](https://rvm.beginrescueend.com/integration/bundler/) + [else](https://rvm.beginrescueend.com/integration/capistrano/) + needs to know about it. +* **Prompt you with warnings when you switch to a project.** Instead + of executing arbitrary code, rbenv reads just the version name + from each project. There's nothing to "trust." ## How It Works -rbenv operates on the per-user directory `~/.rbenv`. Version names in rbenv correspond to subdirectories of `~/.rbenv/versions`. For example, you might have `~/.rbenv/versions/1.8.7-p354` and `~/.rbenv/versions/1.9.3-preview1`. +rbenv operates on the per-user directory `~/.rbenv`. Version names in +rbenv correspond to subdirectories of `~/.rbenv/versions`. For +example, you might have `~/.rbenv/versions/1.8.7-p354` and +`~/.rbenv/versions/1.9.3-preview1`. -Each version is a working tree with its own binaries, like `~/.rbenv/versions/1.8.7-p354/bin/ruby` and `~/.rbenv/versions/1.9.3-preview1/irb`. rbenv makes _shim binaries_ for every such binary across all installed versions of Ruby. +Each version is a working tree with its own binaries, like +`~/.rbenv/versions/1.8.7-p354/bin/ruby` and +`~/.rbenv/versions/1.9.3-preview1/irb`. rbenv makes _shim binaries_ +for every such binary across all installed versions of Ruby. -These shims are simple wrapper scripts that live in `~/.rbenv/shims` and detect which Ruby version you want to use. They insert the directory for the selected version at the beginning of your `$PATH` and then execute the corresponding binary. +These shims are simple wrapper scripts that live in `~/.rbenv/shims` +and detect which Ruby version you want to use. They insert the +directory for the selected version at the beginning of your `$PATH` +and then execute the corresponding binary. -Because of the simplicity of the shim approach, all you need to use rbenv is `~/.rbenv/shims` in your `$PATH`. +Because of the simplicity of the shim approach, all you need to use +rbenv is `~/.rbenv/shims` in your `$PATH`. ## Installation @@ -37,47 +63,65 @@ rbenv is a young project, so for now you must install it from source. $ cd $ git clone git://github.com/sstephenson/rbenv.git .rbenv -2. Add `~/.rbenv/bin` to your `$PATH` for access to the `rbenv` command-line utility. +2. Add `~/.rbenv/bin` to your `$PATH` for access to the `rbenv` +command-line utility. $ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> .bash_profile -3. Add rbenv's shims directory to your `$PATH` and set up Bash autocompletion. (If you prefer not to load rbenv in your shell, you can manually add `$HOME/.rbenv/shims` to your path in step 2.) +3. Add rbenv's shims directory to your `$PATH` and set up Bash +autocompletion. (If you prefer not to load rbenv in your shell, you +can manually add `$HOME/.rbenv/shims` to your path in step 2.) $ echo 'eval "$(rbenv init -)"' >> .bash_profile 4. Restart your shell. You can now begin using rbenv. - $ exec $SHELL + $ exec -5. Install Ruby versions into `~/.rbenv/versions`. For example, to install Ruby 1.9.2-p290, download and unpack the source, then run: +5. Install Ruby versions into `~/.rbenv/versions`. For example, to +install Ruby 1.9.2-p290, download and unpack the source, then run: $ ./configure --prefix=~/.rbenv/versions/1.9.2-p290 $ make $ make install - The [ruby-build](https://github.com/sstephenson/ruby-build) project simplifies this process to a single command: + The [ruby-build](https://github.com/sstephenson/ruby-build) + project simplifies this process to a single command: $ ruby-build 1.9.2-p290 ~/.rbenv/versions/1.9.2-p290 -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). +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). $ rbenv rehash ## Usage -Like `git`, the `rbenv` command delegates to subcommands based on its first argument. The most common subcommands are: +Like `git`, the `rbenv` command delegates to subcommands based on its +first argument. The most common subcommands are: -* **set-default** — sets the default version of Ruby to be used in all shells by writing the version name to the `~/.rbenv/default` file. This version can be overridden by a per-project `.rbenv-version` file, or by setting the `RBENV_VERSION` environment variable. +* **set-default** — sets the default version of Ruby to be used in all + shells by writing the version name to the `~/.rbenv/default` + file. This version can be overridden by a per-project + `.rbenv-version` file, or by setting the `RBENV_VERSION` + environment variable. $ rbenv set-default 1.9.2-p290 - The special version name `system` tells rbenv to use the system Ruby (detected by searching your `$PATH`). + The special version name `system` tells rbenv to use the system + Ruby (detected by searching your `$PATH`). -* **set-local** — sets a local per-project Ruby version by writing the version name to an `.rbenv-version` file in the current directory. This version overrides the default, and can be overridden itself by setting the `RBENV_VERSION` environment variable. +* **set-local** — sets a local per-project Ruby version by writing the + version name to an `.rbenv-version` file in the current + directory. This version overrides the default, and can be + overridden itself by setting the `RBENV_VERSION` environment + variable. $ rbenv set-local rbx-1.2.4 -* **versions** — lists all Ruby versions known to rbenv, and shows an asterisk next to the currently active version. +* **versions** — lists all Ruby versions known to rbenv, and shows an + asterisk next to the currently active version. $ rbenv versions 1.8.7-p352 @@ -87,16 +131,20 @@ Like `git`, the `rbenv` command delegates to subcommands based on its first argu rbx-1.2.4 ree-1.8.7-2011.03 -* **version** — displays the currently active Ruby version, along with information on how it was set. +* **version** — displays the currently active Ruby version, along with + information on how it was set. $ rbenv version 1.8.7-p352 (set by /Volumes/37signals/basecamp/.rbenv-version) ## Contributing -The rbenv source code is [hosted on GitHub](https://github.com/sstephenson/rbenv). It's clean, modular, and easy to understand, even if you're not a shell hacker. +The rbenv source code is [hosted on +GitHub](https://github.com/sstephenson/rbenv). It's clean, modular, +and easy to understand, even if you're not a shell hacker. -Please feel free to submit pull requests and file bugs on the [issue tracker](https://github.com/sstephenson/rbenv/issues). +Please feel free to submit pull requests and file bugs on the [issue +tracker](https://github.com/sstephenson/rbenv/issues). ## License From 77964fb83ec66a5e9f79e944558c03ec7d18c90a Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Thu, 11 Aug 2011 13:25:47 -0500 Subject: [PATCH 059/384] Simplify --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index df320c20..ad2c234e 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # Simple Ruby Version Management: rbenv rbenv lets you easily switch between multiple versions of Ruby. It's -simple, unobtrusive, understandable, and follows in the Unix tradition -of single-purpose tools that do one thing well. +simple, unobtrusive, and follows the UNIX tradition of single-purpose +tools that do one thing well. ### rbenv _does…_ From f8f49fd565c4a0cda31f554139e1d84473627b50 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Thu, 11 Aug 2011 13:25:54 -0500 Subject: [PATCH 060/384] Document rbenv-rehash --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index ad2c234e..12e0b928 100644 --- a/README.md +++ b/README.md @@ -137,6 +137,13 @@ first argument. The most common subcommands are: $ rbenv version 1.8.7-p352 (set by /Volumes/37signals/basecamp/.rbenv-version) +* **rehash** — installs shims for all Ruby binaries known to rbenv + (i.e., `~/.rbenv/versions/*/bin/*`). Run this command after you + install a new version of Ruby, or install a gem that provides + binaries. + + $ rbenv rehash + ## Contributing The rbenv source code is [hosted on From 06bf3a351a21f3b832f230fe2ea892e8184df66a Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Thu, 11 Aug 2011 13:28:02 -0500 Subject: [PATCH 061/384] Add a note about rvm compatibility --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 12e0b928..82fed978 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,11 @@ rbenv is `~/.rbenv/shims` in your `$PATH`. rbenv is a young project, so for now you must install it from source. +**Compatibility note**: rbenv is _incompatible_ with rvm. Things will + appear to work until you try to install a gem. The problem is that + rvm actually overrides the `gem` command with a shell function! + Please remove any references to rvm before using rbenv. + 1. Check out rbenv into `~/.rbenv`. $ cd From 7c8da88df6a7998eb3206bce385fcae6465249ca Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Thu, 11 Aug 2011 14:12:01 -0500 Subject: [PATCH 062/384] Add a screenshot --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 82fed978..5d4ab0f5 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # Simple Ruby Version Management: rbenv + + rbenv lets you easily switch between multiple versions of Ruby. It's simple, unobtrusive, and follows the UNIX tradition of single-purpose tools that do one thing well. @@ -11,7 +13,7 @@ tools that do one thing well. * Allow you to **override the Ruby version** with an environment variable. -### rbenv _does not…_ +### In contrast with rvm, rbenv _does not…_ * **Need to be loaded into your shell.** Instead, rbenv's shim approach works by adding a directory to your `$PATH`. From 066d63c0dff1be07106ca73965bc3e32663cd806 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Thu, 11 Aug 2011 14:21:15 -0500 Subject: [PATCH 063/384] Use mdtoc for the readme --- README.md | 92 +++++++++++++--------- doc/README.mdtoc | 193 +++++++++++++++++++++++++++++++++++++++++++++++ doc/build | 4 + doc/mdtoc.rb | 82 ++++++++++++++++++++ 4 files changed, 334 insertions(+), 37 deletions(-) create mode 100644 doc/README.mdtoc create mode 100755 doc/build create mode 100644 doc/mdtoc.rb diff --git a/README.md b/README.md index 5d4ab0f5..5db99acd 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,18 @@ tools that do one thing well. of executing arbitrary code, rbenv reads just the version name from each project. There's nothing to "trust." -## How It Works + * [1 How It Works](#section_1) + * [2 Installation](#section_2) + * [3 Usage](#section_3) + * [3.1 set-default](#section_3.1) + * [3.2 set-local](#section_3.2) + * [3.3 versions](#section_3.3) + * [3.4 version](#section_3.4) + * [3.5 rehash](#section_3.5) + * [4 Contributing](#section_4) + * [4.1 License](#section_4.1) + +## 1 How It Works rbenv operates on the per-user directory `~/.rbenv`. Version names in rbenv correspond to subdirectories of `~/.rbenv/versions`. For @@ -56,7 +67,7 @@ and then execute the corresponding binary. Because of the simplicity of the shim approach, all you need to use rbenv is `~/.rbenv/shims` in your `$PATH`. -## Installation +## 2 Installation rbenv is a young project, so for now you must install it from source. @@ -103,55 +114,62 @@ when installing a gem that provides a binary). $ rbenv rehash -## Usage +## 3 Usage Like `git`, the `rbenv` command delegates to subcommands based on its first argument. The most common subcommands are: -* **set-default** — sets the default version of Ruby to be used in all - shells by writing the version name to the `~/.rbenv/default` - file. This version can be overridden by a per-project - `.rbenv-version` file, or by setting the `RBENV_VERSION` - environment variable. +### 3.1 set-default - $ rbenv set-default 1.9.2-p290 +Sets the default version of Ruby to be used in all shells by writing +the version name to the `~/.rbenv/default` file. This version can be +overridden by a per-project `.rbenv-version` file, or by setting the +`RBENV_VERSION` environment variable. - The special version name `system` tells rbenv to use the system - Ruby (detected by searching your `$PATH`). + $ rbenv set-default 1.9.2-p290 -* **set-local** — sets a local per-project Ruby version by writing the - version name to an `.rbenv-version` file in the current - directory. This version overrides the default, and can be - overridden itself by setting the `RBENV_VERSION` environment - variable. +The special version name `system` tells rbenv to use the system Ruby +(detected by searching your `$PATH`). - $ rbenv set-local rbx-1.2.4 +### 3.2 set-local -* **versions** — lists all Ruby versions known to rbenv, and shows an - asterisk next to the currently active version. +Sets a local per-project Ruby version by writing the version name to +an `.rbenv-version` file in the current directory. This version +overrides the default, and can be overridden itself by setting the +`RBENV_VERSION` environment variable. - $ rbenv versions - 1.8.7-p352 - 1.9.2-p290 - * 1.9.3-preview1 (set by /Users/sam/.rbenv/default) - jruby-1.6.3 - rbx-1.2.4 - ree-1.8.7-2011.03 + $ rbenv set-local rbx-1.2.4 -* **version** — displays the currently active Ruby version, along with - information on how it was set. +### 3.3 versions - $ rbenv version - 1.8.7-p352 (set by /Volumes/37signals/basecamp/.rbenv-version) +Lists all Ruby versions known to rbenv, and shows an asterisk next to +the currently active version. -* **rehash** — installs shims for all Ruby binaries known to rbenv - (i.e., `~/.rbenv/versions/*/bin/*`). Run this command after you - install a new version of Ruby, or install a gem that provides - binaries. + $ rbenv versions + 1.8.7-p352 + 1.9.2-p290 + * 1.9.3-preview1 (set by /Users/sam/.rbenv/default) + jruby-1.6.3 + rbx-1.2.4 + ree-1.8.7-2011.03 - $ rbenv rehash +### 3.4 version -## Contributing +Displays the currently active Ruby version, along with information on +how it was set. + + $ rbenv version + 1.8.7-p352 (set by /Volumes/37signals/basecamp/.rbenv-version) + +### 3.5 rehash + +Installs shims for all Ruby binaries known to rbenv (i.e., +`~/.rbenv/versions/*/bin/*`). Run this command after you install a new +version of Ruby, or install a gem that provides binaries. + + $ rbenv rehash + +## 4 Contributing The rbenv source code is [hosted on GitHub](https://github.com/sstephenson/rbenv). It's clean, modular, @@ -160,7 +178,7 @@ and easy to understand, even if you're not a shell hacker. Please feel free to submit pull requests and file bugs on the [issue tracker](https://github.com/sstephenson/rbenv/issues). -## License +### 4.1 License (The MIT license) diff --git a/doc/README.mdtoc b/doc/README.mdtoc new file mode 100644 index 00000000..5b443c59 --- /dev/null +++ b/doc/README.mdtoc @@ -0,0 +1,193 @@ +# Simple Ruby Version Management: rbenv + + + +rbenv lets you easily switch between multiple versions of Ruby. It's +simple, unobtrusive, and follows the UNIX tradition of single-purpose +tools that do one thing well. + +### rbenv _does…_ + +* Let you **change the default Ruby version** on a per-user basis. +* Provide support for **per-project Ruby versions**. +* Allow you to **override the Ruby version** with an environment + variable. + +### In contrast with rvm, rbenv _does not…_ + +* **Need to be loaded into your shell.** Instead, rbenv's shim + approach works by adding a directory to your `$PATH`. +* **Override shell commands like `cd`.** That's just obnoxious! +* **Have a configuration file.** There's nothing to configure except + which version of Ruby you want to use. +* **Install Ruby.** You can build and install Ruby yourself, or use + [ruby-build](https://github.com/sstephenson/ruby-build.git) to + automate the process. +* **Manage gemsets.** [Bundler](http://gembundler.com/) is a better + way to manage application dependencies. If you have projects that + are not yet using Bundler you can install the + [rbenv-gemset](https://github.com/jamis/rbenv-gemset) plugin. +* **Require changes to Ruby libraries for compatibility.** The + simplicity of rbenv means as long as it's in your `$PATH`, + [nothing](https://rvm.beginrescueend.com/integration/bundler/) + [else](https://rvm.beginrescueend.com/integration/capistrano/) + needs to know about it. +* **Prompt you with warnings when you switch to a project.** Instead + of executing arbitrary code, rbenv reads just the version name + from each project. There's nothing to "trust." + +## How It Works ## + +rbenv operates on the per-user directory `~/.rbenv`. Version names in +rbenv correspond to subdirectories of `~/.rbenv/versions`. For +example, you might have `~/.rbenv/versions/1.8.7-p354` and +`~/.rbenv/versions/1.9.3-preview1`. + +Each version is a working tree with its own binaries, like +`~/.rbenv/versions/1.8.7-p354/bin/ruby` and +`~/.rbenv/versions/1.9.3-preview1/irb`. rbenv makes _shim binaries_ +for every such binary across all installed versions of Ruby. + +These shims are simple wrapper scripts that live in `~/.rbenv/shims` +and detect which Ruby version you want to use. They insert the +directory for the selected version at the beginning of your `$PATH` +and then execute the corresponding binary. + +Because of the simplicity of the shim approach, all you need to use +rbenv is `~/.rbenv/shims` in your `$PATH`. + +## Installation ## + +rbenv is a young project, so for now you must install it from source. + +**Compatibility note**: rbenv is _incompatible_ with rvm. Things will + appear to work until you try to install a gem. The problem is that + rvm actually overrides the `gem` command with a shell function! + Please remove any references to rvm before using rbenv. + +1. Check out rbenv into `~/.rbenv`. + + $ cd + $ git clone git://github.com/sstephenson/rbenv.git .rbenv + +2. Add `~/.rbenv/bin` to your `$PATH` for access to the `rbenv` +command-line utility. + + $ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> .bash_profile + +3. Add rbenv's shims directory to your `$PATH` and set up Bash +autocompletion. (If you prefer not to load rbenv in your shell, you +can manually add `$HOME/.rbenv/shims` to your path in step 2.) + + $ echo 'eval "$(rbenv init -)"' >> .bash_profile + +4. Restart your shell. You can now begin using rbenv. + + $ exec + +5. Install Ruby versions into `~/.rbenv/versions`. For example, to +install Ruby 1.9.2-p290, download and unpack the source, then run: + + $ ./configure --prefix=~/.rbenv/versions/1.9.2-p290 + $ make + $ make install + + The [ruby-build](https://github.com/sstephenson/ruby-build) + project simplifies this process to a single command: + + $ ruby-build 1.9.2-p290 ~/.rbenv/versions/1.9.2-p290 + +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). + + $ rbenv rehash + +## Usage ## + +Like `git`, the `rbenv` command delegates to subcommands based on its +first argument. The most common subcommands are: + +### set-default ### + +Sets the default version of Ruby to be used in all shells by writing +the version name to the `~/.rbenv/default` file. This version can be +overridden by a per-project `.rbenv-version` file, or by setting the +`RBENV_VERSION` environment variable. + + $ rbenv set-default 1.9.2-p290 + +The special version name `system` tells rbenv to use the system Ruby +(detected by searching your `$PATH`). + +### set-local ### + +Sets a local per-project Ruby version by writing the version name to +an `.rbenv-version` file in the current directory. This version +overrides the default, and can be overridden itself by setting the +`RBENV_VERSION` environment variable. + + $ rbenv set-local rbx-1.2.4 + +### versions ### + +Lists all Ruby versions known to rbenv, and shows an asterisk next to +the currently active version. + + $ rbenv versions + 1.8.7-p352 + 1.9.2-p290 + * 1.9.3-preview1 (set by /Users/sam/.rbenv/default) + jruby-1.6.3 + rbx-1.2.4 + ree-1.8.7-2011.03 + +### version ### + +Displays the currently active Ruby version, along with information on +how it was set. + + $ rbenv version + 1.8.7-p352 (set by /Volumes/37signals/basecamp/.rbenv-version) + +### rehash ### + +Installs shims for all Ruby binaries known to rbenv (i.e., +`~/.rbenv/versions/*/bin/*`). Run this command after you install a new +version of Ruby, or install a gem that provides binaries. + + $ rbenv rehash + +## Contributing ## + +The rbenv source code is [hosted on +GitHub](https://github.com/sstephenson/rbenv). It's clean, modular, +and easy to understand, even if you're not a shell hacker. + +Please feel free to submit pull requests and file bugs on the [issue +tracker](https://github.com/sstephenson/rbenv/issues). + +### License ### + +(The MIT license) + +Copyright (c) 2011 Sam Stephenson + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/doc/build b/doc/build new file mode 100755 index 00000000..3d542d44 --- /dev/null +++ b/doc/build @@ -0,0 +1,4 @@ +#!/bin/sh -e + +ruby mdtoc.rb README.mdtoc > ../README.md + diff --git a/doc/mdtoc.rb b/doc/mdtoc.rb new file mode 100644 index 00000000..1bd8d5f4 --- /dev/null +++ b/doc/mdtoc.rb @@ -0,0 +1,82 @@ +#!/usr/bin/env ruby + +# A little Markdown filter that scans your document for headings, +# numbers them, adds anchors, and inserts a table of contents. +# +# To use it, make sure the headings you want numbered and linked are +# in this format: +# +# ### Title ### +# +# I.e. they must have an equal number of octothorpes around the title +# text. (In Markdown, `#` means `h1`, `##` means `h2`, and so on.) +# The table of contents will be inserted before the first such +# heading. +# +# Released into the public domain. +# Sam Stephenson +# 2011-04-30 + +def mdtoc(markdown) + titles = [] + lines = markdown.split($/) + start = nil + + # First pass: Scan the Markdown source looking for titles of the + # format: `### Title ###`. Record the line number, header level + # (number of octothorpes), and text of each matching title. + lines.each_with_index do |line, line_no| + if line.match(/^(\#{1,6})\s+(.+?)\s+\1$/) + titles << [line_no, $1.length, $2] + start ||= line_no + end + end + + last_section = nil + last_level = nil + + # Second pass: Iterate over all matched titles and compute their + # corresponding section numbers. Then replace the titles with + # annotated anchors. + titles.each do |title_info| + line_no, level, text = title_info + + if last_section + section = last_section.dup + + if last_level < level + section << 1 + else + (last_level - level).times { section.pop } + section[-1] += 1 + end + else + section = [1] + end + + name = section.join(".") + lines[line_no] = %(#{"#" * level} #{name} #{text}) + + title_info << section + last_section = section + last_level = level + end + + # Third pass: Iterate over matched titles once more to produce the + # table of contents. Then insert it immediately above the first + # matched title. + if start + toc = titles.map do |(line_no, level, text, section)| + name = section.join(".") + %(#{" " * (section.length * 3)}* [#{name} #{text}](#section_#{name})) + end + [""] + + lines.insert(start, *toc) + end + + lines.join("\n") +end + +if __FILE__ == $0 + puts mdtoc($<.read) +end From bfa71017ae3de7a880751228a9c2bcc13b76cb48 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Thu, 11 Aug 2011 14:25:08 -0500 Subject: [PATCH 064/384] Add TOC header --- README.md | 2 ++ doc/README.mdtoc | 2 ++ 2 files changed, 4 insertions(+) diff --git a/README.md b/README.md index 5db99acd..a3c2c677 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,8 @@ tools that do one thing well. of executing arbitrary code, rbenv reads just the version name from each project. There's nothing to "trust." +## Table of Contents + * [1 How It Works](#section_1) * [2 Installation](#section_2) * [3 Usage](#section_3) diff --git a/doc/README.mdtoc b/doc/README.mdtoc index 5b443c59..50955432 100644 --- a/doc/README.mdtoc +++ b/doc/README.mdtoc @@ -36,6 +36,8 @@ tools that do one thing well. of executing arbitrary code, rbenv reads just the version name from each project. There's nothing to "trust." +## Table of Contents + ## How It Works ## rbenv operates on the per-user directory `~/.rbenv`. Version names in From 6c468d616659d734f90470d2c393a169c69d6869 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Thu, 11 Aug 2011 14:26:53 -0500 Subject: [PATCH 065/384] Don't highlight the anchors --- README.md | 20 ++++++++++---------- doc/mdtoc.rb | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index a3c2c677..4d0f5edd 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ tools that do one thing well. * [4 Contributing](#section_4) * [4.1 License](#section_4.1) -## 1 How It Works +## 1 How It Works rbenv operates on the per-user directory `~/.rbenv`. Version names in rbenv correspond to subdirectories of `~/.rbenv/versions`. For @@ -69,7 +69,7 @@ and then execute the corresponding binary. Because of the simplicity of the shim approach, all you need to use rbenv is `~/.rbenv/shims` in your `$PATH`. -## 2 Installation +## 2 Installation rbenv is a young project, so for now you must install it from source. @@ -116,12 +116,12 @@ when installing a gem that provides a binary). $ rbenv rehash -## 3 Usage +## 3 Usage Like `git`, the `rbenv` command delegates to subcommands based on its first argument. The most common subcommands are: -### 3.1 set-default +### 3.1 set-default Sets the default version of Ruby to be used in all shells by writing the version name to the `~/.rbenv/default` file. This version can be @@ -133,7 +133,7 @@ overridden by a per-project `.rbenv-version` file, or by setting the The special version name `system` tells rbenv to use the system Ruby (detected by searching your `$PATH`). -### 3.2 set-local +### 3.2 set-local Sets a local per-project Ruby version by writing the version name to an `.rbenv-version` file in the current directory. This version @@ -142,7 +142,7 @@ overrides the default, and can be overridden itself by setting the $ rbenv set-local rbx-1.2.4 -### 3.3 versions +### 3.3 versions Lists all Ruby versions known to rbenv, and shows an asterisk next to the currently active version. @@ -155,7 +155,7 @@ the currently active version. rbx-1.2.4 ree-1.8.7-2011.03 -### 3.4 version +### 3.4 version Displays the currently active Ruby version, along with information on how it was set. @@ -163,7 +163,7 @@ how it was set. $ rbenv version 1.8.7-p352 (set by /Volumes/37signals/basecamp/.rbenv-version) -### 3.5 rehash +### 3.5 rehash Installs shims for all Ruby binaries known to rbenv (i.e., `~/.rbenv/versions/*/bin/*`). Run this command after you install a new @@ -171,7 +171,7 @@ version of Ruby, or install a gem that provides binaries. $ rbenv rehash -## 4 Contributing +## 4 Contributing The rbenv source code is [hosted on GitHub](https://github.com/sstephenson/rbenv). It's clean, modular, @@ -180,7 +180,7 @@ and easy to understand, even if you're not a shell hacker. Please feel free to submit pull requests and file bugs on the [issue tracker](https://github.com/sstephenson/rbenv/issues). -### 4.1 License +### 4.1 License (The MIT license) diff --git a/doc/mdtoc.rb b/doc/mdtoc.rb index 1bd8d5f4..3c5a1735 100644 --- a/doc/mdtoc.rb +++ b/doc/mdtoc.rb @@ -55,7 +55,7 @@ def mdtoc(markdown) end name = section.join(".") - lines[line_no] = %(#{"#" * level} #{name} #{text}) + lines[line_no] = %(#{"#" * level} #{name} #{text}) title_info << section last_section = section From 192dc239986b149454fcc87bb6bb27e2fd1ebcbf Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Thu, 11 Aug 2011 14:29:52 -0500 Subject: [PATCH 066/384] Try a different image url --- README.md | 2 +- doc/README.mdtoc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4d0f5edd..ec9d8501 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Simple Ruby Version Management: rbenv - + rbenv lets you easily switch between multiple versions of Ruby. It's simple, unobtrusive, and follows the UNIX tradition of single-purpose diff --git a/doc/README.mdtoc b/doc/README.mdtoc index 50955432..5622418f 100644 --- a/doc/README.mdtoc +++ b/doc/README.mdtoc @@ -1,6 +1,6 @@ # Simple Ruby Version Management: rbenv - + rbenv lets you easily switch between multiple versions of Ruby. It's simple, unobtrusive, and follows the UNIX tradition of single-purpose From dfe98893271fadaa1739312f5245a317151be775 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Thu, 11 Aug 2011 14:41:24 -0500 Subject: [PATCH 067/384] Fix ruby-build link --- README.md | 2 +- doc/README.mdtoc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ec9d8501..e2a9fa85 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ tools that do one thing well. * **Have a configuration file.** There's nothing to configure except which version of Ruby you want to use. * **Install Ruby.** You can build and install Ruby yourself, or use - [ruby-build](https://github.com/sstephenson/ruby-build.git) to + [ruby-build](https://github.com/sstephenson/ruby-build) to automate the process. * **Manage gemsets.** [Bundler](http://gembundler.com/) is a better way to manage application dependencies. If you have projects that diff --git a/doc/README.mdtoc b/doc/README.mdtoc index 5622418f..8c7ce7dc 100644 --- a/doc/README.mdtoc +++ b/doc/README.mdtoc @@ -21,7 +21,7 @@ tools that do one thing well. * **Have a configuration file.** There's nothing to configure except which version of Ruby you want to use. * **Install Ruby.** You can build and install Ruby yourself, or use - [ruby-build](https://github.com/sstephenson/ruby-build.git) to + [ruby-build](https://github.com/sstephenson/ruby-build) to automate the process. * **Manage gemsets.** [Bundler](http://gembundler.com/) is a better way to manage application dependencies. If you have projects that From 5c11f14c9bfb80a4efd640125dc309125c746a64 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Thu, 11 Aug 2011 14:48:40 -0500 Subject: [PATCH 068/384] rbenv 0.1.0 --- libexec/rbenv-help | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libexec/rbenv-help b/libexec/rbenv-help index 105eeee4..e1c58b4f 100755 --- a/libexec/rbenv-help +++ b/libexec/rbenv-help @@ -27,7 +27,7 @@ Some useful rbenv commands are: versions List all Ruby versions known by rbenv See 'rbenv help ' for more information on a specific command. -For a quick guide to rbenv, see: https://gist.github.com/1120938" +For more information, see: https://github.com/sstephenson/rbenv#readme ;; set-default) echo "usage: rbenv set-default From aae721c5f1fe6cd773fb19ece9b60e8a5911342f Mon Sep 17 00:00:00 2001 From: Chris Moore Date: Thu, 11 Aug 2011 17:43:57 -0400 Subject: [PATCH 069/384] fix typo in rbenv help --- libexec/rbenv-help | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libexec/rbenv-help b/libexec/rbenv-help index e1c58b4f..2b1bba08 100755 --- a/libexec/rbenv-help +++ b/libexec/rbenv-help @@ -27,7 +27,7 @@ Some useful rbenv commands are: versions List all Ruby versions known by rbenv See 'rbenv help ' for more information on a specific command. -For more information, see: https://github.com/sstephenson/rbenv#readme +For more information, see: https://github.com/sstephenson/rbenv#readme" ;; set-default) echo "usage: rbenv set-default From b4c100e1491c7e4fbc6f256bccaaa0cc0f35851d Mon Sep 17 00:00:00 2001 From: Chris Ledet Date: Thu, 11 Aug 2011 22:19:33 -0400 Subject: [PATCH 070/384] use HOME variable when specifying the install dir --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e2a9fa85..7db3ed15 100644 --- a/README.md +++ b/README.md @@ -101,14 +101,14 @@ can manually add `$HOME/.rbenv/shims` to your path in step 2.) 5. Install Ruby versions into `~/.rbenv/versions`. For example, to install Ruby 1.9.2-p290, download and unpack the source, then run: - $ ./configure --prefix=~/.rbenv/versions/1.9.2-p290 + $ ./configure --prefix=$HOME/.rbenv/versions/1.9.2-p290 $ make $ make install The [ruby-build](https://github.com/sstephenson/ruby-build) project simplifies this process to a single command: - $ ruby-build 1.9.2-p290 ~/.rbenv/versions/1.9.2-p290 + $ ruby-build 1.9.2-p290 $HOME/.rbenv/versions/1.9.2-p290 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 From 6938692ca2d57d93819cd22e5a709cb541a61b50 Mon Sep 17 00:00:00 2001 From: Andreas Johansson Date: Fri, 12 Aug 2011 11:33:45 +0200 Subject: [PATCH 071/384] Fix argument that cannot be sent to bash via env /usr/bin/env seems to have problems with arguments to bash on some platforms. To bypass this, use set -e instead. --- libexec/rbenv | 3 ++- libexec/rbenv-commands | 3 ++- libexec/rbenv-exec | 3 ++- libexec/rbenv-help | 3 ++- libexec/rbenv-init | 3 ++- libexec/rbenv-prefix | 3 ++- libexec/rbenv-rehash | 6 ++++-- libexec/rbenv-set-default | 3 ++- libexec/rbenv-set-local | 3 ++- libexec/rbenv-version | 3 ++- libexec/rbenv-version-name | 3 ++- libexec/rbenv-version-origin | 3 ++- libexec/rbenv-versions | 3 ++- libexec/rbenv-whence | 3 ++- libexec/rbenv-which | 3 ++- 15 files changed, 32 insertions(+), 16 deletions(-) diff --git a/libexec/rbenv b/libexec/rbenv index 74ab8928..b979ca85 100755 --- a/libexec/rbenv +++ b/libexec/rbenv @@ -1,4 +1,5 @@ -#!/usr/bin/env bash -e +#!/usr/bin/env bash +set -e abs_dirname() { local cwd="$(pwd)" diff --git a/libexec/rbenv-commands b/libexec/rbenv-commands index 49ba268b..43846ce4 100755 --- a/libexec/rbenv-commands +++ b/libexec/rbenv-commands @@ -1,4 +1,5 @@ -#!/usr/bin/env bash -e +#!/usr/bin/env bash +set -e shopt -s nullglob diff --git a/libexec/rbenv-exec b/libexec/rbenv-exec index a538a52f..3e3929d9 100755 --- a/libexec/rbenv-exec +++ b/libexec/rbenv-exec @@ -1,4 +1,5 @@ -#!/usr/bin/env bash -e +#!/usr/bin/env bash +set -e RBENV_COMMAND="$1" if [ -z "$RBENV_COMMAND" ]; then diff --git a/libexec/rbenv-help b/libexec/rbenv-help index 2b1bba08..8820b200 100755 --- a/libexec/rbenv-help +++ b/libexec/rbenv-help @@ -1,4 +1,5 @@ -#!/usr/bin/env bash -e +#!/usr/bin/env bash +set -e print_set_version() { echo " should be a string matching a Ruby version known by rbenv." diff --git a/libexec/rbenv-init b/libexec/rbenv-init index 6b9765f2..d695879b 100755 --- a/libexec/rbenv-init +++ b/libexec/rbenv-init @@ -1,4 +1,5 @@ -#!/usr/bin/env bash -e +#!/usr/bin/env bash +set -e print="" if [ "$1" = "-" ]; then diff --git a/libexec/rbenv-prefix b/libexec/rbenv-prefix index f65701f6..3f22e7ee 100755 --- a/libexec/rbenv-prefix +++ b/libexec/rbenv-prefix @@ -1,4 +1,5 @@ -#!/usr/bin/env bash -e +#!/usr/bin/env bash +set -e if [ -n "$1" ]; then RBENV_VERSION="$1" diff --git a/libexec/rbenv-rehash b/libexec/rbenv-rehash index 6254d0aa..0259fe1b 100755 --- a/libexec/rbenv-rehash +++ b/libexec/rbenv-rehash @@ -1,8 +1,10 @@ -#!/usr/bin/env bash -e +#!/usr/bin/env bash +set -e create_prototype_shim() { cat > .rbenv-shim < Date: Fri, 12 Aug 2011 10:51:58 -0500 Subject: [PATCH 072/384] Let's not bruise any egos --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e2a9fa85..467bbe3f 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,8 @@ tools that do one thing well. * **Need to be loaded into your shell.** Instead, rbenv's shim approach works by adding a directory to your `$PATH`. -* **Override shell commands like `cd`.** That's just obnoxious! +* **Override shell commands like `cd`.** That's dangerous and + error-prone. * **Have a configuration file.** There's nothing to configure except which version of Ruby you want to use. * **Install Ruby.** You can build and install Ruby yourself, or use From 7a0cde9a4e871983d0fee058ccfa3aa4c886502f Mon Sep 17 00:00:00 2001 From: Graham Ashton Date: Sat, 13 Aug 2011 07:34:15 +0100 Subject: [PATCH 073/384] Remove set- prefix from local and default commands. --- README.md | 12 ++++++------ completions/rbenv.bash | 2 +- libexec/rbenv-default | 12 ++++++++++++ libexec/rbenv-help | 12 ++++++------ libexec/rbenv-local | 12 ++++++++++++ libexec/rbenv-set-default | 12 ++---------- libexec/rbenv-set-local | 12 ++---------- 7 files changed, 41 insertions(+), 33 deletions(-) create mode 100755 libexec/rbenv-default create mode 100755 libexec/rbenv-local diff --git a/README.md b/README.md index 467bbe3f..4bb518b5 100644 --- a/README.md +++ b/README.md @@ -42,8 +42,8 @@ tools that do one thing well. * [1 How It Works](#section_1) * [2 Installation](#section_2) * [3 Usage](#section_3) - * [3.1 set-default](#section_3.1) - * [3.2 set-local](#section_3.2) + * [3.1 default](#section_3.1) + * [3.2 local](#section_3.2) * [3.3 versions](#section_3.3) * [3.4 version](#section_3.4) * [3.5 rehash](#section_3.5) @@ -122,26 +122,26 @@ when installing a gem that provides a binary). Like `git`, the `rbenv` command delegates to subcommands based on its first argument. The most common subcommands are: -### 3.1 set-default +### 3.1 default Sets the default version of Ruby to be used in all shells by writing the version name to the `~/.rbenv/default` file. This version can be overridden by a per-project `.rbenv-version` file, or by setting the `RBENV_VERSION` environment variable. - $ rbenv set-default 1.9.2-p290 + $ rbenv default 1.9.2-p290 The special version name `system` tells rbenv to use the system Ruby (detected by searching your `$PATH`). -### 3.2 set-local +### 3.2 local Sets a local per-project Ruby version by writing the version name to an `.rbenv-version` file in the current directory. This version overrides the default, and can be overridden itself by setting the `RBENV_VERSION` environment variable. - $ rbenv set-local rbx-1.2.4 + $ rbenv local rbx-1.2.4 ### 3.3 versions diff --git a/completions/rbenv.bash b/completions/rbenv.bash index 0e8a383d..3ad2aa21 100644 --- a/completions/rbenv.bash +++ b/completions/rbenv.bash @@ -17,7 +17,7 @@ _rbenv() { local prev="${COMP_WORDS[COMP_CWORD-1]}" case "$prev" in - set-* | prefix ) + default | local | prefix ) _rbenv_versions ;; * ) diff --git a/libexec/rbenv-default b/libexec/rbenv-default new file mode 100755 index 00000000..4e616cf4 --- /dev/null +++ b/libexec/rbenv-default @@ -0,0 +1,12 @@ +#!/usr/bin/env bash -e + +RBENV_VERSION="$1" +if [ -z "$RBENV_VERSION" ]; then + echo "usage: rbenv default VERSION" >&2 + exit 1 +fi + +# Make sure the specified version is installed +rbenv-prefix "$RBENV_VERSION" >/dev/null + +echo "$RBENV_VERSION" > "${HOME}/.rbenv/default" diff --git a/libexec/rbenv-help b/libexec/rbenv-help index 8820b200..ef8f1dfd 100755 --- a/libexec/rbenv-help +++ b/libexec/rbenv-help @@ -22,23 +22,23 @@ case "$1" in Some useful rbenv commands are: commands List all commands rehash Rehash rbenv shims (run this after installing binaries) - set-default Set the default Ruby version - set-local Set a local directory-specific Ruby version + default Set the default Ruby version + local Set a local directory-specific Ruby version version Show the current Ruby version versions List all Ruby versions known by rbenv See 'rbenv help ' for more information on a specific command. For more information, see: https://github.com/sstephenson/rbenv#readme" ;; -set-default) echo "usage: rbenv set-default +default) echo "usage: rbenv default Sets the default Ruby version. You can override the default at any time -by setting a directory-specific version with \`rbenv set-local' or by +by setting a directory-specific version with \`rbenv local' or by setting the RBENV_VERSION environment variable. $(print_set_version)" ;; -set-local) echo "usage: rbenv set-local +local) echo "usage: rbenv local Sets the local directory-specific Ruby version by writing the version name to a file named '.rbenv-version'. @@ -46,7 +46,7 @@ name to a file named '.rbenv-version'. When you run a Ruby command, rbenv will look for an '.rbenv-version' file in the current directory and each parent directory. If no such file is found in the tree, rbenv will use the default Ruby version -specified with \`rbenv set-default', or the version specified in the +specified with \`rbenv default', or the version specified in the RBENV_VERSION environment variable. $(print_set_version)" diff --git a/libexec/rbenv-local b/libexec/rbenv-local new file mode 100755 index 00000000..fc94ec2d --- /dev/null +++ b/libexec/rbenv-local @@ -0,0 +1,12 @@ +#!/usr/bin/env bash -e + +RBENV_VERSION="$1" +if [ -z "$RBENV_VERSION" ]; then + echo "usage: rbenv local VERSION" >&2 + exit 1 +fi + +# Make sure the specified version is installed +rbenv-prefix "$RBENV_VERSION" >/dev/null + +echo "$RBENV_VERSION" > .rbenv-version diff --git a/libexec/rbenv-set-default b/libexec/rbenv-set-default index ba6bbb5c..cff1eb09 100755 --- a/libexec/rbenv-set-default +++ b/libexec/rbenv-set-default @@ -1,13 +1,5 @@ #!/usr/bin/env bash set -e -RBENV_VERSION="$1" -if [ -z "$RBENV_VERSION" ]; then - echo "usage: rbenv set-default VERSION" >&2 - exit 1 -fi - -# Make sure the specified version is installed -rbenv-prefix "$RBENV_VERSION" >/dev/null - -echo "$RBENV_VERSION" > "${HOME}/.rbenv/default" +echo "set-default has been renamed to default" >&2 +rbenv-default "$@" diff --git a/libexec/rbenv-set-local b/libexec/rbenv-set-local index 7ce0fe2f..a93ec24e 100755 --- a/libexec/rbenv-set-local +++ b/libexec/rbenv-set-local @@ -1,13 +1,5 @@ #!/usr/bin/env bash set -e -RBENV_VERSION="$1" -if [ -z "$RBENV_VERSION" ]; then - echo "usage: rbenv set-local VERSION" >&2 - exit 1 -fi - -# Make sure the specified version is installed -rbenv-prefix "$RBENV_VERSION" >/dev/null - -echo "$RBENV_VERSION" > .rbenv-version +echo "set-local has been renamed to local" >&2 +rbenv-local "$@" From 1ed231cb21afe7619513379e46ec3fa83ad91154 Mon Sep 17 00:00:00 2001 From: Graham Ashton Date: Sat, 13 Aug 2011 07:50:23 +0100 Subject: [PATCH 074/384] Report default or local version. If no argument is passed to the default or local sub commands, report the currently configured version. --- README.md | 6 ++++++ libexec/rbenv-default | 18 +++++++++++------- libexec/rbenv-help | 4 ++-- libexec/rbenv-local | 17 +++++++++++------ 4 files changed, 30 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 4bb518b5..9635b362 100644 --- a/README.md +++ b/README.md @@ -134,6 +134,9 @@ overridden by a per-project `.rbenv-version` file, or by setting the The special version name `system` tells rbenv to use the system Ruby (detected by searching your `$PATH`). +When run without a version number the currently configured default +version is reported. + ### 3.2 local Sets a local per-project Ruby version by writing the version name to @@ -143,6 +146,9 @@ overrides the default, and can be overridden itself by setting the $ rbenv local rbx-1.2.4 +When run without a version number the currently configured local +version is reported. + ### 3.3 versions Lists all Ruby versions known to rbenv, and shows an asterisk next to diff --git a/libexec/rbenv-default b/libexec/rbenv-default index 4e616cf4..56f1276e 100755 --- a/libexec/rbenv-default +++ b/libexec/rbenv-default @@ -1,12 +1,16 @@ #!/usr/bin/env bash -e RBENV_VERSION="$1" +VERSION_FILE="${HOME}/.rbenv/default" if [ -z "$RBENV_VERSION" ]; then - echo "usage: rbenv default VERSION" >&2 - exit 1 + if [[ -e "$VERSION_FILE" ]]; then + cat "$VERSION_FILE" + else + echo "No default version configured - set with: rbenv default " + fi +else + # Make sure the specified version is installed + rbenv-prefix "$RBENV_VERSION" >/dev/null + + echo "$RBENV_VERSION" > "$VERSION_FILE" fi - -# Make sure the specified version is installed -rbenv-prefix "$RBENV_VERSION" >/dev/null - -echo "$RBENV_VERSION" > "${HOME}/.rbenv/default" diff --git a/libexec/rbenv-help b/libexec/rbenv-help index ef8f1dfd..4acb7dc6 100755 --- a/libexec/rbenv-help +++ b/libexec/rbenv-help @@ -22,8 +22,8 @@ case "$1" in Some useful rbenv commands are: commands List all commands rehash Rehash rbenv shims (run this after installing binaries) - default Set the default Ruby version - local Set a local directory-specific Ruby version + default Set or show the default Ruby version + local Set or show the local directory-specific Ruby version version Show the current Ruby version versions List all Ruby versions known by rbenv diff --git a/libexec/rbenv-local b/libexec/rbenv-local index fc94ec2d..cfc72067 100755 --- a/libexec/rbenv-local +++ b/libexec/rbenv-local @@ -1,12 +1,17 @@ #!/usr/bin/env bash -e RBENV_VERSION="$1" +VERSION_FILE=".rbenv-version" if [ -z "$RBENV_VERSION" ]; then - echo "usage: rbenv local VERSION" >&2 - exit 1 + if [[ -e "$VERSION_FILE" ]]; then + cat "$VERSION_FILE" + else + echo "No local version configured - set with: rbenv local " + fi +else + # Make sure the specified version is installed + rbenv-prefix "$RBENV_VERSION" >/dev/null + + echo "$RBENV_VERSION" > "$VERSION_FILE" fi -# Make sure the specified version is installed -rbenv-prefix "$RBENV_VERSION" >/dev/null - -echo "$RBENV_VERSION" > .rbenv-version From a14095f2990b072a0f1e7bbf5051245ab9eca1d4 Mon Sep 17 00:00:00 2001 From: Samuel Cochran Date: Sun, 14 Aug 2011 21:30:13 +0800 Subject: [PATCH 075/384] Add "-h" and "--help" which work as expected --- libexec/rbenv | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/libexec/rbenv b/libexec/rbenv index b979ca85..d7e1d567 100755 --- a/libexec/rbenv +++ b/libexec/rbenv @@ -19,10 +19,11 @@ libexec_path="$(abs_dirname "$0")" export PATH="${libexec_path}:${PATH}" command="$1" -if [ -z "$command" ]; then +case $command in +"" | "-h" | "--help") echo -e "rbenv 0.1.0\n$(rbenv-help)" >&2 - -else + ;; +*) command_path="$(command -v "rbenv-$command" || true)" if [ -z "$command_path" ]; then echo "rbenv: no such command \`$command'" >&2 @@ -31,4 +32,5 @@ else shift 1 exec "$command_path" "$@" -fi + ;; +esac From e43a2039a5a7f6370fd08031db5b36dab9152826 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Sun, 14 Aug 2011 13:47:07 -0500 Subject: [PATCH 076/384] Sync mdtoc source --- doc/README.mdtoc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/doc/README.mdtoc b/doc/README.mdtoc index 8c7ce7dc..b49618ef 100644 --- a/doc/README.mdtoc +++ b/doc/README.mdtoc @@ -17,7 +17,8 @@ tools that do one thing well. * **Need to be loaded into your shell.** Instead, rbenv's shim approach works by adding a directory to your `$PATH`. -* **Override shell commands like `cd`.** That's just obnoxious! +* **Override shell commands like `cd`.** That's dangerous and + error-prone. * **Have a configuration file.** There's nothing to configure except which version of Ruby you want to use. * **Install Ruby.** You can build and install Ruby yourself, or use @@ -90,14 +91,14 @@ can manually add `$HOME/.rbenv/shims` to your path in step 2.) 5. Install Ruby versions into `~/.rbenv/versions`. For example, to install Ruby 1.9.2-p290, download and unpack the source, then run: - $ ./configure --prefix=~/.rbenv/versions/1.9.2-p290 + $ ./configure --prefix=$HOME/.rbenv/versions/1.9.2-p290 $ make $ make install The [ruby-build](https://github.com/sstephenson/ruby-build) project simplifies this process to a single command: - $ ruby-build 1.9.2-p290 ~/.rbenv/versions/1.9.2-p290 + $ ruby-build 1.9.2-p290 $HOME/.rbenv/versions/1.9.2-p290 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 From bd1e56ff370413199de14f080192fd0194859958 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Sun, 14 Aug 2011 13:51:51 -0500 Subject: [PATCH 077/384] rbenv 0.1.1 --- libexec/rbenv | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libexec/rbenv b/libexec/rbenv index d7e1d567..5e6b20d4 100755 --- a/libexec/rbenv +++ b/libexec/rbenv @@ -19,11 +19,11 @@ libexec_path="$(abs_dirname "$0")" export PATH="${libexec_path}:${PATH}" command="$1" -case $command in -"" | "-h" | "--help") - echo -e "rbenv 0.1.0\n$(rbenv-help)" >&2 +case "$command" in +"" | "-h" | "--help" ) + echo -e "rbenv 0.1.1\n$(rbenv-help)" >&2 ;; -*) +* ) command_path="$(command -v "rbenv-$command" || true)" if [ -z "$command_path" ]; then echo "rbenv: no such command \`$command'" >&2 From 3efdf6a2430b72bc5f6fe2c25752619d28fd9661 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Sun, 14 Aug 2011 14:16:26 -0500 Subject: [PATCH 078/384] Guard against nonexistent entries in $PATH --- libexec/rbenv-which | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libexec/rbenv-which b/libexec/rbenv-which index 5e605628..0f8fd2c5 100755 --- a/libexec/rbenv-which +++ b/libexec/rbenv-which @@ -2,6 +2,10 @@ set -e expand_path() { + if [ ! -d "$1" ]; then + return 1 + fi + local cwd="$(pwd)" cd "$1" pwd @@ -14,7 +18,7 @@ remove_from_path() { for path in ${PATH//:/$'\n'}; do path="$(expand_path "$path" || true)" - if [ "$path" != "$path_to_remove" ]; then + if [ -n "$path" ] && [ "$path" != "$path_to_remove" ]; then result="${result}${path}:" fi done From dd8a005c7d70b61667d14246ca63def49650cc3c Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Mon, 15 Aug 2011 01:16:13 -0500 Subject: [PATCH 079/384] Atomic rehash --- libexec/rbenv-rehash | 50 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 42 insertions(+), 8 deletions(-) diff --git a/libexec/rbenv-rehash b/libexec/rbenv-rehash index 0259fe1b..e1078fc8 100755 --- a/libexec/rbenv-rehash +++ b/libexec/rbenv-rehash @@ -1,31 +1,67 @@ #!/usr/bin/env bash set -e +SHIM_PATH="${HOME}/.rbenv/shims" +PROTOTYPE_SHIM_PATH="${SHIM_PATH}/.rbenv-shim" + +# Create the shims directory if it doesn't already exist. +mkdir -p "$SHIM_PATH" + +# Ensure only one instance of rbenv-rehash is running at a time by +# setting the shell's `noclobber` option and attempting to write to +# the prototype shim file. If the file already exists, print a warning +# to stderr and exit with a non-zero status. +set -o noclobber +{ echo > "$PROTOTYPE_SHIM_PATH" +} 2>/dev/null || +{ echo "rbenv: cannot rehash: $PROTOTYPE_SHIM_PATH exists" + exit 1 +} >&2 +set +o noclobber + +# If we were able to obtain a lock, register a trap to clean up the +# prototype shim when the process exits. +trap remove_prototype_shim SIGINT SIGTERM EXIT + +remove_prototype_shim() { + rm -f "$PROTOTYPE_SHIM_PATH" +} + +# The prototype shim file is a script that re-execs itself, passing +# its filename and any arguments to `rbenv exec`. This file is +# hard-linked for every binary and then removed. The linking technique +# is fast, uses less disk space than unique files, and also serves as +# a locking mechanism. create_prototype_shim() { - cat > .rbenv-shim < "$PROTOTYPE_SHIM_PATH" < Date: Mon, 15 Aug 2011 01:18:04 -0500 Subject: [PATCH 080/384] Run `rbenv rehash` on init --- libexec/rbenv-init | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libexec/rbenv-init b/libexec/rbenv-init index d695879b..4dc751dd 100755 --- a/libexec/rbenv-init +++ b/libexec/rbenv-init @@ -58,3 +58,5 @@ echo 'export PATH="${HOME}/.rbenv/shims:${PATH}"' if [ "$shell" = "bash" ]; then echo "source \"$root/completions/rbenv.bash\"" fi + +echo 'rbenv rehash 2>/dev/null' From 1700206da89423c99824fa83f1df476bc7200e6a Mon Sep 17 00:00:00 2001 From: Guten Date: Tue, 16 Aug 2011 12:39:38 +0800 Subject: [PATCH 081/384] add zsh completion --- completions/_rbenv.zsh | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 completions/_rbenv.zsh diff --git a/completions/_rbenv.zsh b/completions/_rbenv.zsh new file mode 100644 index 00000000..da51e405 --- /dev/null +++ b/completions/_rbenv.zsh @@ -0,0 +1,20 @@ +#compdef _rbenv rbenv + +function _rbenv_commands() { + cmds_str="$(rbenv commands)" + cmds=("${(ps:\n:)cmds_str}") + _describe '_rbenv_commands' cmds +} + +_rbenv_versions() { + versions_str="$(rbenv versions --bare)" + versions=(system "${(ps:\n:)versions_str}") + _describe '_rbenv_versions' versions +} + +_rbenv() { + case "$words[2]" in + set-local | set-default | prefix ) _rbenv_versions ;; + * ) _rbenv_commands ;; + esac +} From 71b596554064aeccfd2bd33e31f2985c02710ca8 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Tue, 16 Aug 2011 00:01:03 -0500 Subject: [PATCH 082/384] Use read instead of egrep for reading version files. Closes #41. --- libexec/rbenv-version-name | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/libexec/rbenv-version-name b/libexec/rbenv-version-name index 9b2c7810..4faba8c7 100755 --- a/libexec/rbenv-version-name +++ b/libexec/rbenv-version-name @@ -1,8 +1,16 @@ #!/usr/bin/env bash set -e +# Read the first non-whitespace word from the specified file. read_version_file() { - egrep -m 1 '[^[:space:]]' "$1" + 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" From b45bce80ca053648647c00a5a53bc4a718ba2941 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Tue, 16 Aug 2011 00:13:12 -0500 Subject: [PATCH 083/384] Source the zsh autocompletion script in rbenv-init --- completions/{_rbenv.zsh => rbenv.zsh} | 0 libexec/rbenv-init | 8 +++++--- 2 files changed, 5 insertions(+), 3 deletions(-) rename completions/{_rbenv.zsh => rbenv.zsh} (100%) diff --git a/completions/_rbenv.zsh b/completions/rbenv.zsh similarity index 100% rename from completions/_rbenv.zsh rename to completions/rbenv.zsh diff --git a/libexec/rbenv-init b/libexec/rbenv-init index 4dc751dd..392edf40 100755 --- a/libexec/rbenv-init +++ b/libexec/rbenv-init @@ -55,8 +55,10 @@ mkdir -p "${HOME}/.rbenv/"{shims,versions} echo 'export PATH="${HOME}/.rbenv/shims:${PATH}"' -if [ "$shell" = "bash" ]; then - echo "source \"$root/completions/rbenv.bash\"" -fi +case "$shell" in +bash | zsh ) + echo "source \"$root/completions/rbenv.${shell}\"" + ;; +esac echo 'rbenv rehash 2>/dev/null' From 49ecbe147ffd7ebd4e03eb8fc8afd429532f3fce Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Tue, 16 Aug 2011 00:16:17 -0500 Subject: [PATCH 084/384] rbenv 0.1.2 --- libexec/rbenv | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libexec/rbenv b/libexec/rbenv index 5e6b20d4..87181d7b 100755 --- a/libexec/rbenv +++ b/libexec/rbenv @@ -21,7 +21,7 @@ export PATH="${libexec_path}:${PATH}" command="$1" case "$command" in "" | "-h" | "--help" ) - echo -e "rbenv 0.1.1\n$(rbenv-help)" >&2 + echo -e "rbenv 0.1.2\n$(rbenv-help)" >&2 ;; * ) command_path="$(command -v "rbenv-$command" || true)" From b7e19b4953f6f9c3377781342e517c78ebf27bce Mon Sep 17 00:00:00 2001 From: Paul Mucur Date: Tue, 16 Aug 2011 22:26:57 +0100 Subject: [PATCH 085/384] Solaris doesn't support readlink so use greadlink if available instead. Taken from Ryan Tomayko's "GNU is killing Solaris", c.f. http://tomayko.com/writings/gnu-is-killing-solaris --- libexec/rbenv | 6 +++++- libexec/rbenv-init | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/libexec/rbenv b/libexec/rbenv index 87181d7b..ec8adb2a 100755 --- a/libexec/rbenv +++ b/libexec/rbenv @@ -1,6 +1,10 @@ #!/usr/bin/env bash set -e +resolve_link() { + $(type -p greadlink readlink | head -1) $1 +} + abs_dirname() { local cwd="$(pwd)" local path="$1" @@ -8,7 +12,7 @@ abs_dirname() { while [ -n "$path" ]; do cd "${path%/*}" local name="${path##*/}" - path="$(readlink "$name" || true)" + path="$(resolve_link "$name" || true)" done pwd diff --git a/libexec/rbenv-init b/libexec/rbenv-init index 392edf40..3e670372 100755 --- a/libexec/rbenv-init +++ b/libexec/rbenv-init @@ -12,6 +12,10 @@ if [ -z "$shell" ]; then shell="$(basename "$SHELL")" fi +resolve_link() { + $(type -p greadlink readlink | head -1) $1 +} + abs_dirname() { local cwd="$(pwd)" local path="$1" @@ -19,7 +23,7 @@ abs_dirname() { while [ -n "$path" ]; do cd "${path%/*}" local name="${path##*/}" - path="$(readlink "$name" || true)" + path="$(resolve_link "$name" || true)" done pwd From 7bbfecd9afc84526b4bba51c11f9f5783d3a2caf Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Wed, 17 Aug 2011 17:35:04 -0500 Subject: [PATCH 086/384] Working on 0.2.0-pre now --- libexec/rbenv | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libexec/rbenv b/libexec/rbenv index ec8adb2a..32512766 100755 --- a/libexec/rbenv +++ b/libexec/rbenv @@ -25,7 +25,7 @@ export PATH="${libexec_path}:${PATH}" command="$1" case "$command" in "" | "-h" | "--help" ) - echo -e "rbenv 0.1.2\n$(rbenv-help)" >&2 + echo -e "rbenv 0.2.0-pre\n$(rbenv-help)" >&2 ;; * ) command_path="$(command -v "rbenv-$command" || true)" From 1411fa5a1624ca5eeb5582897373c58a715fe2d2 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Wed, 17 Aug 2011 17:35:23 -0500 Subject: [PATCH 087/384] Add experimental ruby-local-exec --- bin/ruby-local-exec | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100755 bin/ruby-local-exec diff --git a/bin/ruby-local-exec b/bin/ruby-local-exec new file mode 100755 index 00000000..af7d7e1a --- /dev/null +++ b/bin/ruby-local-exec @@ -0,0 +1,23 @@ +#!/usr/bin/env bash +# +# `ruby-local-exec` is a drop-in replacement for the standard Ruby +# shebang line: +# +# #!/usr/bin/env ruby-local-exec +# +# Use it for scripts inside a project with an `.rbenv-version` +# file. When you run the scripts, they'll use the project-specified +# Ruby version, regardless of what directory they're run from. Useful +# for e.g. running project tasks in cron scripts without needing to +# `cd` into the project first. + +set -e + +cwd="$(pwd)" +dirname="${1%/*}" + +cd "$dirname" +export RBENV_VERSION="$(rbenv version-name)" +cd "$cwd" + +exec ruby "$@" From 113e037646a7bded95a7aba4c6f5a56a866435e7 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Wed, 17 Aug 2011 17:53:37 -0500 Subject: [PATCH 088/384] Move the nullglob declaration further up so a '*' shim isn't created when no Ruby versions are present. Fixes #45. --- libexec/rbenv-rehash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libexec/rbenv-rehash b/libexec/rbenv-rehash index e1078fc8..13a8d6f4 100755 --- a/libexec/rbenv-rehash +++ b/libexec/rbenv-rehash @@ -59,10 +59,10 @@ cd "$SHIM_PATH" # Create the prototype shim, then make shims for all known binaries. create_prototype_shim +shopt -s nullglob make_shims ../versions/*/bin/* # Find and run any plugins that might want to make shims too. -shopt -s nullglob RBENV_REHASH_PLUGINS=(/etc/rbenv.d/rehash/*.bash ${HOME}/.rbenv/rbenv.d/rehash/*.bash) shopt -u nullglob From 20425c297f7ee2c5a0c101e200aa3fbcfa2b1f9e Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Thu, 18 Aug 2011 12:57:36 -0500 Subject: [PATCH 089/384] Avoid passive voice --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 78f593f9..c2af643a 100644 --- a/README.md +++ b/README.md @@ -134,8 +134,8 @@ overridden by a per-project `.rbenv-version` file, or by setting the The special version name `system` tells rbenv to use the system Ruby (detected by searching your `$PATH`). -When run without a version number the currently configured default -version is reported. +When run without a version number, `rbenv default` reports the +currently configured default version. ### 3.2 local @@ -146,8 +146,8 @@ overrides the default, and can be overridden itself by setting the $ rbenv local rbx-1.2.4 -When run without a version number the currently configured local -version is reported. +When run without a version number, `rbenv local` reports the currently +configured local version. ### 3.3 versions From 1d5c6531a27490bb9af332205a0528fcc502bb8d Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Thu, 18 Aug 2011 14:09:48 -0500 Subject: [PATCH 090/384] Improve deprecation notice --- libexec/rbenv-set-default | 8 ++++++-- libexec/rbenv-set-local | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/libexec/rbenv-set-default b/libexec/rbenv-set-default index cff1eb09..cf68d57e 100755 --- a/libexec/rbenv-set-default +++ b/libexec/rbenv-set-default @@ -1,5 +1,9 @@ #!/usr/bin/env bash set -e -echo "set-default has been renamed to default" >&2 -rbenv-default "$@" +{ echo "rbenv: warning: \`set-default' has been renamed to \`default'" + echo " and will be removed in v0.3.0" + echo +} >&2 + +exec rbenv-default "$@" diff --git a/libexec/rbenv-set-local b/libexec/rbenv-set-local index a93ec24e..28d5961f 100755 --- a/libexec/rbenv-set-local +++ b/libexec/rbenv-set-local @@ -1,5 +1,9 @@ #!/usr/bin/env bash set -e -echo "set-local has been renamed to local" >&2 -rbenv-local "$@" +{ echo "rbenv: warning: \`set-local' has been renamed to \`local'" + echo " and will be removed in v0.3.0" + echo +} >&2 + +exec rbenv-local "$@" From 506bc3634f02f57af18a4fadd5a7ee6b10a9970c Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Thu, 18 Aug 2011 14:11:40 -0500 Subject: [PATCH 091/384] Extract rbenv-version-file{,-read,-write} --- libexec/rbenv-default | 19 +++++++------------ libexec/rbenv-local | 23 ++++++++++------------- libexec/rbenv-version-file | 15 +++++++++++++++ libexec/rbenv-version-file-read | 18 ++++++++++++++++++ libexec/rbenv-version-file-write | 15 +++++++++++++++ libexec/rbenv-version-name | 22 ++-------------------- libexec/rbenv-version-origin | 28 +++------------------------- 7 files changed, 70 insertions(+), 70 deletions(-) create mode 100755 libexec/rbenv-version-file create mode 100755 libexec/rbenv-version-file-read create mode 100755 libexec/rbenv-version-file-write diff --git a/libexec/rbenv-default b/libexec/rbenv-default index 56f1276e..d176e0cd 100755 --- a/libexec/rbenv-default +++ b/libexec/rbenv-default @@ -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 " - 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 diff --git a/libexec/rbenv-local b/libexec/rbenv-local index cfc72067..010e93b3 100755 --- a/libexec/rbenv-local +++ b/libexec/rbenv-local @@ -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 " - fi +RBENV_VERSION_FILE=".rbenv-version" + +if [ -n "$RBENV_VERSION" ]; then + rbenv-version-file-write "$RBENV_VERSION_FILE" "$RBENV_VERSION" else - # Make sure the specified version is installed - rbenv-prefix "$RBENV_VERSION" >/dev/null - - echo "$RBENV_VERSION" > "$VERSION_FILE" + rbenv-version-file-read "$RBENV_VERSION_FILE" || + { echo "rbenv: no local version configured for this directory" + exit 1 + } >&2 fi - diff --git a/libexec/rbenv-version-file b/libexec/rbenv-version-file new file mode 100755 index 00000000..bb4da5b4 --- /dev/null +++ b/libexec/rbenv-version-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" diff --git a/libexec/rbenv-version-file-read b/libexec/rbenv-version-file-read new file mode 100755 index 00000000..5bd293de --- /dev/null +++ b/libexec/rbenv-version-file-read @@ -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 diff --git a/libexec/rbenv-version-file-write b/libexec/rbenv-version-file-write new file mode 100755 index 00000000..b42764b3 --- /dev/null +++ b/libexec/rbenv-version-file-write @@ -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" diff --git a/libexec/rbenv-version-name b/libexec/rbenv-version-name index 4faba8c7..a9c0d1ab 100755 --- a/libexec/rbenv-version-name +++ b/libexec/rbenv-version-name @@ -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 diff --git a/libexec/rbenv-version-origin b/libexec/rbenv-version-origin index e4e6d552..31653d49 100755 --- a/libexec/rbenv-version-origin +++ b/libexec/rbenv-version-origin @@ -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 From 53d55eb08ce95d0cf99e7742ab0acc7a11924164 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Thu, 18 Aug 2011 14:13:20 -0500 Subject: [PATCH 092/384] Update completions --- completions/rbenv.bash | 2 +- completions/rbenv.zsh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/completions/rbenv.bash b/completions/rbenv.bash index 3ad2aa21..493a6a7d 100644 --- a/completions/rbenv.bash +++ b/completions/rbenv.bash @@ -17,7 +17,7 @@ _rbenv() { local prev="${COMP_WORDS[COMP_CWORD-1]}" case "$prev" in - default | local | prefix ) + set-* | default | local | prefix ) _rbenv_versions ;; * ) diff --git a/completions/rbenv.zsh b/completions/rbenv.zsh index da51e405..efaebe4e 100644 --- a/completions/rbenv.zsh +++ b/completions/rbenv.zsh @@ -14,7 +14,7 @@ _rbenv_versions() { _rbenv() { case "$words[2]" in - set-local | set-default | prefix ) _rbenv_versions ;; + set-* | default | local | prefix ) _rbenv_versions ;; * ) _rbenv_commands ;; esac } From 5be66da9f4053137a320058495031d0af6db29b4 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Thu, 18 Aug 2011 14:32:33 -0500 Subject: [PATCH 093/384] Rename rbenv-default to rbenv-global --- README.md | 20 ++++++++++---------- completions/rbenv.bash | 2 +- completions/rbenv.zsh | 2 +- libexec/rbenv-default | 11 ----------- libexec/rbenv-global | 13 +++++++++++++ libexec/rbenv-help | 14 +++++++------- libexec/rbenv-set-default | 4 ++-- libexec/rbenv-version-file | 13 ++++++++++--- libexec/rbenv-version-name | 2 -- 9 files changed, 44 insertions(+), 37 deletions(-) delete mode 100755 libexec/rbenv-default create mode 100755 libexec/rbenv-global diff --git a/README.md b/README.md index c2af643a..10942cfa 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ tools that do one thing well. ### rbenv _does…_ -* Let you **change the default Ruby version** on a per-user basis. +* Let you **change the global Ruby version** on a per-user basis. * Provide support for **per-project Ruby versions**. * Allow you to **override the Ruby version** with an environment variable. @@ -42,7 +42,7 @@ tools that do one thing well. * [1 How It Works](#section_1) * [2 Installation](#section_2) * [3 Usage](#section_3) - * [3.1 default](#section_3.1) + * [3.1 global](#section_3.1) * [3.2 local](#section_3.2) * [3.3 versions](#section_3.3) * [3.4 version](#section_3.4) @@ -122,26 +122,26 @@ when installing a gem that provides a binary). Like `git`, the `rbenv` command delegates to subcommands based on its first argument. The most common subcommands are: -### 3.1 default +### 3.1 global -Sets the default version of Ruby to be used in all shells by writing -the version name to the `~/.rbenv/default` file. This version can be +Sets the global version of Ruby to be used in all shells by writing +the version name to the `~/.rbenv/global` file. This version can be overridden by a per-project `.rbenv-version` file, or by setting the `RBENV_VERSION` environment variable. - $ rbenv default 1.9.2-p290 + $ rbenv global 1.9.2-p290 The special version name `system` tells rbenv to use the system Ruby (detected by searching your `$PATH`). -When run without a version number, `rbenv default` reports the -currently configured default version. +When run without a version number, `rbenv global` reports the +currently configured global version. ### 3.2 local Sets a local per-project Ruby version by writing the version name to an `.rbenv-version` file in the current directory. This version -overrides the default, and can be overridden itself by setting the +overrides the global, and can be overridden itself by setting the `RBENV_VERSION` environment variable. $ rbenv local rbx-1.2.4 @@ -157,7 +157,7 @@ the currently active version. $ rbenv versions 1.8.7-p352 1.9.2-p290 - * 1.9.3-preview1 (set by /Users/sam/.rbenv/default) + * 1.9.3-preview1 (set by /Users/sam/.rbenv/global) jruby-1.6.3 rbx-1.2.4 ree-1.8.7-2011.03 diff --git a/completions/rbenv.bash b/completions/rbenv.bash index 493a6a7d..8d3bbd7f 100644 --- a/completions/rbenv.bash +++ b/completions/rbenv.bash @@ -17,7 +17,7 @@ _rbenv() { local prev="${COMP_WORDS[COMP_CWORD-1]}" case "$prev" in - set-* | default | local | prefix ) + set-* | global | local | prefix ) _rbenv_versions ;; * ) diff --git a/completions/rbenv.zsh b/completions/rbenv.zsh index efaebe4e..105239c2 100644 --- a/completions/rbenv.zsh +++ b/completions/rbenv.zsh @@ -14,7 +14,7 @@ _rbenv_versions() { _rbenv() { case "$words[2]" in - set-* | default | local | prefix ) _rbenv_versions ;; + set-* | global | local | prefix ) _rbenv_versions ;; * ) _rbenv_commands ;; esac } diff --git a/libexec/rbenv-default b/libexec/rbenv-default deleted file mode 100755 index d176e0cd..00000000 --- a/libexec/rbenv-default +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env bash -set -e - -RBENV_VERSION="$1" -RBENV_VERSION_FILE="${HOME}/.rbenv/default" - -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 diff --git a/libexec/rbenv-global b/libexec/rbenv-global new file mode 100755 index 00000000..42cedda5 --- /dev/null +++ b/libexec/rbenv-global @@ -0,0 +1,13 @@ +#!/usr/bin/env bash +set -e + +RBENV_VERSION="$1" +RBENV_VERSION_FILE="${HOME}/.rbenv/global" + +if [ -n "$RBENV_VERSION" ]; then + rbenv-version-file-write "$RBENV_VERSION_FILE" "$RBENV_VERSION" +else + rbenv-version-file-read "$RBENV_VERSION_FILE" || + rbenv-version-file-read "${HOME}/.rbenv/default" || + echo system +fi diff --git a/libexec/rbenv-help b/libexec/rbenv-help index 4acb7dc6..36fcf26b 100755 --- a/libexec/rbenv-help +++ b/libexec/rbenv-help @@ -22,7 +22,7 @@ case "$1" in Some useful rbenv commands are: commands List all commands rehash Rehash rbenv shims (run this after installing binaries) - default Set or show the default Ruby version + global Set or show the global Ruby version local Set or show the local directory-specific Ruby version version Show the current Ruby version versions List all Ruby versions known by rbenv @@ -30,11 +30,11 @@ Some useful rbenv commands are: See 'rbenv help ' for more information on a specific command. For more information, see: https://github.com/sstephenson/rbenv#readme" ;; -default) echo "usage: rbenv default +global) echo "usage: rbenv global -Sets the default Ruby version. You can override the default at any time -by setting a directory-specific version with \`rbenv local' or by -setting the RBENV_VERSION environment variable. +Sets the global Ruby version. You can override the global version at +any time by setting a directory-specific version with \`rbenv local' +or by setting the RBENV_VERSION environment variable. $(print_set_version)" ;; @@ -45,8 +45,8 @@ name to a file named '.rbenv-version'. When you run a Ruby command, rbenv will look for an '.rbenv-version' file in the current directory and each parent directory. If no such -file is found in the tree, rbenv will use the default Ruby version -specified with \`rbenv default', or the version specified in the +file is found in the tree, rbenv will use the global Ruby version +specified with \`rbenv global', or the version specified in the RBENV_VERSION environment variable. $(print_set_version)" diff --git a/libexec/rbenv-set-default b/libexec/rbenv-set-default index cf68d57e..a1fec3db 100755 --- a/libexec/rbenv-set-default +++ b/libexec/rbenv-set-default @@ -1,9 +1,9 @@ #!/usr/bin/env bash set -e -{ echo "rbenv: warning: \`set-default' has been renamed to \`default'" +{ echo "rbenv: warning: \`set-default' has been renamed to \`global'" echo " and will be removed in v0.3.0" echo } >&2 -exec rbenv-default "$@" +exec rbenv-global "$@" diff --git a/libexec/rbenv-version-file b/libexec/rbenv-version-file index bb4da5b4..a0c87201 100755 --- a/libexec/rbenv-version-file +++ b/libexec/rbenv-version-file @@ -1,8 +1,6 @@ #!/usr/bin/env bash set -e -DEFAULT_PATH="${HOME}/.rbenv/default" - root="$(pwd)" while [ -n "$root" ]; do if [ -e "${root}/.rbenv-version" ]; then @@ -12,4 +10,13 @@ while [ -n "$root" ]; do root="${root%/*}" done -echo "$DEFAULT_PATH" +GLOBAL_PATH="${HOME}/.rbenv/global" +DEFAULT_PATH="${HOME}/.rbenv/default" + +if [ -e "$GLOBAL_PATH" ]; then + echo "$GLOBAL_PATH" +elif [ -e "$DEFAULT_PATH" ]; then + echo "$DEFAULT_PATH" +else + echo "$GLOBAL_PATH" +fi diff --git a/libexec/rbenv-version-name b/libexec/rbenv-version-name index a9c0d1ab..4782de75 100755 --- a/libexec/rbenv-version-name +++ b/libexec/rbenv-version-name @@ -1,8 +1,6 @@ #!/usr/bin/env bash set -e -DEFAULT_PATH="${HOME}/.rbenv/default" - if [ -z "$RBENV_VERSION" ]; then RBENV_VERSION_FILE="$(rbenv-version-file)" RBENV_VERSION="$(rbenv-version-file-read "$RBENV_VERSION_FILE" || true)" From af36d449bf500a066ba800b4deaa1d349308e85a Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Thu, 18 Aug 2011 15:28:35 -0500 Subject: [PATCH 094/384] Exit after printing usage in rbenv-version-file-write --- libexec/rbenv-version-file-write | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libexec/rbenv-version-file-write b/libexec/rbenv-version-file-write index b42764b3..0435cf14 100755 --- a/libexec/rbenv-version-file-write +++ b/libexec/rbenv-version-file-write @@ -5,7 +5,8 @@ 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 + echo "usage: rbenv write-version-file FILENAME VERSION" >&2 + exit 1 fi # Make sure the specified version is installed. From aade3ad78157c888d37e37a8a0d83433ef8b78d8 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Thu, 18 Aug 2011 15:53:48 -0500 Subject: [PATCH 095/384] Sync mdtoc source --- doc/README.mdtoc | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/doc/README.mdtoc b/doc/README.mdtoc index b49618ef..1da7969b 100644 --- a/doc/README.mdtoc +++ b/doc/README.mdtoc @@ -8,7 +8,7 @@ tools that do one thing well. ### rbenv _does…_ -* Let you **change the default Ruby version** on a per-user basis. +* Let you **change the global Ruby version** on a per-user basis. * Provide support for **per-project Ruby versions**. * Allow you to **override the Ruby version** with an environment variable. @@ -111,26 +111,32 @@ when installing a gem that provides a binary). Like `git`, the `rbenv` command delegates to subcommands based on its first argument. The most common subcommands are: -### set-default ### +### global ### -Sets the default version of Ruby to be used in all shells by writing -the version name to the `~/.rbenv/default` file. This version can be +Sets the global version of Ruby to be used in all shells by writing +the version name to the `~/.rbenv/global` file. This version can be overridden by a per-project `.rbenv-version` file, or by setting the `RBENV_VERSION` environment variable. - $ rbenv set-default 1.9.2-p290 + $ rbenv global 1.9.2-p290 The special version name `system` tells rbenv to use the system Ruby (detected by searching your `$PATH`). -### set-local ### +When run without a version number, `rbenv global` reports the +currently configured global version. + +### local ### Sets a local per-project Ruby version by writing the version name to an `.rbenv-version` file in the current directory. This version -overrides the default, and can be overridden itself by setting the +overrides the global, and can be overridden itself by setting the `RBENV_VERSION` environment variable. - $ rbenv set-local rbx-1.2.4 + $ rbenv local rbx-1.2.4 + +When run without a version number, `rbenv local` reports the currently +configured local version. ### versions ### @@ -140,7 +146,7 @@ the currently active version. $ rbenv versions 1.8.7-p352 1.9.2-p290 - * 1.9.3-preview1 (set by /Users/sam/.rbenv/default) + * 1.9.3-preview1 (set by /Users/sam/.rbenv/global) jruby-1.6.3 rbx-1.2.4 ree-1.8.7-2011.03 From a6727bf9edc29690bd99e1732ae8af113519a228 Mon Sep 17 00:00:00 2001 From: Michael Hanson Date: Mon, 22 Aug 2011 07:05:15 -0700 Subject: [PATCH 096/384] Ignore /global instead of /default --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 3c6bb8d9..5be802e6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ /versions /shims -/default +/global From 5a4bee6eb51a7ddc99d22d76dab88b125fe2c1ea Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 23 Aug 2011 11:34:03 -0500 Subject: [PATCH 097/384] List sh commands separately --- libexec/rbenv-commands | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/libexec/rbenv-commands b/libexec/rbenv-commands index 43846ce4..08c5a944 100755 --- a/libexec/rbenv-commands +++ b/libexec/rbenv-commands @@ -1,11 +1,25 @@ #!/usr/bin/env bash set -e +if [ "$1" = "--sh" ]; then + sh=1 + shift +fi + shopt -s nullglob { for path in ${PATH//:/$'\n'}; do for command in "${path}/rbenv-"*; do - echo "${command##*rbenv-}" + command="${command##*rbenv-}" + if [ -n "$sh" ]; then + if [ ${command:0:3} = "sh-" ]; then + echo ${command##sh-} + fi + else + if [ ${command:0:3} != "sh-" ]; then + echo $command + fi + fi done done } | sort | uniq From f9225d9cb445cfb24daac4258e1328c0262e3184 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 23 Aug 2011 11:34:42 -0500 Subject: [PATCH 098/384] Define lightweight rbenv shell function to dispatch commands --- libexec/rbenv-init | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/libexec/rbenv-init b/libexec/rbenv-init index 3e670372..29daa10c 100755 --- a/libexec/rbenv-init +++ b/libexec/rbenv-init @@ -66,3 +66,18 @@ bash | zsh ) esac echo 'rbenv rehash 2>/dev/null' + +commands=(`rbenv commands --sh`) +IFS="|" +cat < Date: Tue, 23 Aug 2011 11:35:06 -0500 Subject: [PATCH 099/384] use command --- libexec/rbenv-sh-use | 2 ++ 1 file changed, 2 insertions(+) create mode 100755 libexec/rbenv-sh-use diff --git a/libexec/rbenv-sh-use b/libexec/rbenv-sh-use new file mode 100755 index 00000000..187ed6ac --- /dev/null +++ b/libexec/rbenv-sh-use @@ -0,0 +1,2 @@ +#!/bin/sh +echo "export RBENV_VERSION=$1" From 5130f0464a41732aa7fa4f799f5a9587a3842cb6 Mon Sep 17 00:00:00 2001 From: Alexander Rinass Date: Thu, 25 Aug 2011 09:24:44 +0200 Subject: [PATCH 100/384] Support install locations other than $HOME/.rbenv. Define RBENV_HOME env variable in libexec/rbenv and let all script delegates use this variable to determine rbenv's install location. --- libexec/rbenv | 3 +++ libexec/rbenv-global | 4 ++-- libexec/rbenv-init | 4 ++-- libexec/rbenv-prefix | 2 +- libexec/rbenv-rehash | 4 ++-- libexec/rbenv-version-file | 4 ++-- libexec/rbenv-version-name | 2 +- libexec/rbenv-versions | 2 +- libexec/rbenv-which | 6 +++--- 9 files changed, 17 insertions(+), 14 deletions(-) diff --git a/libexec/rbenv b/libexec/rbenv index 32512766..890ca5e1 100755 --- a/libexec/rbenv +++ b/libexec/rbenv @@ -19,6 +19,9 @@ abs_dirname() { cd "$cwd" } +rbenv_install_location=$(abs_dirname "$(dirname $0)") +export RBENV_HOME="${rbenv_install_location}" + libexec_path="$(abs_dirname "$0")" export PATH="${libexec_path}:${PATH}" diff --git a/libexec/rbenv-global b/libexec/rbenv-global index 42cedda5..72ad5c17 100755 --- a/libexec/rbenv-global +++ b/libexec/rbenv-global @@ -2,12 +2,12 @@ set -e RBENV_VERSION="$1" -RBENV_VERSION_FILE="${HOME}/.rbenv/global" +RBENV_VERSION_FILE="${RBENV_HOME}/global" if [ -n "$RBENV_VERSION" ]; then rbenv-version-file-write "$RBENV_VERSION_FILE" "$RBENV_VERSION" else rbenv-version-file-read "$RBENV_VERSION_FILE" || - rbenv-version-file-read "${HOME}/.rbenv/default" || + rbenv-version-file-read "${RBENV_HOME}/default" || echo system fi diff --git a/libexec/rbenv-init b/libexec/rbenv-init index 3e670372..3001ff6a 100755 --- a/libexec/rbenv-init +++ b/libexec/rbenv-init @@ -55,9 +55,9 @@ if [ -z "$print" ]; then exit 1 fi -mkdir -p "${HOME}/.rbenv/"{shims,versions} +mkdir -p "${RBENV_HOME}/"{shims,versions} -echo 'export PATH="${HOME}/.rbenv/shims:${PATH}"' +echo 'export PATH="'${RBENV_HOME}'/shims:${PATH}"' case "$shell" in bash | zsh ) diff --git a/libexec/rbenv-prefix b/libexec/rbenv-prefix index 3f22e7ee..677814b3 100755 --- a/libexec/rbenv-prefix +++ b/libexec/rbenv-prefix @@ -13,7 +13,7 @@ if [ "$RBENV_VERSION" = "system" ]; then exit fi -RBENV_PREFIX_PATH="${HOME}/.rbenv/versions/${RBENV_VERSION}" +RBENV_PREFIX_PATH="${RBENV_HOME}/versions/${RBENV_VERSION}" if [ ! -d "$RBENV_PREFIX_PATH" ]; then echo "rbenv: version \`${RBENV_VERSION}' not installed" >&2 exit 1 diff --git a/libexec/rbenv-rehash b/libexec/rbenv-rehash index 13a8d6f4..998eab40 100755 --- a/libexec/rbenv-rehash +++ b/libexec/rbenv-rehash @@ -1,7 +1,7 @@ #!/usr/bin/env bash set -e -SHIM_PATH="${HOME}/.rbenv/shims" +SHIM_PATH="${RBENV_HOME}/shims" PROTOTYPE_SHIM_PATH="${SHIM_PATH}/.rbenv-shim" # Create the shims directory if it doesn't already exist. @@ -63,7 +63,7 @@ shopt -s nullglob make_shims ../versions/*/bin/* # Find and run any plugins that might want to make shims too. -RBENV_REHASH_PLUGINS=(/etc/rbenv.d/rehash/*.bash ${HOME}/.rbenv/rbenv.d/rehash/*.bash) +RBENV_REHASH_PLUGINS=(/etc/rbenv.d/rehash/*.bash ${RBENV_HOME}/rbenv.d/rehash/*.bash) shopt -u nullglob for script in ${RBENV_REHASH_PLUGINS[@]}; do diff --git a/libexec/rbenv-version-file b/libexec/rbenv-version-file index a0c87201..6d01e63e 100755 --- a/libexec/rbenv-version-file +++ b/libexec/rbenv-version-file @@ -10,8 +10,8 @@ while [ -n "$root" ]; do root="${root%/*}" done -GLOBAL_PATH="${HOME}/.rbenv/global" -DEFAULT_PATH="${HOME}/.rbenv/default" +GLOBAL_PATH="${RBENV_HOME}/global" +DEFAULT_PATH="${RBENV_HOME}/default" if [ -e "$GLOBAL_PATH" ]; then echo "$GLOBAL_PATH" diff --git a/libexec/rbenv-version-name b/libexec/rbenv-version-name index 4782de75..1861505a 100755 --- a/libexec/rbenv-version-name +++ b/libexec/rbenv-version-name @@ -11,7 +11,7 @@ if [ "$RBENV_VERSION" = "system" ]; then exit fi -RBENV_VERSION_PATH="${HOME}/.rbenv/versions/${RBENV_VERSION}" +RBENV_VERSION_PATH="${RBENV_HOME}/versions/${RBENV_VERSION}" if [ -d "$RBENV_VERSION_PATH" ]; then echo "$RBENV_VERSION" diff --git a/libexec/rbenv-versions b/libexec/rbenv-versions index a67a8ffa..4abb9db4 100755 --- a/libexec/rbenv-versions +++ b/libexec/rbenv-versions @@ -13,7 +13,7 @@ else print_version="$(rbenv-version)" fi -for path in "${HOME}/.rbenv/versions/"*; do +for path in "${RBENV_HOME}/versions/"*; do if [ -d "$path" ]; then version="${path##*/}" diff --git a/libexec/rbenv-which b/libexec/rbenv-which index 0f8fd2c5..e816ef8d 100755 --- a/libexec/rbenv-which +++ b/libexec/rbenv-which @@ -30,14 +30,14 @@ RBENV_VERSION="$(rbenv-version-name)" RBENV_COMMAND="$1" if [ "$RBENV_VERSION" = "system" ]; then - PATH="$(remove_from_path "${HOME}/.rbenv/shims")" + PATH="$(remove_from_path "${RBENV_HOME}/shims")" RBENV_COMMAND_PATH="$(command -v "$RBENV_COMMAND")" else - RBENV_COMMAND_PATH="${HOME}/.rbenv/versions/${RBENV_VERSION}/bin/${RBENV_COMMAND}" + RBENV_COMMAND_PATH="${RBENV_HOME}/versions/${RBENV_VERSION}/bin/${RBENV_COMMAND}" fi shopt -s nullglob -RBENV_WHICH_PLUGINS=(/etc/rbenv.d/which/*.bash ${HOME}/.rbenv/rbenv.d/which/*.bash) +RBENV_WHICH_PLUGINS=(/etc/rbenv.d/which/*.bash ${RBENV_HOME}/rbenv.d/which/*.bash) shopt -u nullglob for script in ${RBENV_WHICH_PLUGINS[@]}; do From c928ba7a210039e288abd548348457fc911ad92d Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 6 Sep 2011 22:07:05 -0500 Subject: [PATCH 101/384] Include sh commands in default listing --- libexec/rbenv-commands | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/libexec/rbenv-commands b/libexec/rbenv-commands index 08c5a944..4b593b4b 100755 --- a/libexec/rbenv-commands +++ b/libexec/rbenv-commands @@ -6,6 +6,11 @@ if [ "$1" = "--sh" ]; then shift fi +if [ "$1" = "--no-sh" ]; then + nosh=1 + shift +fi + shopt -s nullglob { for path in ${PATH//:/$'\n'}; do @@ -15,12 +20,13 @@ shopt -s nullglob if [ ${command:0:3} = "sh-" ]; then echo ${command##sh-} fi - else + elif [ -n "$nosh" ]; then if [ ${command:0:3} != "sh-" ]; then - echo $command + echo ${command##sh-} fi + else + echo ${command##sh-} fi done done } | sort | uniq - From d14529461bbb8d7464b79dc20b2a3873b4992fab Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 6 Sep 2011 22:07:21 -0500 Subject: [PATCH 102/384] Version autocomplete `use` command --- completions/rbenv.bash | 2 +- completions/rbenv.zsh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/completions/rbenv.bash b/completions/rbenv.bash index 8d3bbd7f..769e9aa2 100644 --- a/completions/rbenv.bash +++ b/completions/rbenv.bash @@ -17,7 +17,7 @@ _rbenv() { local prev="${COMP_WORDS[COMP_CWORD-1]}" case "$prev" in - set-* | global | local | prefix ) + set-* | global | local | prefix | use ) _rbenv_versions ;; * ) diff --git a/completions/rbenv.zsh b/completions/rbenv.zsh index 105239c2..834b390e 100644 --- a/completions/rbenv.zsh +++ b/completions/rbenv.zsh @@ -14,7 +14,7 @@ _rbenv_versions() { _rbenv() { case "$words[2]" in - set-* | global | local | prefix ) _rbenv_versions ;; + set-* | global | local | prefix | use ) _rbenv_versions ;; * ) _rbenv_commands ;; esac } From 042794b6517bd19e8b03abeacb3f373ec696f2fa Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Wed, 7 Sep 2011 10:26:11 -0500 Subject: [PATCH 103/384] use -> shell --- completions/rbenv.bash | 2 +- completions/rbenv.zsh | 2 +- libexec/{rbenv-sh-use => rbenv-sh-shell} | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename libexec/{rbenv-sh-use => rbenv-sh-shell} (100%) diff --git a/completions/rbenv.bash b/completions/rbenv.bash index 769e9aa2..d548a859 100644 --- a/completions/rbenv.bash +++ b/completions/rbenv.bash @@ -17,7 +17,7 @@ _rbenv() { local prev="${COMP_WORDS[COMP_CWORD-1]}" case "$prev" in - set-* | global | local | prefix | use ) + set-* | global | local | shell | prefix ) _rbenv_versions ;; * ) diff --git a/completions/rbenv.zsh b/completions/rbenv.zsh index 834b390e..39c1c6f3 100644 --- a/completions/rbenv.zsh +++ b/completions/rbenv.zsh @@ -14,7 +14,7 @@ _rbenv_versions() { _rbenv() { case "$words[2]" in - set-* | global | local | prefix | use ) _rbenv_versions ;; + set-* | global | local | shell | prefix ) _rbenv_versions ;; * ) _rbenv_commands ;; esac } diff --git a/libexec/rbenv-sh-use b/libexec/rbenv-sh-shell similarity index 100% rename from libexec/rbenv-sh-use rename to libexec/rbenv-sh-shell From 837bfc5aa9d9e5b701c23c0d89229397f7ea8bac Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Wed, 7 Sep 2011 14:46:29 -0500 Subject: [PATCH 104/384] Fix rbenv-version-file-read for version files without trailing newlines --- libexec/rbenv-version-file-read | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libexec/rbenv-version-file-read b/libexec/rbenv-version-file-read index 5bd293de..a7b02c0d 100755 --- a/libexec/rbenv-version-file-read +++ b/libexec/rbenv-version-file-read @@ -12,7 +12,7 @@ if [ -e "$VERSION_FILE" ]; then echo "$version" break fi - done < "$VERSION_FILE" + done < <( cat "$VERSION_FILE" && echo ) else exit 1 fi From 39497042bcd7c90acd32a9f38b6fbe8eb8e9553c Mon Sep 17 00:00:00 2001 From: Timothy King Date: Fri, 9 Sep 2011 08:18:14 -0400 Subject: [PATCH 105/384] Adds error handling to rbenv-sh-shell --- libexec/rbenv-sh-shell | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/libexec/rbenv-sh-shell b/libexec/rbenv-sh-shell index 187ed6ac..f4e11e8e 100755 --- a/libexec/rbenv-sh-shell +++ b/libexec/rbenv-sh-shell @@ -1,2 +1,16 @@ #!/bin/sh -echo "export RBENV_VERSION=$1" + +if [ -z "$1" ]; then + echo "Please specify one of the following Ruby versions to use:" >&2 + echo "" >&2 + echo "$(rbenv-versions)" >&2 + exit 1 +fi + +version=$1 + +if [ -d "$HOME/.rbenv/versions/$version" ]; then + echo "export RBENV_VERSION=$version" +else + echo "rbenv: version \`$version' is not installed" >&2 +fi From 555472210b6c0e1be0d49830bef8f626f04f78b6 Mon Sep 17 00:00:00 2001 From: Timothy King Date: Fri, 9 Sep 2011 08:22:03 -0400 Subject: [PATCH 106/384] Adds sh-shell subcommand to unset RBENV_VERSION --- libexec/rbenv-sh-shell | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/libexec/rbenv-sh-shell b/libexec/rbenv-sh-shell index f4e11e8e..a61f33f3 100755 --- a/libexec/rbenv-sh-shell +++ b/libexec/rbenv-sh-shell @@ -12,5 +12,12 @@ version=$1 if [ -d "$HOME/.rbenv/versions/$version" ]; then echo "export RBENV_VERSION=$version" else - echo "rbenv: version \`$version' is not installed" >&2 + case $version in + default|reset) + echo "unset RBENV_VERSION" + ;; + *) + echo "rbenv: version \`$version' is not installed" >&2 + exit 1 + esac fi From 783a5700c4dcb8ffcbc17a04af4664b5b3fc5776 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Fri, 9 Sep 2011 10:45:23 -0500 Subject: [PATCH 107/384] reset isn't standard --- libexec/rbenv-sh-shell | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libexec/rbenv-sh-shell b/libexec/rbenv-sh-shell index a61f33f3..10a5bf7a 100755 --- a/libexec/rbenv-sh-shell +++ b/libexec/rbenv-sh-shell @@ -13,7 +13,7 @@ if [ -d "$HOME/.rbenv/versions/$version" ]; then echo "export RBENV_VERSION=$version" else case $version in - default|reset) + default) echo "unset RBENV_VERSION" ;; *) From db2a94d4bc95647cf7d57e394d9c1324f8e2c755 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Fri, 9 Sep 2011 15:52:31 -0500 Subject: [PATCH 108/384] `rbenv-version-name` returns `system` for empty version files. Closes #62, #65, #77. --- libexec/rbenv-version-file-read | 4 ++-- libexec/rbenv-version-name | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libexec/rbenv-version-file-read b/libexec/rbenv-version-file-read index a7b02c0d..74f7acb1 100755 --- a/libexec/rbenv-version-file-read +++ b/libexec/rbenv-version-file-read @@ -13,6 +13,6 @@ if [ -e "$VERSION_FILE" ]; then break fi done < <( cat "$VERSION_FILE" && echo ) -else - exit 1 fi + +exit 1 diff --git a/libexec/rbenv-version-name b/libexec/rbenv-version-name index 4782de75..195d1349 100755 --- a/libexec/rbenv-version-name +++ b/libexec/rbenv-version-name @@ -6,8 +6,8 @@ if [ -z "$RBENV_VERSION" ]; then RBENV_VERSION="$(rbenv-version-file-read "$RBENV_VERSION_FILE" || true)" fi -if [ "$RBENV_VERSION" = "system" ]; then - echo "$RBENV_VERSION" +if [ -z "$RBENV_VERSION" ] || [ "$RBENV_VERSION" = "system" ]; then + echo "system" exit fi From b81b64453bb66dc54b15e1c1b90430ead25f1f13 Mon Sep 17 00:00:00 2001 From: Eric Lindvall Date: Fri, 9 Sep 2011 15:00:59 -0700 Subject: [PATCH 109/384] Deal with an empty result from expand_path --- libexec/rbenv-which | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libexec/rbenv-which b/libexec/rbenv-which index 0f8fd2c5..89cba18c 100755 --- a/libexec/rbenv-which +++ b/libexec/rbenv-which @@ -16,6 +16,11 @@ remove_from_path() { local path_to_remove="$(expand_path "$1")" local result="" + if [ -z "$path_to_remove" ]; then + echo "${PATH}" + return + fi + for path in ${PATH//:/$'\n'}; do path="$(expand_path "$path" || true)" if [ -n "$path" ] && [ "$path" != "$path_to_remove" ]; then From 76929320c82a999e6e2cf64691b704058cbd9dbc Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Sat, 10 Sep 2011 19:45:22 -0500 Subject: [PATCH 110/384] Make rbenv-sh-shell consistent with rbenv-local --- libexec/rbenv-sh-shell | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/libexec/rbenv-sh-shell b/libexec/rbenv-sh-shell index 10a5bf7a..d2c80904 100755 --- a/libexec/rbenv-sh-shell +++ b/libexec/rbenv-sh-shell @@ -1,23 +1,24 @@ -#!/bin/sh +#!/usr/bin/env bash +set -e -if [ -z "$1" ]; then - echo "Please specify one of the following Ruby versions to use:" >&2 - echo "" >&2 - echo "$(rbenv-versions)" >&2 +version="$1" + +if [ -z "$version" ]; then + if [ -z "$RBENV_VERSION" ]; then + echo "rbenv: no shell-specific version configured" >&2 + exit 1 + else + echo "echo \"\$RBENV_VERSION\"" + exit + fi +fi + +if [ "$version" = "--unset" ]; then + echo "unset RBENV_VERSION" exit 1 fi -version=$1 +# Make sure the specified version is installed. +rbenv-prefix "$version" >/dev/null -if [ -d "$HOME/.rbenv/versions/$version" ]; then - echo "export RBENV_VERSION=$version" -else - case $version in - default) - echo "unset RBENV_VERSION" - ;; - *) - echo "rbenv: version \`$version' is not installed" >&2 - exit 1 - esac -fi +echo "export RBENV_VERSION=\"${version}\"" From 1ba2ce0cb69510856201f9f7e379d48838aed994 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Sat, 10 Sep 2011 19:45:36 -0500 Subject: [PATCH 111/384] Fix quoting in rbenv function --- libexec/rbenv-init | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libexec/rbenv-init b/libexec/rbenv-init index 29daa10c..df2bf00c 100755 --- a/libexec/rbenv-init +++ b/libexec/rbenv-init @@ -71,13 +71,13 @@ commands=(`rbenv commands --sh`) IFS="|" cat < Date: Sat, 10 Sep 2011 19:50:12 -0500 Subject: [PATCH 112/384] Only shift if an argument is passed. Fixes #78. --- libexec/rbenv-init | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/libexec/rbenv-init b/libexec/rbenv-init index df2bf00c..cc1196c4 100755 --- a/libexec/rbenv-init +++ b/libexec/rbenv-init @@ -70,14 +70,17 @@ echo 'rbenv rehash 2>/dev/null' commands=(`rbenv commands --sh`) IFS="|" cat < Date: Sat, 10 Sep 2011 20:09:27 -0500 Subject: [PATCH 113/384] Fix zsh autocompletion. Closes #47. --- completions/rbenv.zsh | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/completions/rbenv.zsh b/completions/rbenv.zsh index 39c1c6f3..e5abc345 100644 --- a/completions/rbenv.zsh +++ b/completions/rbenv.zsh @@ -1,18 +1,17 @@ -#compdef _rbenv rbenv +compctl -K _rbenv rbenv function _rbenv_commands() { cmds_str="$(rbenv commands)" - cmds=("${(ps:\n:)cmds_str}") - _describe '_rbenv_commands' cmds + reply=("${(ps:\n:)cmds_str}") } _rbenv_versions() { versions_str="$(rbenv versions --bare)" - versions=(system "${(ps:\n:)versions_str}") - _describe '_rbenv_versions' versions + reply=(system "${(ps:\n:)versions_str}") } _rbenv() { + read -cA words case "$words[2]" in set-* | global | local | shell | prefix ) _rbenv_versions ;; * ) _rbenv_commands ;; From 96679b7715a5de98db8743daad2b890301b642a3 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Sat, 10 Sep 2011 20:13:42 -0500 Subject: [PATCH 114/384] Don't leak local variables --- completions/rbenv.zsh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/completions/rbenv.zsh b/completions/rbenv.zsh index e5abc345..45f556e9 100644 --- a/completions/rbenv.zsh +++ b/completions/rbenv.zsh @@ -1,12 +1,12 @@ compctl -K _rbenv rbenv function _rbenv_commands() { - cmds_str="$(rbenv commands)" + local cmds_str="$(rbenv commands)" reply=("${(ps:\n:)cmds_str}") } _rbenv_versions() { - versions_str="$(rbenv versions --bare)" + local versions_str="$(rbenv versions --bare)" reply=(system "${(ps:\n:)versions_str}") } From e5c0fd22e1c56a1d63cc8802b731fb4dc25e11ce Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Sun, 11 Sep 2011 10:16:08 -0500 Subject: [PATCH 115/384] Exit with 0 status when a version file is read successfully --- libexec/rbenv-version-file-read | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libexec/rbenv-version-file-read b/libexec/rbenv-version-file-read index 74f7acb1..bc79d13a 100755 --- a/libexec/rbenv-version-file-read +++ b/libexec/rbenv-version-file-read @@ -10,7 +10,7 @@ if [ -e "$VERSION_FILE" ]; then version="${words[0]}" if [ -n "$version" ]; then echo "$version" - break + exit fi done < <( cat "$VERSION_FILE" && echo ) fi From 6fa81ef28d358e34f56b4c60fd7444d097e76e3f Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Sun, 11 Sep 2011 10:16:22 -0500 Subject: [PATCH 116/384] Add `rbenv local --unset` --- libexec/rbenv-local | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libexec/rbenv-local b/libexec/rbenv-local index 010e93b3..8b08a429 100755 --- a/libexec/rbenv-local +++ b/libexec/rbenv-local @@ -4,7 +4,9 @@ set -e RBENV_VERSION="$1" RBENV_VERSION_FILE=".rbenv-version" -if [ -n "$RBENV_VERSION" ]; then +if [ "$RBENV_VERSION" = "--unset" ]; then + rm -f "$RBENV_VERSION_FILE" +elif [ -n "$RBENV_VERSION" ]; then rbenv-version-file-write "$RBENV_VERSION_FILE" "$RBENV_VERSION" else rbenv-version-file-read "$RBENV_VERSION_FILE" || From 7ac964353ffa4759910089bf337dcd933009f9de Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Sun, 11 Sep 2011 11:58:57 -0500 Subject: [PATCH 117/384] RBENV_HOME -> RBENV_ROOT --- libexec/rbenv | 2 +- libexec/rbenv-global | 2 +- libexec/rbenv-init | 4 ++-- libexec/rbenv-prefix | 2 +- libexec/rbenv-rehash | 4 ++-- libexec/rbenv-version-file | 4 ++-- libexec/rbenv-version-name | 2 +- libexec/rbenv-versions | 2 +- libexec/rbenv-which | 6 +++--- 9 files changed, 14 insertions(+), 14 deletions(-) diff --git a/libexec/rbenv b/libexec/rbenv index 890ca5e1..d15d6e30 100755 --- a/libexec/rbenv +++ b/libexec/rbenv @@ -20,7 +20,7 @@ abs_dirname() { } rbenv_install_location=$(abs_dirname "$(dirname $0)") -export RBENV_HOME="${rbenv_install_location}" +export RBENV_ROOT="${rbenv_install_location}" libexec_path="$(abs_dirname "$0")" export PATH="${libexec_path}:${PATH}" diff --git a/libexec/rbenv-global b/libexec/rbenv-global index 72ad5c17..837a7b4f 100755 --- a/libexec/rbenv-global +++ b/libexec/rbenv-global @@ -8,6 +8,6 @@ if [ -n "$RBENV_VERSION" ]; then rbenv-version-file-write "$RBENV_VERSION_FILE" "$RBENV_VERSION" else rbenv-version-file-read "$RBENV_VERSION_FILE" || - rbenv-version-file-read "${RBENV_HOME}/default" || + rbenv-version-file-read "${RBENV_ROOT}/default" || echo system fi diff --git a/libexec/rbenv-init b/libexec/rbenv-init index bd79efcc..ffc30682 100755 --- a/libexec/rbenv-init +++ b/libexec/rbenv-init @@ -55,9 +55,9 @@ if [ -z "$print" ]; then exit 1 fi -mkdir -p "${RBENV_HOME}/"{shims,versions} +mkdir -p "${RBENV_ROOT}/"{shims,versions} -echo 'export PATH="'${RBENV_HOME}'/shims:${PATH}"' +echo 'export PATH="'${RBENV_ROOT}'/shims:${PATH}"' case "$shell" in bash | zsh ) diff --git a/libexec/rbenv-prefix b/libexec/rbenv-prefix index 677814b3..c623a3e2 100755 --- a/libexec/rbenv-prefix +++ b/libexec/rbenv-prefix @@ -13,7 +13,7 @@ if [ "$RBENV_VERSION" = "system" ]; then exit fi -RBENV_PREFIX_PATH="${RBENV_HOME}/versions/${RBENV_VERSION}" +RBENV_PREFIX_PATH="${RBENV_ROOT}/versions/${RBENV_VERSION}" if [ ! -d "$RBENV_PREFIX_PATH" ]; then echo "rbenv: version \`${RBENV_VERSION}' not installed" >&2 exit 1 diff --git a/libexec/rbenv-rehash b/libexec/rbenv-rehash index 998eab40..a2fe17cf 100755 --- a/libexec/rbenv-rehash +++ b/libexec/rbenv-rehash @@ -1,7 +1,7 @@ #!/usr/bin/env bash set -e -SHIM_PATH="${RBENV_HOME}/shims" +SHIM_PATH="${RBENV_ROOT}/shims" PROTOTYPE_SHIM_PATH="${SHIM_PATH}/.rbenv-shim" # Create the shims directory if it doesn't already exist. @@ -63,7 +63,7 @@ shopt -s nullglob make_shims ../versions/*/bin/* # Find and run any plugins that might want to make shims too. -RBENV_REHASH_PLUGINS=(/etc/rbenv.d/rehash/*.bash ${RBENV_HOME}/rbenv.d/rehash/*.bash) +RBENV_REHASH_PLUGINS=(/etc/rbenv.d/rehash/*.bash ${RBENV_ROOT}/rbenv.d/rehash/*.bash) shopt -u nullglob for script in ${RBENV_REHASH_PLUGINS[@]}; do diff --git a/libexec/rbenv-version-file b/libexec/rbenv-version-file index 6d01e63e..d175dd42 100755 --- a/libexec/rbenv-version-file +++ b/libexec/rbenv-version-file @@ -10,8 +10,8 @@ while [ -n "$root" ]; do root="${root%/*}" done -GLOBAL_PATH="${RBENV_HOME}/global" -DEFAULT_PATH="${RBENV_HOME}/default" +GLOBAL_PATH="${RBENV_ROOT}/global" +DEFAULT_PATH="${RBENV_ROOT}/default" if [ -e "$GLOBAL_PATH" ]; then echo "$GLOBAL_PATH" diff --git a/libexec/rbenv-version-name b/libexec/rbenv-version-name index 7284edc9..74f6de04 100755 --- a/libexec/rbenv-version-name +++ b/libexec/rbenv-version-name @@ -11,7 +11,7 @@ if [ -z "$RBENV_VERSION" ] || [ "$RBENV_VERSION" = "system" ]; then exit fi -RBENV_VERSION_PATH="${RBENV_HOME}/versions/${RBENV_VERSION}" +RBENV_VERSION_PATH="${RBENV_ROOT}/versions/${RBENV_VERSION}" if [ -d "$RBENV_VERSION_PATH" ]; then echo "$RBENV_VERSION" diff --git a/libexec/rbenv-versions b/libexec/rbenv-versions index 4abb9db4..ac53ad11 100755 --- a/libexec/rbenv-versions +++ b/libexec/rbenv-versions @@ -13,7 +13,7 @@ else print_version="$(rbenv-version)" fi -for path in "${RBENV_HOME}/versions/"*; do +for path in "${RBENV_ROOT}/versions/"*; do if [ -d "$path" ]; then version="${path##*/}" diff --git a/libexec/rbenv-which b/libexec/rbenv-which index 7a8939bd..32884ed9 100755 --- a/libexec/rbenv-which +++ b/libexec/rbenv-which @@ -35,14 +35,14 @@ RBENV_VERSION="$(rbenv-version-name)" RBENV_COMMAND="$1" if [ "$RBENV_VERSION" = "system" ]; then - PATH="$(remove_from_path "${RBENV_HOME}/shims")" + PATH="$(remove_from_path "${RBENV_ROOT}/shims")" RBENV_COMMAND_PATH="$(command -v "$RBENV_COMMAND")" else - RBENV_COMMAND_PATH="${RBENV_HOME}/versions/${RBENV_VERSION}/bin/${RBENV_COMMAND}" + RBENV_COMMAND_PATH="${RBENV_ROOT}/versions/${RBENV_VERSION}/bin/${RBENV_COMMAND}" fi shopt -s nullglob -RBENV_WHICH_PLUGINS=(/etc/rbenv.d/which/*.bash ${RBENV_HOME}/rbenv.d/which/*.bash) +RBENV_WHICH_PLUGINS=(/etc/rbenv.d/which/*.bash ${RBENV_ROOT}/rbenv.d/which/*.bash) shopt -u nullglob for script in ${RBENV_WHICH_PLUGINS[@]}; do From 8f6b0bc1d41aa04a85af73c8fedac9aa0d58c419 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Sun, 11 Sep 2011 12:00:02 -0500 Subject: [PATCH 118/384] Use RBENV_ROOT to search for rbenv-exec plugins --- libexec/rbenv-exec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libexec/rbenv-exec b/libexec/rbenv-exec index 3e3929d9..9d1a70af 100755 --- a/libexec/rbenv-exec +++ b/libexec/rbenv-exec @@ -11,7 +11,7 @@ RBENV_COMMAND_PATH="$(rbenv-which "$RBENV_COMMAND")" RBENV_BIN_PATH="${RBENV_COMMAND_PATH%/*}" shopt -s nullglob -RBENV_EXEC_PLUGINS=(/etc/rbenv.d/exec/*.bash ${HOME}/.rbenv/rbenv.d/exec/*.bash) +RBENV_EXEC_PLUGINS=(/etc/rbenv.d/exec/*.bash ${RBENV_ROOT}/rbenv.d/exec/*.bash) shopt -u nullglob for script in ${RBENV_EXEC_PLUGINS[@]}; do From c36950a7cbc0a99894c487750002deb47346ae46 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Sun, 11 Sep 2011 12:04:59 -0500 Subject: [PATCH 119/384] RBENV_HOME -> RBENV_ROOT --- libexec/rbenv-global | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libexec/rbenv-global b/libexec/rbenv-global index 837a7b4f..134c26b9 100755 --- a/libexec/rbenv-global +++ b/libexec/rbenv-global @@ -2,7 +2,7 @@ set -e RBENV_VERSION="$1" -RBENV_VERSION_FILE="${RBENV_HOME}/global" +RBENV_VERSION_FILE="${RBENV_ROOT}/global" if [ -n "$RBENV_VERSION" ]; then rbenv-version-file-write "$RBENV_VERSION_FILE" "$RBENV_VERSION" From 2e3e141d2e4a209ef7b13f33ff5b0136a17638f1 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Sun, 11 Sep 2011 12:05:56 -0500 Subject: [PATCH 120/384] RBENV_ROOT defaults to ~/.rbenv --- libexec/rbenv | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libexec/rbenv b/libexec/rbenv index d15d6e30..275e122a 100755 --- a/libexec/rbenv +++ b/libexec/rbenv @@ -19,8 +19,10 @@ abs_dirname() { cd "$cwd" } -rbenv_install_location=$(abs_dirname "$(dirname $0)") -export RBENV_ROOT="${rbenv_install_location}" +if [ -z "${RBENV_ROOT}" ]; then + RBENV_ROOT="${HOME}/.rbenv" +fi +export RBENV_ROOT libexec_path="$(abs_dirname "$0")" export PATH="${libexec_path}:${PATH}" From 0632325a438a3aef38e7f94e10308ee69b72ad97 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Mon, 12 Sep 2011 10:11:59 -0500 Subject: [PATCH 121/384] Set RBENV_DEBUG=1 to see what's going on under the hood --- libexec/rbenv | 1 + libexec/rbenv-commands | 1 + libexec/rbenv-exec | 1 + libexec/rbenv-global | 1 + libexec/rbenv-help | 1 + libexec/rbenv-init | 1 + libexec/rbenv-local | 1 + libexec/rbenv-prefix | 1 + libexec/rbenv-rehash | 1 + libexec/rbenv-sh-shell | 1 + libexec/rbenv-version | 1 + libexec/rbenv-version-file | 1 + libexec/rbenv-version-file-read | 1 + libexec/rbenv-version-file-write | 1 + libexec/rbenv-version-name | 1 + libexec/rbenv-version-origin | 1 + libexec/rbenv-versions | 1 + libexec/rbenv-whence | 1 + libexec/rbenv-which | 1 + 19 files changed, 19 insertions(+) diff --git a/libexec/rbenv b/libexec/rbenv index 275e122a..3c241d3e 100755 --- a/libexec/rbenv +++ b/libexec/rbenv @@ -1,5 +1,6 @@ #!/usr/bin/env bash set -e +[ -n "$RBENV_DEBUG" ] && set -x resolve_link() { $(type -p greadlink readlink | head -1) $1 diff --git a/libexec/rbenv-commands b/libexec/rbenv-commands index 4b593b4b..94fa249e 100755 --- a/libexec/rbenv-commands +++ b/libexec/rbenv-commands @@ -1,5 +1,6 @@ #!/usr/bin/env bash set -e +[ -n "$RBENV_DEBUG" ] && set -x if [ "$1" = "--sh" ]; then sh=1 diff --git a/libexec/rbenv-exec b/libexec/rbenv-exec index 9d1a70af..6d6ad1eb 100755 --- a/libexec/rbenv-exec +++ b/libexec/rbenv-exec @@ -1,5 +1,6 @@ #!/usr/bin/env bash set -e +[ -n "$RBENV_DEBUG" ] && set -x RBENV_COMMAND="$1" if [ -z "$RBENV_COMMAND" ]; then diff --git a/libexec/rbenv-global b/libexec/rbenv-global index 134c26b9..4bffa7cf 100755 --- a/libexec/rbenv-global +++ b/libexec/rbenv-global @@ -1,5 +1,6 @@ #!/usr/bin/env bash set -e +[ -n "$RBENV_DEBUG" ] && set -x RBENV_VERSION="$1" RBENV_VERSION_FILE="${RBENV_ROOT}/global" diff --git a/libexec/rbenv-help b/libexec/rbenv-help index 36fcf26b..7d941360 100755 --- a/libexec/rbenv-help +++ b/libexec/rbenv-help @@ -1,5 +1,6 @@ #!/usr/bin/env bash set -e +[ -n "$RBENV_DEBUG" ] && set -x print_set_version() { echo " should be a string matching a Ruby version known by rbenv." diff --git a/libexec/rbenv-init b/libexec/rbenv-init index ffc30682..a83cee40 100755 --- a/libexec/rbenv-init +++ b/libexec/rbenv-init @@ -1,5 +1,6 @@ #!/usr/bin/env bash set -e +[ -n "$RBENV_DEBUG" ] && set -x print="" if [ "$1" = "-" ]; then diff --git a/libexec/rbenv-local b/libexec/rbenv-local index 8b08a429..e8f1c96d 100755 --- a/libexec/rbenv-local +++ b/libexec/rbenv-local @@ -1,5 +1,6 @@ #!/usr/bin/env bash set -e +[ -n "$RBENV_DEBUG" ] && set -x RBENV_VERSION="$1" RBENV_VERSION_FILE=".rbenv-version" diff --git a/libexec/rbenv-prefix b/libexec/rbenv-prefix index c623a3e2..41df5323 100755 --- a/libexec/rbenv-prefix +++ b/libexec/rbenv-prefix @@ -1,5 +1,6 @@ #!/usr/bin/env bash set -e +[ -n "$RBENV_DEBUG" ] && set -x if [ -n "$1" ]; then RBENV_VERSION="$1" diff --git a/libexec/rbenv-rehash b/libexec/rbenv-rehash index a2fe17cf..10c5d1e8 100755 --- a/libexec/rbenv-rehash +++ b/libexec/rbenv-rehash @@ -1,5 +1,6 @@ #!/usr/bin/env bash set -e +[ -n "$RBENV_DEBUG" ] && set -x SHIM_PATH="${RBENV_ROOT}/shims" PROTOTYPE_SHIM_PATH="${SHIM_PATH}/.rbenv-shim" diff --git a/libexec/rbenv-sh-shell b/libexec/rbenv-sh-shell index d2c80904..dde85e11 100755 --- a/libexec/rbenv-sh-shell +++ b/libexec/rbenv-sh-shell @@ -1,5 +1,6 @@ #!/usr/bin/env bash set -e +[ -n "$RBENV_DEBUG" ] && set -x version="$1" diff --git a/libexec/rbenv-version b/libexec/rbenv-version index b3b2cdf0..7251a4c9 100755 --- a/libexec/rbenv-version +++ b/libexec/rbenv-version @@ -1,4 +1,5 @@ #!/usr/bin/env bash set -e +[ -n "$RBENV_DEBUG" ] && set -x echo "$(rbenv-version-name) (set by $(rbenv-version-origin))" diff --git a/libexec/rbenv-version-file b/libexec/rbenv-version-file index d175dd42..eb72ec38 100755 --- a/libexec/rbenv-version-file +++ b/libexec/rbenv-version-file @@ -1,5 +1,6 @@ #!/usr/bin/env bash set -e +[ -n "$RBENV_DEBUG" ] && set -x root="$(pwd)" while [ -n "$root" ]; do diff --git a/libexec/rbenv-version-file-read b/libexec/rbenv-version-file-read index bc79d13a..8d27b0f0 100755 --- a/libexec/rbenv-version-file-read +++ b/libexec/rbenv-version-file-read @@ -1,5 +1,6 @@ #!/usr/bin/env bash set -e +[ -n "$RBENV_DEBUG" ] && set -x VERSION_FILE="$1" diff --git a/libexec/rbenv-version-file-write b/libexec/rbenv-version-file-write index 0435cf14..7c0fc7db 100755 --- a/libexec/rbenv-version-file-write +++ b/libexec/rbenv-version-file-write @@ -1,5 +1,6 @@ #!/usr/bin/env bash set -e +[ -n "$RBENV_DEBUG" ] && set -x RBENV_VERSION_FILE="$1" RBENV_VERSION="$2" diff --git a/libexec/rbenv-version-name b/libexec/rbenv-version-name index 74f6de04..f65fa1d4 100755 --- a/libexec/rbenv-version-name +++ b/libexec/rbenv-version-name @@ -1,5 +1,6 @@ #!/usr/bin/env bash set -e +[ -n "$RBENV_DEBUG" ] && set -x if [ -z "$RBENV_VERSION" ]; then RBENV_VERSION_FILE="$(rbenv-version-file)" diff --git a/libexec/rbenv-version-origin b/libexec/rbenv-version-origin index 31653d49..9b029b0c 100755 --- a/libexec/rbenv-version-origin +++ b/libexec/rbenv-version-origin @@ -1,5 +1,6 @@ #!/usr/bin/env bash set -e +[ -n "$RBENV_DEBUG" ] && set -x if [ -n "$RBENV_VERSION" ]; then echo "RBENV_VERSION environment variable" diff --git a/libexec/rbenv-versions b/libexec/rbenv-versions index ac53ad11..2fb8fc07 100755 --- a/libexec/rbenv-versions +++ b/libexec/rbenv-versions @@ -1,5 +1,6 @@ #!/usr/bin/env bash set -e +[ -n "$RBENV_DEBUG" ] && set -x RBENV_VERSION_NAME="$(rbenv-version-name)" diff --git a/libexec/rbenv-whence b/libexec/rbenv-whence index 591ad6cd..f90b6c4e 100755 --- a/libexec/rbenv-whence +++ b/libexec/rbenv-whence @@ -1,5 +1,6 @@ #!/usr/bin/env bash set -e +[ -n "$RBENV_DEBUG" ] && set -x if [ "$1" = "--path" ]; then print_paths="1" diff --git a/libexec/rbenv-which b/libexec/rbenv-which index 32884ed9..233c3e4f 100755 --- a/libexec/rbenv-which +++ b/libexec/rbenv-which @@ -1,5 +1,6 @@ #!/usr/bin/env bash set -e +[ -n "$RBENV_DEBUG" ] && set -x expand_path() { if [ ! -d "$1" ]; then From 964c12fe2764da6b1de264505d25a41c5f0de60d Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Mon, 12 Sep 2011 11:05:45 -0500 Subject: [PATCH 122/384] Ensure shims set RBENV_ROOT --- libexec/rbenv-rehash | 1 + 1 file changed, 1 insertion(+) diff --git a/libexec/rbenv-rehash b/libexec/rbenv-rehash index 10c5d1e8..c69a129a 100755 --- a/libexec/rbenv-rehash +++ b/libexec/rbenv-rehash @@ -37,6 +37,7 @@ create_prototype_shim() { cat > "$PROTOTYPE_SHIM_PATH" < Date: Tue, 13 Sep 2011 10:13:27 -0500 Subject: [PATCH 123/384] Proof-of-concept external completions --- completions/rbenv.bash | 31 ++++++++----------------------- libexec/rbenv-completions | 15 +++++++++++++++ libexec/rbenv-local | 7 +++++++ 3 files changed, 30 insertions(+), 23 deletions(-) create mode 100755 libexec/rbenv-completions diff --git a/completions/rbenv.bash b/completions/rbenv.bash index d548a859..e3276016 100644 --- a/completions/rbenv.bash +++ b/completions/rbenv.bash @@ -1,29 +1,14 @@ -_rbenv_commands() { - COMPREPLY=() - local cur="${COMP_WORDS[COMP_CWORD]}" - COMPREPLY=( $( compgen -W "$(rbenv commands)" -- $cur ) ) -} - -_rbenv_versions() { - COMPREPLY=() - local cur="${COMP_WORDS[COMP_CWORD]}" - local versions="$(echo system; rbenv versions --bare)" - COMPREPLY=( $( compgen -W "$versions" -- $cur ) ) -} - _rbenv() { COMPREPLY=() - local cur="${COMP_WORDS[COMP_CWORD]}" - local prev="${COMP_WORDS[COMP_CWORD-1]}" + local word="${COMP_WORDS[COMP_CWORD]}" - case "$prev" in - set-* | global | local | shell | prefix ) - _rbenv_versions - ;; - * ) - _rbenv_commands - ;; - esac + if [ "$COMP_CWORD" -eq 1 ]; then + COMPREPLY=( $(compgen -W "$(rbenv commands)" -- "$word") ) + else + local command="${COMP_WORDS[1]}" + local completions="$(rbenv completions "$command")" + COMPREPLY=( $(compgen -W "$completions" -- "$word") ) + fi } complete -F _rbenv rbenv diff --git a/libexec/rbenv-completions b/libexec/rbenv-completions new file mode 100755 index 00000000..e83690dc --- /dev/null +++ b/libexec/rbenv-completions @@ -0,0 +1,15 @@ +#!/usr/bin/env bash +set -e +[ -n "$RBENV_DEBUG" ] && set -x + +COMMAND="$1" +if [ -z "$COMMAND" ]; then + echo "usage: rbenv completions COMMAND [arg1 arg2...]" >&2 + exit 1 +fi + +COMMAND_PATH="$(command -v "rbenv-$COMMAND")" +if grep -i "^# provide rbenv completions" "$COMMAND_PATH" >/dev/null; then + shift + exec "$COMMAND_PATH" --complete "$@" +fi diff --git a/libexec/rbenv-local b/libexec/rbenv-local index e8f1c96d..d261564c 100755 --- a/libexec/rbenv-local +++ b/libexec/rbenv-local @@ -2,6 +2,13 @@ set -e [ -n "$RBENV_DEBUG" ] && set -x +# Provide rbenv completions +if [ "$1" = "--complete" ]; then + shift + echo system + exec rbenv-versions --bare +fi + RBENV_VERSION="$1" RBENV_VERSION_FILE=".rbenv-version" From d50ce90a36d954473e85fb8d9ef0bb09e4b9e4d1 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Tue, 13 Sep 2011 12:33:46 -0500 Subject: [PATCH 124/384] Add --unset to local completion --- libexec/rbenv-local | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libexec/rbenv-local b/libexec/rbenv-local index d261564c..b9312fd1 100755 --- a/libexec/rbenv-local +++ b/libexec/rbenv-local @@ -5,7 +5,7 @@ set -e # Provide rbenv completions if [ "$1" = "--complete" ]; then shift - echo system + echo system --unset exec rbenv-versions --bare fi From 43520db38915e7c42fefea442c571525d2310e40 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Tue, 13 Sep 2011 12:37:29 -0500 Subject: [PATCH 125/384] Fix `rbenv prefix system` --- libexec/rbenv-prefix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libexec/rbenv-prefix b/libexec/rbenv-prefix index 41df5323..9aeacc09 100755 --- a/libexec/rbenv-prefix +++ b/libexec/rbenv-prefix @@ -3,7 +3,7 @@ set -e [ -n "$RBENV_DEBUG" ] && set -x if [ -n "$1" ]; then - RBENV_VERSION="$1" + export RBENV_VERSION="$1" elif [ -z "$RBENV_VERSION" ]; then RBENV_VERSION="$(rbenv-version-name)" fi From f1ca8906c0f38940dbe7b162cedacd6b76d75735 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Tue, 13 Sep 2011 12:38:34 -0500 Subject: [PATCH 126/384] Completions for global, local, prefix, shell --- libexec/rbenv-global | 6 ++++++ libexec/rbenv-local | 1 - libexec/rbenv-prefix | 6 ++++++ libexec/rbenv-sh-shell | 6 ++++++ 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/libexec/rbenv-global b/libexec/rbenv-global index 4bffa7cf..0c239fd1 100755 --- a/libexec/rbenv-global +++ b/libexec/rbenv-global @@ -2,6 +2,12 @@ set -e [ -n "$RBENV_DEBUG" ] && set -x +# Provide rbenv completions +if [ "$1" = "--complete" ]; then + echo system + exec rbenv-versions --bare +fi + RBENV_VERSION="$1" RBENV_VERSION_FILE="${RBENV_ROOT}/global" diff --git a/libexec/rbenv-local b/libexec/rbenv-local index b9312fd1..5e154069 100755 --- a/libexec/rbenv-local +++ b/libexec/rbenv-local @@ -4,7 +4,6 @@ set -e # Provide rbenv completions if [ "$1" = "--complete" ]; then - shift echo system --unset exec rbenv-versions --bare fi diff --git a/libexec/rbenv-prefix b/libexec/rbenv-prefix index 9aeacc09..e6094aec 100755 --- a/libexec/rbenv-prefix +++ b/libexec/rbenv-prefix @@ -2,6 +2,12 @@ set -e [ -n "$RBENV_DEBUG" ] && set -x +# Provide rbenv completions +if [ "$1" = "--complete" ]; then + echo system + exec rbenv-versions --bare +fi + if [ -n "$1" ]; then export RBENV_VERSION="$1" elif [ -z "$RBENV_VERSION" ]; then diff --git a/libexec/rbenv-sh-shell b/libexec/rbenv-sh-shell index dde85e11..674a9267 100755 --- a/libexec/rbenv-sh-shell +++ b/libexec/rbenv-sh-shell @@ -2,6 +2,12 @@ set -e [ -n "$RBENV_DEBUG" ] && set -x +# Provide rbenv completions +if [ "$1" = "--complete" ]; then + echo system --unset + exec rbenv-versions --bare +fi + version="$1" if [ -z "$version" ]; then From 4923838981ae57c3d70fef988c3d2db9f70279b3 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Tue, 13 Sep 2011 12:46:06 -0500 Subject: [PATCH 127/384] Completion for exec --- libexec/rbenv-exec | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libexec/rbenv-exec b/libexec/rbenv-exec index 6d6ad1eb..d53065fa 100755 --- a/libexec/rbenv-exec +++ b/libexec/rbenv-exec @@ -2,6 +2,14 @@ set -e [ -n "$RBENV_DEBUG" ] && set -x +# Provide rbenv completions +if [ "$1" = "--complete" ]; then + for command in "${RBENV_ROOT}/shims/"*; do + echo "${command##*/}" + done + exit +fi + RBENV_COMMAND="$1" if [ -z "$RBENV_COMMAND" ]; then echo "usage: rbenv exec COMMAND [arg1 arg2...]" >&2 From 69d596f56fbf1e18e8d70f9a8b20353b7bc29f1e Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Tue, 13 Sep 2011 12:48:49 -0500 Subject: [PATCH 128/384] Completion for commands --- libexec/rbenv-commands | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/libexec/rbenv-commands b/libexec/rbenv-commands index 94fa249e..a5d56cc2 100755 --- a/libexec/rbenv-commands +++ b/libexec/rbenv-commands @@ -2,12 +2,16 @@ set -e [ -n "$RBENV_DEBUG" ] && set -x +# Provide rbenv completions +if [ "$1" = "--complete" ]; then + echo --sh --no-sh + exit +fi + if [ "$1" = "--sh" ]; then sh=1 shift -fi - -if [ "$1" = "--no-sh" ]; then +elif [ "$1" = "--no-sh" ]; then nosh=1 shift fi From 61830048d5b0e4d064d2186a103c9da692ad1d07 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Tue, 13 Sep 2011 12:55:19 -0500 Subject: [PATCH 129/384] Extract rbenv-shims --- libexec/rbenv-exec | 5 +---- libexec/rbenv-shims | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) create mode 100755 libexec/rbenv-shims diff --git a/libexec/rbenv-exec b/libexec/rbenv-exec index d53065fa..ac060196 100755 --- a/libexec/rbenv-exec +++ b/libexec/rbenv-exec @@ -4,10 +4,7 @@ set -e # Provide rbenv completions if [ "$1" = "--complete" ]; then - for command in "${RBENV_ROOT}/shims/"*; do - echo "${command##*/}" - done - exit + exec rbenv shims --short fi RBENV_COMMAND="$1" diff --git a/libexec/rbenv-shims b/libexec/rbenv-shims new file mode 100755 index 00000000..6691e60d --- /dev/null +++ b/libexec/rbenv-shims @@ -0,0 +1,17 @@ +#!/usr/bin/env bash +set -e +[ -n "$RBENV_DEBUG" ] && set -x + +# Provide rbenv completions +if [ "$1" = "--complete" ]; then + echo --short + exit +fi + +for command in "${RBENV_ROOT}/shims/"*; do + if [ "$1" = "--short" ]; then + echo "${command##*/}" + else + echo "$command" + fi +done | sort From 03d664e0481b51b77ceadfb7d4fb64e131aef32e Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Tue, 13 Sep 2011 12:59:59 -0500 Subject: [PATCH 130/384] Completion for whence --- libexec/rbenv-whence | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libexec/rbenv-whence b/libexec/rbenv-whence index f90b6c4e..8a926877 100755 --- a/libexec/rbenv-whence +++ b/libexec/rbenv-whence @@ -2,6 +2,12 @@ set -e [ -n "$RBENV_DEBUG" ] && set -x +# Provide rbenv completions +if [ "$1" = "--complete" ]; then + echo --path + exec rbenv shims --short +fi + if [ "$1" = "--path" ]; then print_paths="1" shift From 3644840d4b23a00561f2500047f00aa8c1f234fb Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Tue, 13 Sep 2011 13:01:31 -0500 Subject: [PATCH 131/384] Show usage for `rbenv which` without an argument --- libexec/rbenv-which | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libexec/rbenv-which b/libexec/rbenv-which index 233c3e4f..cf5864a6 100755 --- a/libexec/rbenv-which +++ b/libexec/rbenv-which @@ -35,6 +35,11 @@ remove_from_path() { RBENV_VERSION="$(rbenv-version-name)" RBENV_COMMAND="$1" +if [ -z "$RBENV_COMMAND" ]; then + echo "usage: rbenv which COMMAND" >&2 + exit 1 +fi + if [ "$RBENV_VERSION" = "system" ]; then PATH="$(remove_from_path "${RBENV_ROOT}/shims")" RBENV_COMMAND_PATH="$(command -v "$RBENV_COMMAND")" From 465a1472bae33fa474660459cd446e73197054f7 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Tue, 13 Sep 2011 13:02:55 -0500 Subject: [PATCH 132/384] Completion for which --- libexec/rbenv-which | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libexec/rbenv-which b/libexec/rbenv-which index cf5864a6..4ba82678 100755 --- a/libexec/rbenv-which +++ b/libexec/rbenv-which @@ -2,6 +2,11 @@ set -e [ -n "$RBENV_DEBUG" ] && set -x +# Provide rbenv completions +if [ "$1" = "--complete" ]; then + exec rbenv shims --short +fi + expand_path() { if [ ! -d "$1" ]; then return 1 From b4f8906b246711db4c5116a12b6d9b0772084b97 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Tue, 13 Sep 2011 13:12:04 -0500 Subject: [PATCH 133/384] Update zsh completion adapter --- completions/rbenv.zsh | 24 ++++++++++-------------- libexec/rbenv-commands | 3 ++- libexec/rbenv-local | 3 ++- libexec/rbenv-sh-shell | 3 ++- 4 files changed, 16 insertions(+), 17 deletions(-) diff --git a/completions/rbenv.zsh b/completions/rbenv.zsh index 45f556e9..f1a41ad9 100644 --- a/completions/rbenv.zsh +++ b/completions/rbenv.zsh @@ -1,19 +1,15 @@ compctl -K _rbenv rbenv -function _rbenv_commands() { - local cmds_str="$(rbenv commands)" - reply=("${(ps:\n:)cmds_str}") -} - -_rbenv_versions() { - local versions_str="$(rbenv versions --bare)" - reply=(system "${(ps:\n:)versions_str}") -} - _rbenv() { + local word words completions read -cA words - case "$words[2]" in - set-* | global | local | shell | prefix ) _rbenv_versions ;; - * ) _rbenv_commands ;; - esac + word="${words[2]}" + + if [ "${#words}" -eq 2 ]; then + completions="$(rbenv commands)" + else + completions="$(rbenv completions "${word}")" + fi + + reply=("${(ps:\n:)completions}") } diff --git a/libexec/rbenv-commands b/libexec/rbenv-commands index a5d56cc2..297f8d99 100755 --- a/libexec/rbenv-commands +++ b/libexec/rbenv-commands @@ -4,7 +4,8 @@ set -e # Provide rbenv completions if [ "$1" = "--complete" ]; then - echo --sh --no-sh + echo --sh + echo --no-sh exit fi diff --git a/libexec/rbenv-local b/libexec/rbenv-local index 5e154069..9b102c5c 100755 --- a/libexec/rbenv-local +++ b/libexec/rbenv-local @@ -4,7 +4,8 @@ set -e # Provide rbenv completions if [ "$1" = "--complete" ]; then - echo system --unset + echo --unset + echo system exec rbenv-versions --bare fi diff --git a/libexec/rbenv-sh-shell b/libexec/rbenv-sh-shell index 674a9267..a216cb29 100755 --- a/libexec/rbenv-sh-shell +++ b/libexec/rbenv-sh-shell @@ -4,7 +4,8 @@ set -e # Provide rbenv completions if [ "$1" = "--complete" ]; then - echo system --unset + echo --unset + echo system exec rbenv-versions --bare fi From 568cd4b23e5c0a8dc24e8a1fa591760d4a5790ed Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Wed, 14 Sep 2011 12:45:44 -0500 Subject: [PATCH 134/384] Strip trailing slashes from RBENV_ROOT (#83) --- libexec/rbenv | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libexec/rbenv b/libexec/rbenv index 3c241d3e..0a9d0122 100755 --- a/libexec/rbenv +++ b/libexec/rbenv @@ -22,6 +22,8 @@ abs_dirname() { if [ -z "${RBENV_ROOT}" ]; then RBENV_ROOT="${HOME}/.rbenv" +else + RBENV_ROOT="${RBENV_ROOT%/}" fi export RBENV_ROOT From 305db1c35ba426257378ea64e1057b11350043cf Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Fri, 16 Sep 2011 14:18:29 -0500 Subject: [PATCH 135/384] Fix rbenv-completions for shell commands. Closes #90. --- libexec/rbenv-completions | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libexec/rbenv-completions b/libexec/rbenv-completions index e83690dc..4bc21a3c 100755 --- a/libexec/rbenv-completions +++ b/libexec/rbenv-completions @@ -8,7 +8,7 @@ if [ -z "$COMMAND" ]; then exit 1 fi -COMMAND_PATH="$(command -v "rbenv-$COMMAND")" +COMMAND_PATH="$(command -v "rbenv-$COMMAND" || command -v "rbenv-sh-$COMMAND")" if grep -i "^# provide rbenv completions" "$COMMAND_PATH" >/dev/null; then shift exec "$COMMAND_PATH" --complete "$@" From 919fc872c8d92b1ff8b4c1fcbe504ce7853ca28a Mon Sep 17 00:00:00 2001 From: Javier Julio Date: Sat, 17 Sep 2011 17:38:09 -0400 Subject: [PATCH 136/384] Using simpler rbenv-install command in ruby-build section --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 10942cfa..4967aec5 100644 --- a/README.md +++ b/README.md @@ -109,7 +109,7 @@ install Ruby 1.9.2-p290, download and unpack the source, then run: The [ruby-build](https://github.com/sstephenson/ruby-build) project simplifies this process to a single command: - $ ruby-build 1.9.2-p290 $HOME/.rbenv/versions/1.9.2-p290 + $ rbenv-install 1.9.2-p290 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 From 94d87211f978c1fff3ab79537191683d30742079 Mon Sep 17 00:00:00 2001 From: Roy Liu Date: Mon, 19 Sep 2011 10:45:12 -0400 Subject: [PATCH 137/384] Restore the current working directory in rbenv-rehash --- libexec/rbenv-rehash | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libexec/rbenv-rehash b/libexec/rbenv-rehash index c69a129a..3d9a9a70 100755 --- a/libexec/rbenv-rehash +++ b/libexec/rbenv-rehash @@ -55,6 +55,9 @@ make_shims() { done } +# Save the working directory. +CUR_PATH=$PWD + # Empty out the shims directory and make it the working directory. rm -f "$SHIM_PATH"/* cd "$SHIM_PATH" @@ -68,6 +71,9 @@ make_shims ../versions/*/bin/* RBENV_REHASH_PLUGINS=(/etc/rbenv.d/rehash/*.bash ${RBENV_ROOT}/rbenv.d/rehash/*.bash) shopt -u nullglob +# Restore the previous working directory. +cd "$CUR_PATH" + for script in ${RBENV_REHASH_PLUGINS[@]}; do source $script done From c6c6ebaf40f4b2c439a5417a16d3f1f805e07711 Mon Sep 17 00:00:00 2001 From: Javier Julio Date: Tue, 20 Sep 2011 10:59:27 -0400 Subject: [PATCH 138/384] Updating command sample to "rbenv install", no dash --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4967aec5..4e57fd06 100644 --- a/README.md +++ b/README.md @@ -109,7 +109,7 @@ install Ruby 1.9.2-p290, download and unpack the source, then run: The [ruby-build](https://github.com/sstephenson/ruby-build) project simplifies this process to a single command: - $ rbenv-install 1.9.2-p290 + $ rbenv install 1.9.2-p290 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 From 789ace54ec8699d5042c7cd0dda244610b2a5e1c Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Wed, 21 Sep 2011 12:36:07 -0500 Subject: [PATCH 139/384] Add bin to list plugin scripts --- libexec/rbenv-plugin-scripts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100755 libexec/rbenv-plugin-scripts diff --git a/libexec/rbenv-plugin-scripts b/libexec/rbenv-plugin-scripts new file mode 100755 index 00000000..e77c8719 --- /dev/null +++ b/libexec/rbenv-plugin-scripts @@ -0,0 +1,19 @@ +#!/usr/bin/env bash +set -e +[ -n "$RBENV_DEBUG" ] && set -x + +# Provide rbenv completions +if [ "$1" = "--complete" ]; then + echo exec + echo rehash + echo which + exit +fi + +shopt -s nullglob +RBENV_EXEC_PLUGINS=(/etc/rbenv.d/$1/*.bash ${RBENV_ROOT}/rbenv.d/$1/*.bash) +shopt -u nullglob + +for script in ${RBENV_EXEC_PLUGINS[@]}; do + echo $script +done From 96b98ed039ae39fc386d2c93dc3568df6973ec35 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Wed, 21 Sep 2011 12:38:58 -0500 Subject: [PATCH 140/384] Use plugin-scripts --- libexec/rbenv-exec | 8 ++------ libexec/rbenv-rehash | 8 ++------ libexec/rbenv-which | 8 ++------ 3 files changed, 6 insertions(+), 18 deletions(-) diff --git a/libexec/rbenv-exec b/libexec/rbenv-exec index ac060196..d940a7a3 100755 --- a/libexec/rbenv-exec +++ b/libexec/rbenv-exec @@ -16,12 +16,8 @@ fi RBENV_COMMAND_PATH="$(rbenv-which "$RBENV_COMMAND")" RBENV_BIN_PATH="${RBENV_COMMAND_PATH%/*}" -shopt -s nullglob -RBENV_EXEC_PLUGINS=(/etc/rbenv.d/exec/*.bash ${RBENV_ROOT}/rbenv.d/exec/*.bash) -shopt -u nullglob - -for script in ${RBENV_EXEC_PLUGINS[@]}; do - source $script +for script in $(rbenv-plugin-scripts exec); do + source $script; done shift 1 diff --git a/libexec/rbenv-rehash b/libexec/rbenv-rehash index 3d9a9a70..a11b64bd 100755 --- a/libexec/rbenv-rehash +++ b/libexec/rbenv-rehash @@ -67,13 +67,9 @@ create_prototype_shim shopt -s nullglob make_shims ../versions/*/bin/* -# Find and run any plugins that might want to make shims too. -RBENV_REHASH_PLUGINS=(/etc/rbenv.d/rehash/*.bash ${RBENV_ROOT}/rbenv.d/rehash/*.bash) -shopt -u nullglob - # Restore the previous working directory. cd "$CUR_PATH" -for script in ${RBENV_REHASH_PLUGINS[@]}; do - source $script +for script in $(rbenv-plugin-scripts rehash); do + source $script; done diff --git a/libexec/rbenv-which b/libexec/rbenv-which index 4ba82678..a47badd3 100755 --- a/libexec/rbenv-which +++ b/libexec/rbenv-which @@ -52,12 +52,8 @@ else RBENV_COMMAND_PATH="${RBENV_ROOT}/versions/${RBENV_VERSION}/bin/${RBENV_COMMAND}" fi -shopt -s nullglob -RBENV_WHICH_PLUGINS=(/etc/rbenv.d/which/*.bash ${RBENV_ROOT}/rbenv.d/which/*.bash) -shopt -u nullglob - -for script in ${RBENV_WHICH_PLUGINS[@]}; do - source $script +for script in $(rbenv-plugin-scripts which); do + source $script; done if [ -x "$RBENV_COMMAND_PATH" ]; then From 2b5fb40b99b555dcaed597faa1b7cd0f158c227a Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Wed, 21 Sep 2011 12:39:26 -0500 Subject: [PATCH 141/384] Not exec specific --- libexec/rbenv-plugin-scripts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libexec/rbenv-plugin-scripts b/libexec/rbenv-plugin-scripts index e77c8719..2bc5bfdf 100755 --- a/libexec/rbenv-plugin-scripts +++ b/libexec/rbenv-plugin-scripts @@ -11,9 +11,9 @@ if [ "$1" = "--complete" ]; then fi shopt -s nullglob -RBENV_EXEC_PLUGINS=(/etc/rbenv.d/$1/*.bash ${RBENV_ROOT}/rbenv.d/$1/*.bash) +SCRIPTS=(/etc/rbenv.d/$1/*.bash ${RBENV_ROOT}/rbenv.d/$1/*.bash) shopt -u nullglob -for script in ${RBENV_EXEC_PLUGINS[@]}; do +for script in ${SCRIPTS[@]}; do echo $script done From 0c7c62dc04dab195ff249bc93460a4c4c352ac00 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Wed, 21 Sep 2011 12:43:22 -0500 Subject: [PATCH 142/384] Show usage if no arguments are passed to rbenv-plugin-scripts --- libexec/rbenv-plugin-scripts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/libexec/rbenv-plugin-scripts b/libexec/rbenv-plugin-scripts index 2bc5bfdf..27568007 100755 --- a/libexec/rbenv-plugin-scripts +++ b/libexec/rbenv-plugin-scripts @@ -10,8 +10,14 @@ if [ "$1" = "--complete" ]; then exit fi +RBENV_COMMAND="$1" +if [ -z "$RBENV_COMMAND" ]; then + echo "usage: rbenv plugin-scripts COMMAND" >&2 + exit 1 +fi + shopt -s nullglob -SCRIPTS=(/etc/rbenv.d/$1/*.bash ${RBENV_ROOT}/rbenv.d/$1/*.bash) +SCRIPTS=(/etc/rbenv.d/"$RBENV_COMMAND"/*.bash ${RBENV_ROOT}/rbenv.d/"$RBENV_COMMAND"/*.bash) shopt -u nullglob for script in ${SCRIPTS[@]}; do From 096743acde3ff83e430ecc0b5c5fde1aa99163fc Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Wed, 21 Sep 2011 13:00:23 -0500 Subject: [PATCH 143/384] Add support for RBENV_PLUGIN_PATH environment variable --- libexec/rbenv | 3 +++ libexec/rbenv-plugin-scripts | 10 +++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/libexec/rbenv b/libexec/rbenv index 0a9d0122..aab66512 100755 --- a/libexec/rbenv +++ b/libexec/rbenv @@ -27,6 +27,9 @@ else fi export RBENV_ROOT + +export RBENV_PLUGIN_PATH="${RBENV_PLUGIN_PATH}:/etc/rbenv.d:${RBENV_ROOT}/rbenv.d" + libexec_path="$(abs_dirname "$0")" export PATH="${libexec_path}:${PATH}" diff --git a/libexec/rbenv-plugin-scripts b/libexec/rbenv-plugin-scripts index 27568007..af9648ed 100755 --- a/libexec/rbenv-plugin-scripts +++ b/libexec/rbenv-plugin-scripts @@ -17,9 +17,9 @@ if [ -z "$RBENV_COMMAND" ]; then fi shopt -s nullglob -SCRIPTS=(/etc/rbenv.d/"$RBENV_COMMAND"/*.bash ${RBENV_ROOT}/rbenv.d/"$RBENV_COMMAND"/*.bash) -shopt -u nullglob - -for script in ${SCRIPTS[@]}; do - echo $script +for path in ${RBENV_PLUGIN_PATH//:/$'\n'}; do + for script in $path/"$RBENV_COMMAND"/*.bash; do + echo $script + done done +shopt -u nullglob From 699cd8c2031561447e20b0163217ed3f9ae185a1 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Wed, 21 Sep 2011 13:05:08 -0500 Subject: [PATCH 144/384] Quote script path and remove unnecessary semicolon --- libexec/rbenv-exec | 2 +- libexec/rbenv-rehash | 2 +- libexec/rbenv-which | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libexec/rbenv-exec b/libexec/rbenv-exec index d940a7a3..892e17a9 100755 --- a/libexec/rbenv-exec +++ b/libexec/rbenv-exec @@ -17,7 +17,7 @@ RBENV_COMMAND_PATH="$(rbenv-which "$RBENV_COMMAND")" RBENV_BIN_PATH="${RBENV_COMMAND_PATH%/*}" for script in $(rbenv-plugin-scripts exec); do - source $script; + source "$script" done shift 1 diff --git a/libexec/rbenv-rehash b/libexec/rbenv-rehash index a11b64bd..ca83c54b 100755 --- a/libexec/rbenv-rehash +++ b/libexec/rbenv-rehash @@ -71,5 +71,5 @@ make_shims ../versions/*/bin/* cd "$CUR_PATH" for script in $(rbenv-plugin-scripts rehash); do - source $script; + source "$script" done diff --git a/libexec/rbenv-which b/libexec/rbenv-which index a47badd3..d22a91eb 100755 --- a/libexec/rbenv-which +++ b/libexec/rbenv-which @@ -53,7 +53,7 @@ else fi for script in $(rbenv-plugin-scripts which); do - source $script; + source "$script" done if [ -x "$RBENV_COMMAND_PATH" ]; then From a238099e381a3c359683fcd49f51a266a9fafaa9 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Thu, 22 Sep 2011 19:08:03 -0500 Subject: [PATCH 145/384] Include /usr/local/etc hooks --- libexec/rbenv | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libexec/rbenv b/libexec/rbenv index aab66512..8c298493 100755 --- a/libexec/rbenv +++ b/libexec/rbenv @@ -28,7 +28,7 @@ fi export RBENV_ROOT -export RBENV_PLUGIN_PATH="${RBENV_PLUGIN_PATH}:/etc/rbenv.d:${RBENV_ROOT}/rbenv.d" +export RBENV_PLUGIN_PATH="${RBENV_PLUGIN_PATH}:${RBENV_ROOT}/rbenv.d:/usr/local/etc/rbenv.d:/etc/rbenv.d" libexec_path="$(abs_dirname "$0")" export PATH="${libexec_path}:${PATH}" From eae5e5e092b934f4583c41f1d93e7b7e3ff9e0aa Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Thu, 22 Sep 2011 19:15:00 -0500 Subject: [PATCH 146/384] realpath plugin scripts --- libexec/rbenv-plugin-scripts | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/libexec/rbenv-plugin-scripts b/libexec/rbenv-plugin-scripts index af9648ed..34d10809 100755 --- a/libexec/rbenv-plugin-scripts +++ b/libexec/rbenv-plugin-scripts @@ -16,10 +16,29 @@ if [ -z "$RBENV_COMMAND" ]; then exit 1 fi +resolve_link() { + $(type -p greadlink readlink | head -1) $1 +} + +realpath() { + local cwd="$(pwd)" + local base="$(basename $1)" + local path="$1" + + while [ -n "$path" ]; do + cd "${path%/*}" + local name="${path##*/}" + path="$(resolve_link "$name" || true)" + done + + echo "$(pwd)/$base" + cd "$cwd" +} + shopt -s nullglob for path in ${RBENV_PLUGIN_PATH//:/$'\n'}; do for script in $path/"$RBENV_COMMAND"/*.bash; do - echo $script + echo $(realpath $script) done done shopt -u nullglob From f9fb3c934e2242d82e67e173162f1dfde792fa65 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Fri, 23 Sep 2011 10:43:06 -0500 Subject: [PATCH 147/384] rbenv-plugin-scripts -> rbenv-hooks; RBENV_PLUGIN_PATH -> RBENV_HOOK_PATH --- libexec/rbenv | 2 +- libexec/rbenv-exec | 2 +- libexec/{rbenv-plugin-scripts => rbenv-hooks} | 4 ++-- libexec/rbenv-rehash | 2 +- libexec/rbenv-which | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) rename libexec/{rbenv-plugin-scripts => rbenv-hooks} (87%) diff --git a/libexec/rbenv b/libexec/rbenv index 8c298493..6fd6d7e4 100755 --- a/libexec/rbenv +++ b/libexec/rbenv @@ -28,7 +28,7 @@ fi export RBENV_ROOT -export RBENV_PLUGIN_PATH="${RBENV_PLUGIN_PATH}:${RBENV_ROOT}/rbenv.d:/usr/local/etc/rbenv.d:/etc/rbenv.d" +export RBENV_HOOK_PATH="${RBENV_HOOK_PATH}:${RBENV_ROOT}/rbenv.d:/usr/local/etc/rbenv.d:/etc/rbenv.d" libexec_path="$(abs_dirname "$0")" export PATH="${libexec_path}:${PATH}" diff --git a/libexec/rbenv-exec b/libexec/rbenv-exec index 892e17a9..92ecb72b 100755 --- a/libexec/rbenv-exec +++ b/libexec/rbenv-exec @@ -16,7 +16,7 @@ fi RBENV_COMMAND_PATH="$(rbenv-which "$RBENV_COMMAND")" RBENV_BIN_PATH="${RBENV_COMMAND_PATH%/*}" -for script in $(rbenv-plugin-scripts exec); do +for script in $(rbenv-hooks exec); do source "$script" done diff --git a/libexec/rbenv-plugin-scripts b/libexec/rbenv-hooks similarity index 87% rename from libexec/rbenv-plugin-scripts rename to libexec/rbenv-hooks index 34d10809..47ee910a 100755 --- a/libexec/rbenv-plugin-scripts +++ b/libexec/rbenv-hooks @@ -12,7 +12,7 @@ fi RBENV_COMMAND="$1" if [ -z "$RBENV_COMMAND" ]; then - echo "usage: rbenv plugin-scripts COMMAND" >&2 + echo "usage: rbenv hooks COMMAND" >&2 exit 1 fi @@ -36,7 +36,7 @@ realpath() { } shopt -s nullglob -for path in ${RBENV_PLUGIN_PATH//:/$'\n'}; do +for path in ${RBENV_HOOK_PATH//:/$'\n'}; do for script in $path/"$RBENV_COMMAND"/*.bash; do echo $(realpath $script) done diff --git a/libexec/rbenv-rehash b/libexec/rbenv-rehash index ca83c54b..cb7713ef 100755 --- a/libexec/rbenv-rehash +++ b/libexec/rbenv-rehash @@ -70,6 +70,6 @@ make_shims ../versions/*/bin/* # Restore the previous working directory. cd "$CUR_PATH" -for script in $(rbenv-plugin-scripts rehash); do +for script in $(rbenv-hooks rehash); do source "$script" done diff --git a/libexec/rbenv-which b/libexec/rbenv-which index d22a91eb..768e8451 100755 --- a/libexec/rbenv-which +++ b/libexec/rbenv-which @@ -52,7 +52,7 @@ else RBENV_COMMAND_PATH="${RBENV_ROOT}/versions/${RBENV_VERSION}/bin/${RBENV_COMMAND}" fi -for script in $(rbenv-plugin-scripts which); do +for script in $(rbenv-hooks which); do source "$script" done From 8ce5e84c218f715c05961b4b6d772a6865e1a2a4 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Fri, 23 Sep 2011 10:44:00 -0500 Subject: [PATCH 148/384] Automatically add ${RBENV_ROOT}/plugins/*/bin to $PATH --- libexec/rbenv | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/libexec/rbenv b/libexec/rbenv index 6fd6d7e4..5d087860 100755 --- a/libexec/rbenv +++ b/libexec/rbenv @@ -30,8 +30,16 @@ export RBENV_ROOT export RBENV_HOOK_PATH="${RBENV_HOOK_PATH}:${RBENV_ROOT}/rbenv.d:/usr/local/etc/rbenv.d:/etc/rbenv.d" -libexec_path="$(abs_dirname "$0")" -export PATH="${libexec_path}:${PATH}" + +shopt -s nullglob +rbenv_path="$(abs_dirname "$0")" +for plugin_bin in "${RBENV_ROOT}/plugins/"*/bin; do + rbenv_path="${rbenv_path}:${plugin_bin}" +done +shopt -u nullglob + +export PATH="${rbenv_path}:${PATH}" + command="$1" case "$command" in From 10084ae020704f8f364c72461f44b24ffab66534 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Fri, 23 Sep 2011 10:47:45 -0500 Subject: [PATCH 149/384] Automatically add ${RBENV_ROOT}/plugins/*/etc/rbenv.d to $RBENV_HOOK_PATH --- libexec/rbenv | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/libexec/rbenv b/libexec/rbenv index 5d087860..2c00d7d7 100755 --- a/libexec/rbenv +++ b/libexec/rbenv @@ -28,17 +28,21 @@ fi export RBENV_ROOT -export RBENV_HOOK_PATH="${RBENV_HOOK_PATH}:${RBENV_ROOT}/rbenv.d:/usr/local/etc/rbenv.d:/etc/rbenv.d" - - shopt -s nullglob -rbenv_path="$(abs_dirname "$0")" -for plugin_bin in "${RBENV_ROOT}/plugins/"*/bin; do - rbenv_path="${rbenv_path}:${plugin_bin}" -done -shopt -u nullglob -export PATH="${rbenv_path}:${PATH}" +bin_path="$(abs_dirname "$0")" +for plugin_bin in "${RBENV_ROOT}/plugins/"*/bin; do + bin_path="${bin_path}:${plugin_bin}" +done +export PATH="${bin_path}:${PATH}" + +hook_path="${RBENV_HOOK_PATH}:${RBENV_ROOT}/rbenv.d:/usr/local/etc/rbenv.d:/etc/rbenv.d" +for plugin_hook in "${RBENV_ROOT}/plugins/"*/etc/rbenv.d; do + hook_path="${hook_path}:${plugin_hook}" +done +export RBENV_HOOK_PATH="$hook_path" + +shopt -u nullglob command="$1" From 07815769aeda3097f43d032fb31f6c89d1a7942f Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Tue, 27 Sep 2011 15:50:39 -0500 Subject: [PATCH 150/384] RBENV_DIR sets the directory from which .rbenv-version files are scanned --- bin/ruby-local-exec | 9 +++------ libexec/rbenv | 5 +++++ libexec/rbenv-version-file | 2 +- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/bin/ruby-local-exec b/bin/ruby-local-exec index af7d7e1a..b1b5a5fa 100755 --- a/bin/ruby-local-exec +++ b/bin/ruby-local-exec @@ -13,11 +13,8 @@ set -e -cwd="$(pwd)" -dirname="${1%/*}" - -cd "$dirname" -export RBENV_VERSION="$(rbenv version-name)" -cd "$cwd" +if [ -z "$RBENV_DIR" ]; then + export RBENV_DIR="${1%/*}" +fi exec ruby "$@" diff --git a/libexec/rbenv b/libexec/rbenv index 2c00d7d7..f6b07b92 100755 --- a/libexec/rbenv +++ b/libexec/rbenv @@ -27,6 +27,11 @@ else fi export RBENV_ROOT +if [ -z "${RBENV_DIR}" ]; then + RBENV_DIR="$(pwd)" +fi +export RBENV_DIR + shopt -s nullglob diff --git a/libexec/rbenv-version-file b/libexec/rbenv-version-file index eb72ec38..31b8670d 100755 --- a/libexec/rbenv-version-file +++ b/libexec/rbenv-version-file @@ -2,7 +2,7 @@ set -e [ -n "$RBENV_DEBUG" ] && set -x -root="$(pwd)" +root="$RBENV_DIR" while [ -n "$root" ]; do if [ -e "${root}/.rbenv-version" ]; then echo "${root}/.rbenv-version" From 65bf6279faec5b97bef81f2240f15372d7ba3321 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Tue, 27 Sep 2011 15:53:08 -0500 Subject: [PATCH 151/384] Always set RBENV_DIR in ruby-local-exec --- bin/ruby-local-exec | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/bin/ruby-local-exec b/bin/ruby-local-exec index b1b5a5fa..a2064370 100755 --- a/bin/ruby-local-exec +++ b/bin/ruby-local-exec @@ -12,9 +12,5 @@ # `cd` into the project first. set -e - -if [ -z "$RBENV_DIR" ]; then - export RBENV_DIR="${1%/*}" -fi - +export RBENV_DIR="${1%/*}" exec ruby "$@" From 0a4ffcd15f6d02f9c707af008d9c2542dc1f864d Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Wed, 28 Sep 2011 09:45:58 -0500 Subject: [PATCH 152/384] Global version file is now `${RBENV_ROOT}/version` This is the last time it'll change. Promise. --- .gitignore | 4 ++-- libexec/rbenv-global | 3 ++- libexec/rbenv-version-file | 15 ++++++++------- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index 5be802e6..c74d07f5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ -/versions /shims -/global +/version +/versions diff --git a/libexec/rbenv-global b/libexec/rbenv-global index 0c239fd1..2f68f2ec 100755 --- a/libexec/rbenv-global +++ b/libexec/rbenv-global @@ -9,12 +9,13 @@ if [ "$1" = "--complete" ]; then fi RBENV_VERSION="$1" -RBENV_VERSION_FILE="${RBENV_ROOT}/global" +RBENV_VERSION_FILE="${RBENV_ROOT}/version" if [ -n "$RBENV_VERSION" ]; then rbenv-version-file-write "$RBENV_VERSION_FILE" "$RBENV_VERSION" else rbenv-version-file-read "$RBENV_VERSION_FILE" || + rbenv-version-file-read "${RBENV_ROOT}/global" || rbenv-version-file-read "${RBENV_ROOT}/default" || echo system fi diff --git a/libexec/rbenv-version-file b/libexec/rbenv-version-file index 31b8670d..9b678769 100755 --- a/libexec/rbenv-version-file +++ b/libexec/rbenv-version-file @@ -11,13 +11,14 @@ while [ -n "$root" ]; do root="${root%/*}" done -GLOBAL_PATH="${RBENV_ROOT}/global" -DEFAULT_PATH="${RBENV_ROOT}/default" +global_version_file="${RBENV_ROOT}/version" -if [ -e "$GLOBAL_PATH" ]; then - echo "$GLOBAL_PATH" -elif [ -e "$DEFAULT_PATH" ]; then - echo "$DEFAULT_PATH" +if [ -e "$global_version_file" ]; then + echo "$global_version_file" +elif [ -e "${RBENV_ROOT}/global" ]; then + echo "${RBENV_ROOT}/global" +elif [ -e "${RBENV_ROOT}/default" ]; then + echo "${RBENV_ROOT}/default" else - echo "$GLOBAL_PATH" + echo "$global_version_file" fi From c954d5755583089033e4086405ee14d31ee7755f Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Wed, 28 Sep 2011 09:46:17 -0500 Subject: [PATCH 153/384] Add /plugins to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index c74d07f5..7e2eb978 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +/plugins /shims /version /versions From a3d3005859c59e50d5d20ec9f9696bbde322d714 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Wed, 28 Sep 2011 10:13:28 -0500 Subject: [PATCH 154/384] Document `rbenv shell` --- README.md | 63 ++++++++++++++++++++++++++++++++++++------------ doc/README.mdtoc | 54 ++++++++++++++++++++++++++++++++--------- 2 files changed, 91 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 4e57fd06..31c26474 100644 --- a/README.md +++ b/README.md @@ -42,11 +42,12 @@ tools that do one thing well. * [1 How It Works](#section_1) * [2 Installation](#section_2) * [3 Usage](#section_3) - * [3.1 global](#section_3.1) - * [3.2 local](#section_3.2) - * [3.3 versions](#section_3.3) - * [3.4 version](#section_3.4) - * [3.5 rehash](#section_3.5) + * [3.1 rbenv global](#section_3.1) + * [3.2 rbenv local](#section_3.2) + * [3.3 rbenv shell](#section_3.3) + * [3.4 rbenv versions](#section_3.4) + * [3.5 rbenv version](#section_3.5) + * [3.6 rbenv rehash](#section_3.6) * [4 Contributing](#section_4) * [4.1 License](#section_4.1) @@ -89,15 +90,23 @@ command-line utility. $ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> .bash_profile +zsh users should add this line to `.zshrc` instead: + + $ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> .zshrc + 3. Add rbenv's shims directory to your `$PATH` and set up Bash autocompletion. (If you prefer not to load rbenv in your shell, you can manually add `$HOME/.rbenv/shims` to your path in step 2.) $ echo 'eval "$(rbenv init -)"' >> .bash_profile +zsh users should add this line to `.zshrc` instead: + + $ echo 'eval "$(rbenv init -)"' >> .zshrc + 4. Restart your shell. You can now begin using rbenv. - $ exec + $ exec $SHELL 5. Install Ruby versions into `~/.rbenv/versions`. For example, to install Ruby 1.9.2-p290, download and unpack the source, then run: @@ -107,7 +116,8 @@ install Ruby 1.9.2-p290, download and unpack the source, then run: $ make install The [ruby-build](https://github.com/sstephenson/ruby-build) - project simplifies this process to a single command: + provides an `rbenv install` command that simplifies the process of + installing new Ruby versions to: $ rbenv install 1.9.2-p290 @@ -122,10 +132,10 @@ when installing a gem that provides a binary). Like `git`, the `rbenv` command delegates to subcommands based on its first argument. The most common subcommands are: -### 3.1 global +### 3.1 rbenv global Sets the global version of Ruby to be used in all shells by writing -the version name to the `~/.rbenv/global` file. This version can be +the version name to the `~/.rbenv/version` file. This version can be overridden by a per-project `.rbenv-version` file, or by setting the `RBENV_VERSION` environment variable. @@ -137,19 +147,42 @@ The special version name `system` tells rbenv to use the system Ruby When run without a version number, `rbenv global` reports the currently configured global version. -### 3.2 local +### 3.2 rbenv local Sets a local per-project Ruby version by writing the version name to an `.rbenv-version` file in the current directory. This version overrides the global, and can be overridden itself by setting the -`RBENV_VERSION` environment variable. +`RBENV_VERSION` environment variable or with the `rbenv shell` +command. $ rbenv local rbx-1.2.4 When run without a version number, `rbenv local` reports the currently -configured local version. +configured local version. You can also unset the local version: -### 3.3 versions + $ rbenv local --unset + +### 3.3 rbenv shell + +Sets a shell-specific Ruby version by setting the `RBENV_VERSION` +environment variable in your shell. This version overrides both +project-specific versions and the global version. + + $ rbenv shell jruby-1.6.3 + +When run without a version number, `rbenv shell` reports the current +value of `RBENV_VERSION`. You can also unset the shell version: + + $ rbenv shell --unset + +Note that you'll need rbenv's shell integration enabled (step 3 of +the installation instructions) in order to use this command. If you +prefer not to use shell integration, you may simply set the +`RBENV_VERSION` variable yourself: + + $ export RBENV_VERSION=jruby-1.6.3 + +### 3.4 rbenv versions Lists all Ruby versions known to rbenv, and shows an asterisk next to the currently active version. @@ -162,7 +195,7 @@ the currently active version. rbx-1.2.4 ree-1.8.7-2011.03 -### 3.4 version +### 3.5 rbenv version Displays the currently active Ruby version, along with information on how it was set. @@ -170,7 +203,7 @@ how it was set. $ rbenv version 1.8.7-p352 (set by /Volumes/37signals/basecamp/.rbenv-version) -### 3.5 rehash +### 3.6 rbenv rehash Installs shims for all Ruby binaries known to rbenv (i.e., `~/.rbenv/versions/*/bin/*`). Run this command after you install a new diff --git a/doc/README.mdtoc b/doc/README.mdtoc index 1da7969b..d75bdd1f 100644 --- a/doc/README.mdtoc +++ b/doc/README.mdtoc @@ -78,15 +78,23 @@ command-line utility. $ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> .bash_profile +zsh users should add this line to `.zshrc` instead: + + $ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> .zshrc + 3. Add rbenv's shims directory to your `$PATH` and set up Bash autocompletion. (If you prefer not to load rbenv in your shell, you can manually add `$HOME/.rbenv/shims` to your path in step 2.) $ echo 'eval "$(rbenv init -)"' >> .bash_profile +zsh users should add this line to `.zshrc` instead: + + $ echo 'eval "$(rbenv init -)"' >> .zshrc + 4. Restart your shell. You can now begin using rbenv. - $ exec + $ exec $SHELL 5. Install Ruby versions into `~/.rbenv/versions`. For example, to install Ruby 1.9.2-p290, download and unpack the source, then run: @@ -96,9 +104,10 @@ install Ruby 1.9.2-p290, download and unpack the source, then run: $ make install The [ruby-build](https://github.com/sstephenson/ruby-build) - project simplifies this process to a single command: + provides an `rbenv install` command that simplifies the process of + installing new Ruby versions to: - $ ruby-build 1.9.2-p290 $HOME/.rbenv/versions/1.9.2-p290 + $ rbenv install 1.9.2-p290 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 @@ -111,10 +120,10 @@ when installing a gem that provides a binary). Like `git`, the `rbenv` command delegates to subcommands based on its first argument. The most common subcommands are: -### global ### +### rbenv global ### Sets the global version of Ruby to be used in all shells by writing -the version name to the `~/.rbenv/global` file. This version can be +the version name to the `~/.rbenv/version` file. This version can be overridden by a per-project `.rbenv-version` file, or by setting the `RBENV_VERSION` environment variable. @@ -126,19 +135,42 @@ The special version name `system` tells rbenv to use the system Ruby When run without a version number, `rbenv global` reports the currently configured global version. -### local ### +### rbenv local ### Sets a local per-project Ruby version by writing the version name to an `.rbenv-version` file in the current directory. This version overrides the global, and can be overridden itself by setting the -`RBENV_VERSION` environment variable. +`RBENV_VERSION` environment variable or with the `rbenv shell` +command. $ rbenv local rbx-1.2.4 When run without a version number, `rbenv local` reports the currently -configured local version. +configured local version. You can also unset the local version: -### versions ### + $ rbenv local --unset + +### rbenv shell ### + +Sets a shell-specific Ruby version by setting the `RBENV_VERSION` +environment variable in your shell. This version overrides both +project-specific versions and the global version. + + $ rbenv shell jruby-1.6.3 + +When run without a version number, `rbenv shell` reports the current +value of `RBENV_VERSION`. You can also unset the shell version: + + $ rbenv shell --unset + +Note that you'll need rbenv's shell integration enabled (step 3 of +the installation instructions) in order to use this command. If you +prefer not to use shell integration, you may simply set the +`RBENV_VERSION` variable yourself: + + $ export RBENV_VERSION=jruby-1.6.3 + +### rbenv versions ### Lists all Ruby versions known to rbenv, and shows an asterisk next to the currently active version. @@ -151,7 +183,7 @@ the currently active version. rbx-1.2.4 ree-1.8.7-2011.03 -### version ### +### rbenv version ### Displays the currently active Ruby version, along with information on how it was set. @@ -159,7 +191,7 @@ how it was set. $ rbenv version 1.8.7-p352 (set by /Volumes/37signals/basecamp/.rbenv-version) -### rehash ### +### rbenv rehash ### Installs shims for all Ruby binaries known to rbenv (i.e., `~/.rbenv/versions/*/bin/*`). Run this command after you install a new From 058e2cb7a65020f758fc46c6a681914e47a4152a Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Wed, 28 Sep 2011 10:21:57 -0500 Subject: [PATCH 155/384] Add `rbenv shell` to help --- libexec/rbenv-help | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/libexec/rbenv-help b/libexec/rbenv-help index 7d941360..d0ead2c4 100755 --- a/libexec/rbenv-help +++ b/libexec/rbenv-help @@ -25,6 +25,7 @@ Some useful rbenv commands are: rehash Rehash rbenv shims (run this after installing binaries) global Set or show the global Ruby version local Set or show the local directory-specific Ruby version + shell Set or show the shell-specific Ruby version version Show the current Ruby version versions List all Ruby versions known by rbenv @@ -40,6 +41,7 @@ or by setting the RBENV_VERSION environment variable. $(print_set_version)" ;; local) echo "usage: rbenv local + rbenv local --unset Sets the local directory-specific Ruby version by writing the version name to a file named '.rbenv-version'. @@ -50,6 +52,15 @@ file is found in the tree, rbenv will use the global Ruby version specified with \`rbenv global', or the version specified in the RBENV_VERSION environment variable. +$(print_set_version)" +;; +shell) echo "usage: rbenv shell + rbenv shell --unset + +Sets a shell-specific Ruby version by setting the 'RBENV_VERSION' +environment variable in your shell. This version overrides both +project-specific versions and the global version. + $(print_set_version)" ;; *) echo "No command arguments needed or invalid/undocumented command." From ada26ab92e52b87f978be8b4744355a3c8821444 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Wed, 28 Sep 2011 10:48:04 -0500 Subject: [PATCH 156/384] Document `rbenv which` and `rbenv whence` --- README.md | 34 +++++++++++++++++++++++++++------- doc/README.mdtoc | 32 +++++++++++++++++++++++++------- libexec/rbenv-help | 13 ++++++++++++- 3 files changed, 64 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 31c26474..a72c14fb 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,8 @@ tools that do one thing well. * [3.4 rbenv versions](#section_3.4) * [3.5 rbenv version](#section_3.5) * [3.6 rbenv rehash](#section_3.6) + * [3.7 rbenv which](#section_3.7) + * [3.8 rbenv whence](#section_3.8) * [4 Contributing](#section_4) * [4.1 License](#section_4.1) @@ -56,11 +58,11 @@ tools that do one thing well. rbenv operates on the per-user directory `~/.rbenv`. Version names in rbenv correspond to subdirectories of `~/.rbenv/versions`. For example, you might have `~/.rbenv/versions/1.8.7-p354` and -`~/.rbenv/versions/1.9.3-preview1`. +`~/.rbenv/versions/1.9.3-rc1`. Each version is a working tree with its own binaries, like `~/.rbenv/versions/1.8.7-p354/bin/ruby` and -`~/.rbenv/versions/1.9.3-preview1/irb`. rbenv makes _shim binaries_ +`~/.rbenv/versions/1.9.3-rc1/bin/irb`. rbenv makes _shim binaries_ for every such binary across all installed versions of Ruby. These shims are simple wrapper scripts that live in `~/.rbenv/shims` @@ -104,7 +106,8 @@ zsh users should add this line to `.zshrc` instead: $ echo 'eval "$(rbenv init -)"' >> .zshrc -4. Restart your shell. You can now begin using rbenv. +4. Restart your shell so the path changes take effect. You can now +begin using rbenv. $ exec $SHELL @@ -168,7 +171,7 @@ Sets a shell-specific Ruby version by setting the `RBENV_VERSION` environment variable in your shell. This version overrides both project-specific versions and the global version. - $ rbenv shell jruby-1.6.3 + $ rbenv shell jruby-1.6.4 When run without a version number, `rbenv shell` reports the current value of `RBENV_VERSION`. You can also unset the shell version: @@ -180,7 +183,7 @@ the installation instructions) in order to use this command. If you prefer not to use shell integration, you may simply set the `RBENV_VERSION` variable yourself: - $ export RBENV_VERSION=jruby-1.6.3 + $ export RBENV_VERSION=jruby-1.6.4 ### 3.4 rbenv versions @@ -190,8 +193,8 @@ the currently active version. $ rbenv versions 1.8.7-p352 1.9.2-p290 - * 1.9.3-preview1 (set by /Users/sam/.rbenv/global) - jruby-1.6.3 + * 1.9.3-rc1 (set by /Users/sam/.rbenv/global) + jruby-1.6.4 rbx-1.2.4 ree-1.8.7-2011.03 @@ -211,6 +214,23 @@ version of Ruby, or install a gem that provides binaries. $ rbenv rehash +### 3.7 rbenv which + +Displays the full path to the binary that rbenv will execute when you +run the given command. + + $ rbenv which irb + /Users/sam/.rbenv/versions/1.9.2-p290/bin/irb + +### 3.8 rbenv whence + +Lists all Ruby versions with the given command installed. + + $ rbenv whence rackup + 1.9.3-rc1 + jruby-1.6.4 + ree-1.8.7-2011.03 + ## 4 Contributing The rbenv source code is [hosted on diff --git a/doc/README.mdtoc b/doc/README.mdtoc index d75bdd1f..956e3147 100644 --- a/doc/README.mdtoc +++ b/doc/README.mdtoc @@ -44,11 +44,11 @@ tools that do one thing well. rbenv operates on the per-user directory `~/.rbenv`. Version names in rbenv correspond to subdirectories of `~/.rbenv/versions`. For example, you might have `~/.rbenv/versions/1.8.7-p354` and -`~/.rbenv/versions/1.9.3-preview1`. +`~/.rbenv/versions/1.9.3-rc1`. Each version is a working tree with its own binaries, like `~/.rbenv/versions/1.8.7-p354/bin/ruby` and -`~/.rbenv/versions/1.9.3-preview1/irb`. rbenv makes _shim binaries_ +`~/.rbenv/versions/1.9.3-rc1/bin/irb`. rbenv makes _shim binaries_ for every such binary across all installed versions of Ruby. These shims are simple wrapper scripts that live in `~/.rbenv/shims` @@ -92,7 +92,8 @@ zsh users should add this line to `.zshrc` instead: $ echo 'eval "$(rbenv init -)"' >> .zshrc -4. Restart your shell. You can now begin using rbenv. +4. Restart your shell so the path changes take effect. You can now +begin using rbenv. $ exec $SHELL @@ -156,7 +157,7 @@ Sets a shell-specific Ruby version by setting the `RBENV_VERSION` environment variable in your shell. This version overrides both project-specific versions and the global version. - $ rbenv shell jruby-1.6.3 + $ rbenv shell jruby-1.6.4 When run without a version number, `rbenv shell` reports the current value of `RBENV_VERSION`. You can also unset the shell version: @@ -168,7 +169,7 @@ the installation instructions) in order to use this command. If you prefer not to use shell integration, you may simply set the `RBENV_VERSION` variable yourself: - $ export RBENV_VERSION=jruby-1.6.3 + $ export RBENV_VERSION=jruby-1.6.4 ### rbenv versions ### @@ -178,8 +179,8 @@ the currently active version. $ rbenv versions 1.8.7-p352 1.9.2-p290 - * 1.9.3-preview1 (set by /Users/sam/.rbenv/global) - jruby-1.6.3 + * 1.9.3-rc1 (set by /Users/sam/.rbenv/global) + jruby-1.6.4 rbx-1.2.4 ree-1.8.7-2011.03 @@ -199,6 +200,23 @@ version of Ruby, or install a gem that provides binaries. $ rbenv rehash +### rbenv which ### + +Displays the full path to the binary that rbenv will execute when you +run the given command. + + $ rbenv which irb + /Users/sam/.rbenv/versions/1.9.2-p290/bin/irb + +### rbenv whence ### + +Lists all Ruby versions with the given command installed. + + $ rbenv whence rackup + 1.9.3-rc1 + jruby-1.6.4 + ree-1.8.7-2011.03 + ## Contributing ## The rbenv source code is [hosted on diff --git a/libexec/rbenv-help b/libexec/rbenv-help index d0ead2c4..ff0a1d7b 100755 --- a/libexec/rbenv-help +++ b/libexec/rbenv-help @@ -21,13 +21,15 @@ case "$1" in "") echo "usage: rbenv [] Some useful rbenv commands are: - commands List all commands + commands List all rbenv commands rehash Rehash rbenv shims (run this after installing binaries) global Set or show the global Ruby version local Set or show the local directory-specific Ruby version shell Set or show the shell-specific Ruby version version Show the current Ruby version versions List all Ruby versions known by rbenv + which Show the full path for the given Ruby command + whence List all Ruby versions with the given command See 'rbenv help ' for more information on a specific command. For more information, see: https://github.com/sstephenson/rbenv#readme" @@ -63,5 +65,14 @@ project-specific versions and the global version. $(print_set_version)" ;; +which) echo "usage: rbenv which + +Displays the full path to the binary that rbenv will execute when you +run the given command." +;; +whence) echo "usage: rbenv whence + +Lists all Ruby versions with the given command installed." +;; *) echo "No command arguments needed or invalid/undocumented command." esac From 09d912895f601ae38492c142cb684c8733e81b84 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Wed, 28 Sep 2011 10:51:09 -0500 Subject: [PATCH 157/384] Fix markdown indentation --- README.md | 4 ++-- doc/README.mdtoc | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index a72c14fb..69466b18 100644 --- a/README.md +++ b/README.md @@ -92,7 +92,7 @@ command-line utility. $ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> .bash_profile -zsh users should add this line to `.zshrc` instead: + zsh users should add this line to `.zshrc` instead: $ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> .zshrc @@ -102,7 +102,7 @@ can manually add `$HOME/.rbenv/shims` to your path in step 2.) $ echo 'eval "$(rbenv init -)"' >> .bash_profile -zsh users should add this line to `.zshrc` instead: + zsh users should add this line to `.zshrc` instead: $ echo 'eval "$(rbenv init -)"' >> .zshrc diff --git a/doc/README.mdtoc b/doc/README.mdtoc index 956e3147..304026b3 100644 --- a/doc/README.mdtoc +++ b/doc/README.mdtoc @@ -78,7 +78,7 @@ command-line utility. $ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> .bash_profile -zsh users should add this line to `.zshrc` instead: + zsh users should add this line to `.zshrc` instead: $ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> .zshrc @@ -88,7 +88,7 @@ can manually add `$HOME/.rbenv/shims` to your path in step 2.) $ echo 'eval "$(rbenv init -)"' >> .bash_profile -zsh users should add this line to `.zshrc` instead: + zsh users should add this line to `.zshrc` instead: $ echo 'eval "$(rbenv init -)"' >> .zshrc From 72b62e13aa43fb8252fde133ad9a692f13917df9 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Wed, 28 Sep 2011 10:59:02 -0500 Subject: [PATCH 158/384] Make `rbenv help` a little nicer --- libexec/rbenv-help | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/libexec/rbenv-help b/libexec/rbenv-help index ff0a1d7b..7204b2a1 100755 --- a/libexec/rbenv-help +++ b/libexec/rbenv-help @@ -31,8 +31,8 @@ Some useful rbenv commands are: which Show the full path for the given Ruby command whence List all Ruby versions with the given command -See 'rbenv help ' for more information on a specific command. -For more information, see: https://github.com/sstephenson/rbenv#readme" +See 'rbenv help ' for information on a specific command. +For full documentation, see: https://github.com/sstephenson/rbenv#readme" ;; global) echo "usage: rbenv global @@ -74,5 +74,15 @@ whence) echo "usage: rbenv whence Lists all Ruby versions with the given command installed." ;; -*) echo "No command arguments needed or invalid/undocumented command." +*) + command_path="$(command -v "rbenv-$1" || true)" + if [ -n "$command_path" ]; then + echo "Sorry, the \`$1' command isn't documented yet." + echo + echo "You can view the command's source here:" + echo "$command_path" + echo + else + echo "rbenv: no such command \`$1'" + fi esac From 26a08c6d12a08efad924135f8ed53ca6a46e5a54 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Wed, 28 Sep 2011 11:20:15 -0500 Subject: [PATCH 159/384] Add upgrade instructions --- doc/README.mdtoc | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/doc/README.mdtoc b/doc/README.mdtoc index 304026b3..9fb2e791 100644 --- a/doc/README.mdtoc +++ b/doc/README.mdtoc @@ -116,6 +116,28 @@ when installing a gem that provides a binary). $ rbenv rehash +### Upgrading an existing installation ### + +If you've installed rbenv using the instructions above, you can +upgrade your installation at any time using git. + +To upgrade to the latest development version of rbenv, use `git pull`: + + $ cd ~/.rbenv + $ git pull + +To upgrade to a specific release of rbenv, check out the corresponding +tag: + + $ cd ~/.rbenv + $ git fetch + $ git tag + v0.1.0 + v0.1.1 + v0.1.2 + v0.2.0 + $ git checkout v0.2.0 + ## Usage ## Like `git`, the `rbenv` command delegates to subcommands based on its From 7ba843c5851319cb45f95b2e345c525c69170b7e Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Wed, 28 Sep 2011 11:20:36 -0500 Subject: [PATCH 160/384] Add upgrade instructions --- README.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/README.md b/README.md index 69466b18..c0fe53f7 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,7 @@ tools that do one thing well. * [1 How It Works](#section_1) * [2 Installation](#section_2) + * [2.1 Upgrading an existing installation](#section_2.1) * [3 Usage](#section_3) * [3.1 rbenv global](#section_3.1) * [3.2 rbenv local](#section_3.2) @@ -130,6 +131,28 @@ when installing a gem that provides a binary). $ rbenv rehash +### 2.1 Upgrading an existing installation + +If you've installed rbenv using the instructions above, you can +upgrade your installation at any time using git. + +To upgrade to the latest development version of rbenv, use `git pull`: + + $ cd ~/.rbenv + $ git pull + +To upgrade to a specific release of rbenv, check out the corresponding +tag: + + $ cd ~/.rbenv + $ git fetch + $ git tag + v0.1.0 + v0.1.1 + v0.1.2 + v0.2.0 + $ git checkout v0.2.0 + ## 3 Usage Like `git`, the `rbenv` command delegates to subcommands based on its From 4712db8eddd2b684fe958e2d465d72751a682008 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Wed, 28 Sep 2011 12:01:44 -0500 Subject: [PATCH 161/384] Add version history --- README.md | 60 ++++++++++++++++++++++++++++++++++++++++++++---- doc/README.mdtoc | 53 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 108 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index c0fe53f7..18ca6015 100644 --- a/README.md +++ b/README.md @@ -51,8 +51,9 @@ tools that do one thing well. * [3.6 rbenv rehash](#section_3.6) * [3.7 rbenv which](#section_3.7) * [3.8 rbenv whence](#section_3.8) - * [4 Contributing](#section_4) - * [4.1 License](#section_4.1) + * [4 Development](#section_4) + * [4.1 Version History](#section_4.1) + * [4.2 License](#section_4.2) ## 1 How It Works @@ -254,7 +255,7 @@ Lists all Ruby versions with the given command installed. jruby-1.6.4 ree-1.8.7-2011.03 -## 4 Contributing +## 4 Development The rbenv source code is [hosted on GitHub](https://github.com/sstephenson/rbenv). It's clean, modular, @@ -263,7 +264,58 @@ and easy to understand, even if you're not a shell hacker. Please feel free to submit pull requests and file bugs on the [issue tracker](https://github.com/sstephenson/rbenv/issues). -### 4.1 License +### 4.1 Version History + +**HEAD** + +* Renamed `rbenv set-default` to `rbenv global` and `rbenv set-local` + to `rbenv local`. The `set-` commands are deprecated and will be + removed in the next major release. +* rbenv now uses `greadlink` on Solaris. +* Added a `ruby-local-exec` command which can be used in shebangs in + place of `#!/usr/bin/env ruby` to properly set the project-specific + Ruby version regardless of current working directory. +* Fixed an issue with `rbenv rehash` when no binaries are present. +* Added support for `rbenv-sh-*` commands, which run inside the + current shell instead of in a child process. +* Added an `rbenv shell` command for conveniently setting the + `$RBENV_VERSION` environment variable. +* Added support for storing rbenv versions and shims in directories + other than `~/.rbenv` with the `$RBENV_ROOT` environment variable. +* Added support for debugging rbenv via `set -x` when the + `$RBENV_DEBUG` environment variable is set. +* Refactored the autocompletion system so that completions are now + built-in to each command and shared between bash and zsh. +* Added support for plugin bundles in `~/.rbenv/plugins` as documented + in [issue #102](https://github.com/sstephenson/rbenv/pull/102). +* Added `/usr/local/etc/rbenv.d` to the list of directories searched + for rbenv hooks. +* Added support for an `$RBENV_DIR` environment variable which + defaults to the current working directory for specifying where rbenv + searches for local version files. + +**0.1.2** (August 16, 2011) + +* Fixed rbenv to be more resilient against nonexistent entries in + `$PATH`. +* Made the `rbenv rehash` command operate atomically. +* Modified the `rbenv init` script to automatically run `rbenv + rehash` so that shims are recreated whenever a new shell is opened. +* Added initial support for zsh autocompletion. +* Removed the dependency on egrep for reading version files. + +**0.1.1** (August 14, 2011) + +* Fixed a syntax error in the `rbenv help` command. +* Removed `-e` from the shebang in favor of `set -e` at the top of + each file for compatibility with operating systems that do not + support more than one argument in the shebang. + +**0.1.0** (August 11, 2011) + +* Initial public release. + +### 4.2 License (The MIT license) diff --git a/doc/README.mdtoc b/doc/README.mdtoc index 9fb2e791..f693993b 100644 --- a/doc/README.mdtoc +++ b/doc/README.mdtoc @@ -239,7 +239,7 @@ Lists all Ruby versions with the given command installed. jruby-1.6.4 ree-1.8.7-2011.03 -## Contributing ## +## Development ## The rbenv source code is [hosted on GitHub](https://github.com/sstephenson/rbenv). It's clean, modular, @@ -248,6 +248,57 @@ and easy to understand, even if you're not a shell hacker. Please feel free to submit pull requests and file bugs on the [issue tracker](https://github.com/sstephenson/rbenv/issues). +### Version History ### + +**HEAD** + +* Renamed `rbenv set-default` to `rbenv global` and `rbenv set-local` + to `rbenv local`. The `set-` commands are deprecated and will be + removed in the next major release. +* rbenv now uses `greadlink` on Solaris. +* Added a `ruby-local-exec` command which can be used in shebangs in + place of `#!/usr/bin/env ruby` to properly set the project-specific + Ruby version regardless of current working directory. +* Fixed an issue with `rbenv rehash` when no binaries are present. +* Added support for `rbenv-sh-*` commands, which run inside the + current shell instead of in a child process. +* Added an `rbenv shell` command for conveniently setting the + `$RBENV_VERSION` environment variable. +* Added support for storing rbenv versions and shims in directories + other than `~/.rbenv` with the `$RBENV_ROOT` environment variable. +* Added support for debugging rbenv via `set -x` when the + `$RBENV_DEBUG` environment variable is set. +* Refactored the autocompletion system so that completions are now + built-in to each command and shared between bash and zsh. +* Added support for plugin bundles in `~/.rbenv/plugins` as documented + in [issue #102](https://github.com/sstephenson/rbenv/pull/102). +* Added `/usr/local/etc/rbenv.d` to the list of directories searched + for rbenv hooks. +* Added support for an `$RBENV_DIR` environment variable which + defaults to the current working directory for specifying where rbenv + searches for local version files. + +**0.1.2** (August 16, 2011) + +* Fixed rbenv to be more resilient against nonexistent entries in + `$PATH`. +* Made the `rbenv rehash` command operate atomically. +* Modified the `rbenv init` script to automatically run `rbenv + rehash` so that shims are recreated whenever a new shell is opened. +* Added initial support for zsh autocompletion. +* Removed the dependency on egrep for reading version files. + +**0.1.1** (August 14, 2011) + +* Fixed a syntax error in the `rbenv help` command. +* Removed `-e` from the shebang in favor of `set -e` at the top of + each file for compatibility with operating systems that do not + support more than one argument in the shebang. + +**0.1.0** (August 11, 2011) + +* Initial public release. + ### License ### (The MIT license) From 149e61a6496725e72d34ad3513e60872e4adb273 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Wed, 28 Sep 2011 12:06:53 -0500 Subject: [PATCH 162/384] Don't exit out of piped loop Can cause the stdin of cat to close too soon causing: echo: write error: Broken pipe Fixes #97 --- libexec/rbenv-version-file-read | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/libexec/rbenv-version-file-read b/libexec/rbenv-version-file-read index 8d27b0f0..9a3cd05b 100755 --- a/libexec/rbenv-version-file-read +++ b/libexec/rbenv-version-file-read @@ -7,13 +7,18 @@ VERSION_FILE="$1" if [ -e "$VERSION_FILE" ]; then # Read and print the first non-whitespace word from the specified # version file. + version="" while read -a words; do - version="${words[0]}" - if [ -n "$version" ]; then - echo "$version" - exit + word="${words[0]}" + if [ -z "$version" ] && [ -n "$word" ]; then + version="$word" fi done < <( cat "$VERSION_FILE" && echo ) + + if [ -n "$version" ]; then + echo "$version" + exit + fi fi exit 1 From 828051e65110d5917b41bceb3cfb5b4fd558199e Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Wed, 28 Sep 2011 12:08:08 -0500 Subject: [PATCH 163/384] Move intro line above the fold --- README.md | 4 ++-- doc/README.mdtoc | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 18ca6015..1469ba7d 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,11 @@ # Simple Ruby Version Management: rbenv - - rbenv lets you easily switch between multiple versions of Ruby. It's simple, unobtrusive, and follows the UNIX tradition of single-purpose tools that do one thing well. + + ### rbenv _does…_ * Let you **change the global Ruby version** on a per-user basis. diff --git a/doc/README.mdtoc b/doc/README.mdtoc index f693993b..69cb7fb1 100644 --- a/doc/README.mdtoc +++ b/doc/README.mdtoc @@ -1,11 +1,11 @@ # Simple Ruby Version Management: rbenv - - rbenv lets you easily switch between multiple versions of Ruby. It's simple, unobtrusive, and follows the UNIX tradition of single-purpose tools that do one thing well. + + ### rbenv _does…_ * Let you **change the global Ruby version** on a per-user basis. From 53d45707cab2ee894f1370d1f20b3f9a4fc64092 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Wed, 28 Sep 2011 12:19:36 -0500 Subject: [PATCH 164/384] Add Homebrew to the readme --- README.md | 15 +++++++++++++++ doc/README.mdtoc | 14 ++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/README.md b/README.md index 1469ba7d..9c4d56e0 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,7 @@ tools that do one thing well. * [1 How It Works](#section_1) * [2 Installation](#section_2) * [2.1 Upgrading an existing installation](#section_2.1) + * [2.2 Homebrew on Mac OS X](#section_2.2) * [3 Usage](#section_3) * [3.1 rbenv global](#section_3.1) * [3.2 rbenv local](#section_3.2) @@ -154,6 +155,20 @@ tag: v0.2.0 $ git checkout v0.2.0 +### 2.2 Homebrew on Mac OS X + +You can also install rbenv using the +[Homebrew](http://mxcl.github.com/homebrew/) package manager on Mac OS +X. + + $ brew update + $ brew install rbenv + +You'll need to add rbenv's shims directory to your path afterwards +(installation step 3 above). Follow the instructions above for +installing Ruby versions. (The ruby-build package can be installed +with Homebrew as well.) + ## 3 Usage Like `git`, the `rbenv` command delegates to subcommands based on its diff --git a/doc/README.mdtoc b/doc/README.mdtoc index 69cb7fb1..2f234ca2 100644 --- a/doc/README.mdtoc +++ b/doc/README.mdtoc @@ -138,6 +138,20 @@ tag: v0.2.0 $ git checkout v0.2.0 +### Homebrew on Mac OS X ### + +You can also install rbenv using the +[Homebrew](http://mxcl.github.com/homebrew/) package manager on Mac OS +X. + + $ brew update + $ brew install rbenv + +You'll need to add rbenv's shims directory to your path afterwards +(installation step 3 above). Follow the instructions above for +installing Ruby versions. (The ruby-build package can be installed +with Homebrew as well.) + ## Usage ## Like `git`, the `rbenv` command delegates to subcommands based on its From 88e59647aee0abe12cd1cd77d2dce6d33af8caef Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Wed, 28 Sep 2011 13:05:29 -0500 Subject: [PATCH 165/384] Installation edits --- README.md | 66 +++++++++++++++++++++++------------------------- doc/README.mdtoc | 65 +++++++++++++++++++++++------------------------ 2 files changed, 63 insertions(+), 68 deletions(-) diff --git a/README.md b/README.md index 9c4d56e0..027129f2 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,7 @@ tools that do one thing well. * [2 Installation](#section_2) * [2.1 Upgrading an existing installation](#section_2.1) * [2.2 Homebrew on Mac OS X](#section_2.2) + * [2.3 Neckbeard Configuration](#section_2.3) * [3 Usage](#section_3) * [3.1 rbenv global](#section_3.1) * [3.2 rbenv local](#section_3.2) @@ -78,58 +79,42 @@ rbenv is `~/.rbenv/shims` in your `$PATH`. ## 2 Installation -rbenv is a young project, so for now you must install it from source. +**Compatibility note**: rbenv is _incompatible_ with rvm. Things will appear to work until you try to install a gem. The problem is that rvm actually overrides the `gem` command with a shell function! Please remove any references to rvm before using rbenv. -**Compatibility note**: rbenv is _incompatible_ with rvm. Things will - appear to work until you try to install a gem. The problem is that - rvm actually overrides the `gem` command with a shell function! - Please remove any references to rvm before using rbenv. +### Basic GitHub checkout + +This will get you going with the latest version of rbenv and make it easy to fork and contribute any changes back upstream. 1. Check out rbenv into `~/.rbenv`. $ cd $ git clone git://github.com/sstephenson/rbenv.git .rbenv -2. Add `~/.rbenv/bin` to your `$PATH` for access to the `rbenv` -command-line utility. +2. Add `~/.rbenv/bin` to your `$PATH` for access to the `rbenv` command-line utility. $ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> .bash_profile - zsh users should add this line to `.zshrc` instead: +**ZSH note**: Modifiy your `~/.zshrc` file instead of `~/.bash_profile`. - $ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> .zshrc - -3. Add rbenv's shims directory to your `$PATH` and set up Bash -autocompletion. (If you prefer not to load rbenv in your shell, you -can manually add `$HOME/.rbenv/shims` to your path in step 2.) +3. Add rbenv init to your shell to enable shims and autocompletion. $ echo 'eval "$(rbenv init -)"' >> .bash_profile - zsh users should add this line to `.zshrc` instead: - - $ echo 'eval "$(rbenv init -)"' >> .zshrc - -4. Restart your shell so the path changes take effect. You can now -begin using rbenv. +4. Restart your shell so the path changes take effect. You can now begin using rbenv. $ exec $SHELL -5. Install Ruby versions into `~/.rbenv/versions`. For example, to -install Ruby 1.9.2-p290, download and unpack the source, then run: +5. Install Ruby versions into `~/.rbenv/versions`. For example, to install Ruby 1.9.2-p290, download and unpack the source, then run: $ ./configure --prefix=$HOME/.rbenv/versions/1.9.2-p290 $ make $ make install - The [ruby-build](https://github.com/sstephenson/ruby-build) - provides an `rbenv install` command that simplifies the process of - installing new Ruby versions to: +The [ruby-build](https://github.com/sstephenson/ruby-build) provides an `rbenv install` command that simplifies the process of installing new Ruby versions to: $ rbenv install 1.9.2-p290 -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). +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). $ rbenv rehash @@ -157,17 +142,30 @@ tag: ### 2.2 Homebrew on Mac OS X -You can also install rbenv using the -[Homebrew](http://mxcl.github.com/homebrew/) package manager on Mac OS -X. +You can also install rbenv using the [Homebrew](http://mxcl.github.com/homebrew/) package manager on Mac OS X. $ brew update $ brew install rbenv + $ brew install ruby-build -You'll need to add rbenv's shims directory to your path afterwards -(installation step 3 above). Follow the instructions above for -installing Ruby versions. (The ruby-build package can be installed -with Homebrew as well.) +The same commands can be used for upgrading. + +Afterwards you'll still need to add `eval "$(rbenv init -)"` to your profile as stated in the caveats. You'll only ever have to do this once. + +### 2.3 Neckbeard Configuration + +Skip this section unless you must know what every line in your shell profile is doing. + +`rbenv init` is the only command that crosses the line of loading extra commands into your shell. Coming from rvm, some of you might be opposed to this idea. + +Heres what `rbenv init` actually does: + +1. Sets up your shims path. This is the only requirement for rbenv to functional properly. You can do this by hand by prepending `~/.rbenv/shims` to your `$PATH`. +2. Installs autocompletion. This is entirely optional but pretty useful. Sourcing `~/.rbenv/completions/rbenv.bash` will set that up. There is also a `~/.rbenv/completions/rbenv.zsh` for ZSH users. +3. Initial rehash. From time to time you'll need to rebuild you're shim files. Doing this on init makes sure everything is up to date. `rbenv rehash` can always be ran manually. +4. Install sh dispatcher. This bit is also optional but allows rbenv and plugins to change variables in your current shell. This makes commands like `rbenv shell` possible. This doesn't do anything crazy like override `cd` or hack your shell prompt. But for some reason you may need `rbenv` to be a real script rather than a shell function. + +Run `rbenv init -` for yourself to see exactly whats its doing. ## 3 Usage diff --git a/doc/README.mdtoc b/doc/README.mdtoc index 2f234ca2..52f5cf81 100644 --- a/doc/README.mdtoc +++ b/doc/README.mdtoc @@ -61,58 +61,42 @@ rbenv is `~/.rbenv/shims` in your `$PATH`. ## Installation ## -rbenv is a young project, so for now you must install it from source. +**Compatibility note**: rbenv is _incompatible_ with rvm. Things will appear to work until you try to install a gem. The problem is that rvm actually overrides the `gem` command with a shell function! Please remove any references to rvm before using rbenv. -**Compatibility note**: rbenv is _incompatible_ with rvm. Things will - appear to work until you try to install a gem. The problem is that - rvm actually overrides the `gem` command with a shell function! - Please remove any references to rvm before using rbenv. +### Basic GitHub checkout + +This will get you going with the latest version of rbenv and make it easy to fork and contribute any changes back upstream. 1. Check out rbenv into `~/.rbenv`. $ cd $ git clone git://github.com/sstephenson/rbenv.git .rbenv -2. Add `~/.rbenv/bin` to your `$PATH` for access to the `rbenv` -command-line utility. +2. Add `~/.rbenv/bin` to your `$PATH` for access to the `rbenv` command-line utility. $ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> .bash_profile - zsh users should add this line to `.zshrc` instead: +**ZSH note**: Modifiy your `~/.zshrc` file instead of `~/.bash_profile`. - $ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> .zshrc - -3. Add rbenv's shims directory to your `$PATH` and set up Bash -autocompletion. (If you prefer not to load rbenv in your shell, you -can manually add `$HOME/.rbenv/shims` to your path in step 2.) +3. Add rbenv init to your shell to enable shims and autocompletion. $ echo 'eval "$(rbenv init -)"' >> .bash_profile - zsh users should add this line to `.zshrc` instead: - - $ echo 'eval "$(rbenv init -)"' >> .zshrc - -4. Restart your shell so the path changes take effect. You can now -begin using rbenv. +4. Restart your shell so the path changes take effect. You can now begin using rbenv. $ exec $SHELL -5. Install Ruby versions into `~/.rbenv/versions`. For example, to -install Ruby 1.9.2-p290, download and unpack the source, then run: +5. Install Ruby versions into `~/.rbenv/versions`. For example, to install Ruby 1.9.2-p290, download and unpack the source, then run: $ ./configure --prefix=$HOME/.rbenv/versions/1.9.2-p290 $ make $ make install - The [ruby-build](https://github.com/sstephenson/ruby-build) - provides an `rbenv install` command that simplifies the process of - installing new Ruby versions to: +The [ruby-build](https://github.com/sstephenson/ruby-build) provides an `rbenv install` command that simplifies the process of installing new Ruby versions to: $ rbenv install 1.9.2-p290 -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). +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). $ rbenv rehash @@ -140,17 +124,30 @@ tag: ### Homebrew on Mac OS X ### -You can also install rbenv using the -[Homebrew](http://mxcl.github.com/homebrew/) package manager on Mac OS -X. +You can also install rbenv using the [Homebrew](http://mxcl.github.com/homebrew/) package manager on Mac OS X. $ brew update $ brew install rbenv + $ brew install ruby-build -You'll need to add rbenv's shims directory to your path afterwards -(installation step 3 above). Follow the instructions above for -installing Ruby versions. (The ruby-build package can be installed -with Homebrew as well.) +The same commands can be used for upgrading. + +Afterwards you'll still need to add `eval "$(rbenv init -)"` to your profile as stated in the caveats. You'll only ever have to do this once. + +### Neckbeard Configuration ### + +Skip this section unless you must know what every line in your shell profile is doing. + +`rbenv init` is the only command that crosses the line of loading extra commands into your shell. Coming from rvm, some of you might be opposed to this idea. + +Heres what `rbenv init` actually does: + +1. Sets up your shims path. This is the only requirement for rbenv to functional properly. You can do this by hand by prepending `~/.rbenv/shims` to your `$PATH`. +2. Installs autocompletion. This is entirely optional but pretty useful. Sourcing `~/.rbenv/completions/rbenv.bash` will set that up. There is also a `~/.rbenv/completions/rbenv.zsh` for ZSH users. +3. Initial rehash. From time to time you'll need to rebuild you're shim files. Doing this on init makes sure everything is up to date. `rbenv rehash` can always be ran manually. +4. Install sh dispatcher. This bit is also optional but allows rbenv and plugins to change variables in your current shell. This makes commands like `rbenv shell` possible. This doesn't do anything crazy like override `cd` or hack your shell prompt. But for some reason you may need `rbenv` to be a real script rather than a shell function. + +Run `rbenv init -` for yourself to see exactly whats its doing. ## Usage ## From 500c6de37cc0493c9c35c44cf068a175ceb99419 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Wed, 28 Sep 2011 13:27:42 -0500 Subject: [PATCH 166/384] fill-region --- README.md | 74 +++++++++++++++++++++++++++++++++++------------- doc/README.mdtoc | 71 ++++++++++++++++++++++++++++++++++------------ 2 files changed, 108 insertions(+), 37 deletions(-) diff --git a/README.md b/README.md index 027129f2..78ba9d07 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,8 @@ tools that do one thing well. * [1 How It Works](#section_1) * [2 Installation](#section_2) - * [2.1 Upgrading an existing installation](#section_2.1) + * [2.1 Basic GitHub Checkout](#section_2.1) + * [2.1.1 Upgrading](#section_2.1.1) * [2.2 Homebrew on Mac OS X](#section_2.2) * [2.3 Neckbeard Configuration](#section_2.3) * [3 Usage](#section_3) @@ -79,46 +80,59 @@ rbenv is `~/.rbenv/shims` in your `$PATH`. ## 2 Installation -**Compatibility note**: rbenv is _incompatible_ with rvm. Things will appear to work until you try to install a gem. The problem is that rvm actually overrides the `gem` command with a shell function! Please remove any references to rvm before using rbenv. +**Compatibility note**: rbenv is _incompatible_ with rvm. Things will + appear to work until you try to install a gem. The problem is that + rvm actually overrides the `gem` command with a shell function! + Please remove any references to rvm before using rbenv. -### Basic GitHub checkout +### 2.1 Basic GitHub Checkout -This will get you going with the latest version of rbenv and make it easy to fork and contribute any changes back upstream. +This will get you going with the latest version of rbenv and make it +easy to fork and contribute any changes back upstream. 1. Check out rbenv into `~/.rbenv`. $ cd $ git clone git://github.com/sstephenson/rbenv.git .rbenv -2. Add `~/.rbenv/bin` to your `$PATH` for access to the `rbenv` command-line utility. +2. Add `~/.rbenv/bin` to your `$PATH` for access to the `rbenv` + command-line utility. $ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> .bash_profile -**ZSH note**: Modifiy your `~/.zshrc` file instead of `~/.bash_profile`. + **ZSH note**: Modifiy your `~/.zshrc` file instead of `~/.bash_profile`. 3. Add rbenv init to your shell to enable shims and autocompletion. $ echo 'eval "$(rbenv init -)"' >> .bash_profile -4. Restart your shell so the path changes take effect. You can now begin using rbenv. + **ZSH note**: Modifiy your `~/.zshrc` file instead of `~/.bash_profile`. + +4. Restart your shell so the path changes take effect. You can now + begin using rbenv. $ exec $SHELL -5. Install Ruby versions into `~/.rbenv/versions`. For example, to install Ruby 1.9.2-p290, download and unpack the source, then run: +5. Install Ruby versions into `~/.rbenv/versions`. For example, to + install Ruby 1.9.2-p290, download and unpack the source, then run: $ ./configure --prefix=$HOME/.rbenv/versions/1.9.2-p290 $ make $ make install -The [ruby-build](https://github.com/sstephenson/ruby-build) provides an `rbenv install` command that simplifies the process of installing new Ruby versions to: + The [ruby-build](https://github.com/sstephenson/ruby-build) + provides an `rbenv install` command that simplifies the process of + installing new Ruby versions to: $ rbenv install 1.9.2-p290 -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). +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). $ rbenv rehash -### 2.1 Upgrading an existing installation +#### 2.1.1 Upgrading If you've installed rbenv using the instructions above, you can upgrade your installation at any time using git. @@ -142,7 +156,9 @@ tag: ### 2.2 Homebrew on Mac OS X -You can also install rbenv using the [Homebrew](http://mxcl.github.com/homebrew/) package manager on Mac OS X. +You can also install rbenv using the +[Homebrew](http://mxcl.github.com/homebrew/) package manager on Mac OS +X. $ brew update $ brew install rbenv @@ -150,20 +166,40 @@ You can also install rbenv using the [Homebrew](http://mxcl.github.com/homebrew/ The same commands can be used for upgrading. -Afterwards you'll still need to add `eval "$(rbenv init -)"` to your profile as stated in the caveats. You'll only ever have to do this once. +Afterwards you'll still need to add `eval "$(rbenv init -)"` to your +profile as stated in the caveats. You'll only ever have to do this +once. ### 2.3 Neckbeard Configuration -Skip this section unless you must know what every line in your shell profile is doing. +Skip this section unless you must know what every line in your shell +profile is doing. -`rbenv init` is the only command that crosses the line of loading extra commands into your shell. Coming from rvm, some of you might be opposed to this idea. +`rbenv init` is the only command that crosses the line of loading +extra commands into your shell. Coming from rvm, some of you might be +opposed to this idea. Heres what `rbenv init` actually does: -1. Sets up your shims path. This is the only requirement for rbenv to functional properly. You can do this by hand by prepending `~/.rbenv/shims` to your `$PATH`. -2. Installs autocompletion. This is entirely optional but pretty useful. Sourcing `~/.rbenv/completions/rbenv.bash` will set that up. There is also a `~/.rbenv/completions/rbenv.zsh` for ZSH users. -3. Initial rehash. From time to time you'll need to rebuild you're shim files. Doing this on init makes sure everything is up to date. `rbenv rehash` can always be ran manually. -4. Install sh dispatcher. This bit is also optional but allows rbenv and plugins to change variables in your current shell. This makes commands like `rbenv shell` possible. This doesn't do anything crazy like override `cd` or hack your shell prompt. But for some reason you may need `rbenv` to be a real script rather than a shell function. +1. Sets up your shims path. This is the only requirement for rbenv to + functional properly. You can do this by hand by prepending + `~/.rbenv/shims` to your `$PATH`. + +2. Installs autocompletion. This is entirely optional but pretty + useful. Sourcing `~/.rbenv/completions/rbenv.bash` will set that + up. There is also a `~/.rbenv/completions/rbenv.zsh` for ZSH + users. + +3. Initial rehash. From time to time you'll need to rebuild you're + shim files. Doing this on init makes sure everything is up to + date. `rbenv rehash` can always be ran manually. + +4. Install sh dispatcher. This bit is also optional but allows rbenv + and plugins to change variables in your current shell. This makes + commands like `rbenv shell` possible. This doesn't do anything + crazy like override `cd` or hack your shell prompt. But for some + reason you may need `rbenv` to be a real script rather than a shell + function. Run `rbenv init -` for yourself to see exactly whats its doing. diff --git a/doc/README.mdtoc b/doc/README.mdtoc index 52f5cf81..7fe00572 100644 --- a/doc/README.mdtoc +++ b/doc/README.mdtoc @@ -61,46 +61,59 @@ rbenv is `~/.rbenv/shims` in your `$PATH`. ## Installation ## -**Compatibility note**: rbenv is _incompatible_ with rvm. Things will appear to work until you try to install a gem. The problem is that rvm actually overrides the `gem` command with a shell function! Please remove any references to rvm before using rbenv. +**Compatibility note**: rbenv is _incompatible_ with rvm. Things will + appear to work until you try to install a gem. The problem is that + rvm actually overrides the `gem` command with a shell function! + Please remove any references to rvm before using rbenv. -### Basic GitHub checkout +### Basic GitHub Checkout ### -This will get you going with the latest version of rbenv and make it easy to fork and contribute any changes back upstream. +This will get you going with the latest version of rbenv and make it +easy to fork and contribute any changes back upstream. 1. Check out rbenv into `~/.rbenv`. $ cd $ git clone git://github.com/sstephenson/rbenv.git .rbenv -2. Add `~/.rbenv/bin` to your `$PATH` for access to the `rbenv` command-line utility. +2. Add `~/.rbenv/bin` to your `$PATH` for access to the `rbenv` + command-line utility. $ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> .bash_profile -**ZSH note**: Modifiy your `~/.zshrc` file instead of `~/.bash_profile`. + **ZSH note**: Modifiy your `~/.zshrc` file instead of `~/.bash_profile`. 3. Add rbenv init to your shell to enable shims and autocompletion. $ echo 'eval "$(rbenv init -)"' >> .bash_profile -4. Restart your shell so the path changes take effect. You can now begin using rbenv. + **ZSH note**: Modifiy your `~/.zshrc` file instead of `~/.bash_profile`. + +4. Restart your shell so the path changes take effect. You can now + begin using rbenv. $ exec $SHELL -5. Install Ruby versions into `~/.rbenv/versions`. For example, to install Ruby 1.9.2-p290, download and unpack the source, then run: +5. Install Ruby versions into `~/.rbenv/versions`. For example, to + install Ruby 1.9.2-p290, download and unpack the source, then run: $ ./configure --prefix=$HOME/.rbenv/versions/1.9.2-p290 $ make $ make install -The [ruby-build](https://github.com/sstephenson/ruby-build) provides an `rbenv install` command that simplifies the process of installing new Ruby versions to: + The [ruby-build](https://github.com/sstephenson/ruby-build) + provides an `rbenv install` command that simplifies the process of + installing new Ruby versions to: $ rbenv install 1.9.2-p290 -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). +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). $ rbenv rehash -### Upgrading an existing installation ### +#### Upgrading #### If you've installed rbenv using the instructions above, you can upgrade your installation at any time using git. @@ -124,7 +137,9 @@ tag: ### Homebrew on Mac OS X ### -You can also install rbenv using the [Homebrew](http://mxcl.github.com/homebrew/) package manager on Mac OS X. +You can also install rbenv using the +[Homebrew](http://mxcl.github.com/homebrew/) package manager on Mac OS +X. $ brew update $ brew install rbenv @@ -132,20 +147,40 @@ You can also install rbenv using the [Homebrew](http://mxcl.github.com/homebrew/ The same commands can be used for upgrading. -Afterwards you'll still need to add `eval "$(rbenv init -)"` to your profile as stated in the caveats. You'll only ever have to do this once. +Afterwards you'll still need to add `eval "$(rbenv init -)"` to your +profile as stated in the caveats. You'll only ever have to do this +once. ### Neckbeard Configuration ### -Skip this section unless you must know what every line in your shell profile is doing. +Skip this section unless you must know what every line in your shell +profile is doing. -`rbenv init` is the only command that crosses the line of loading extra commands into your shell. Coming from rvm, some of you might be opposed to this idea. +`rbenv init` is the only command that crosses the line of loading +extra commands into your shell. Coming from rvm, some of you might be +opposed to this idea. Heres what `rbenv init` actually does: -1. Sets up your shims path. This is the only requirement for rbenv to functional properly. You can do this by hand by prepending `~/.rbenv/shims` to your `$PATH`. -2. Installs autocompletion. This is entirely optional but pretty useful. Sourcing `~/.rbenv/completions/rbenv.bash` will set that up. There is also a `~/.rbenv/completions/rbenv.zsh` for ZSH users. -3. Initial rehash. From time to time you'll need to rebuild you're shim files. Doing this on init makes sure everything is up to date. `rbenv rehash` can always be ran manually. -4. Install sh dispatcher. This bit is also optional but allows rbenv and plugins to change variables in your current shell. This makes commands like `rbenv shell` possible. This doesn't do anything crazy like override `cd` or hack your shell prompt. But for some reason you may need `rbenv` to be a real script rather than a shell function. +1. Sets up your shims path. This is the only requirement for rbenv to + functional properly. You can do this by hand by prepending + `~/.rbenv/shims` to your `$PATH`. + +2. Installs autocompletion. This is entirely optional but pretty + useful. Sourcing `~/.rbenv/completions/rbenv.bash` will set that + up. There is also a `~/.rbenv/completions/rbenv.zsh` for ZSH + users. + +3. Initial rehash. From time to time you'll need to rebuild you're + shim files. Doing this on init makes sure everything is up to + date. `rbenv rehash` can always be ran manually. + +4. Install sh dispatcher. This bit is also optional but allows rbenv + and plugins to change variables in your current shell. This makes + commands like `rbenv shell` possible. This doesn't do anything + crazy like override `cd` or hack your shell prompt. But for some + reason you may need `rbenv` to be a real script rather than a shell + function. Run `rbenv init -` for yourself to see exactly whats its doing. From dc1f58390305e2bc78576ca89212dfd5fb51b3b6 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Wed, 28 Sep 2011 13:29:37 -0500 Subject: [PATCH 167/384] "Zsh" is the canonical capitalization --- README.md | 10 +++++----- doc/README.mdtoc | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 78ba9d07..d8bc11c7 100644 --- a/README.md +++ b/README.md @@ -100,13 +100,13 @@ easy to fork and contribute any changes back upstream. $ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> .bash_profile - **ZSH note**: Modifiy your `~/.zshrc` file instead of `~/.bash_profile`. + **Zsh note**: Modifiy your `~/.zshrc` file instead of `~/.bash_profile`. 3. Add rbenv init to your shell to enable shims and autocompletion. $ echo 'eval "$(rbenv init -)"' >> .bash_profile - **ZSH note**: Modifiy your `~/.zshrc` file instead of `~/.bash_profile`. + **Zsh note**: Modifiy your `~/.zshrc` file instead of `~/.bash_profile`. 4. Restart your shell so the path changes take effect. You can now begin using rbenv. @@ -187,7 +187,7 @@ Heres what `rbenv init` actually does: 2. Installs autocompletion. This is entirely optional but pretty useful. Sourcing `~/.rbenv/completions/rbenv.bash` will set that - up. There is also a `~/.rbenv/completions/rbenv.zsh` for ZSH + up. There is also a `~/.rbenv/completions/rbenv.zsh` for Zsh users. 3. Initial rehash. From time to time you'll need to rebuild you're @@ -334,7 +334,7 @@ tracker](https://github.com/sstephenson/rbenv/issues). * Added support for debugging rbenv via `set -x` when the `$RBENV_DEBUG` environment variable is set. * Refactored the autocompletion system so that completions are now - built-in to each command and shared between bash and zsh. + built-in to each command and shared between bash and Zsh. * Added support for plugin bundles in `~/.rbenv/plugins` as documented in [issue #102](https://github.com/sstephenson/rbenv/pull/102). * Added `/usr/local/etc/rbenv.d` to the list of directories searched @@ -350,7 +350,7 @@ tracker](https://github.com/sstephenson/rbenv/issues). * Made the `rbenv rehash` command operate atomically. * Modified the `rbenv init` script to automatically run `rbenv rehash` so that shims are recreated whenever a new shell is opened. -* Added initial support for zsh autocompletion. +* Added initial support for Zsh autocompletion. * Removed the dependency on egrep for reading version files. **0.1.1** (August 14, 2011) diff --git a/doc/README.mdtoc b/doc/README.mdtoc index 7fe00572..96e32e95 100644 --- a/doc/README.mdtoc +++ b/doc/README.mdtoc @@ -81,13 +81,13 @@ easy to fork and contribute any changes back upstream. $ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> .bash_profile - **ZSH note**: Modifiy your `~/.zshrc` file instead of `~/.bash_profile`. + **Zsh note**: Modifiy your `~/.zshrc` file instead of `~/.bash_profile`. 3. Add rbenv init to your shell to enable shims and autocompletion. $ echo 'eval "$(rbenv init -)"' >> .bash_profile - **ZSH note**: Modifiy your `~/.zshrc` file instead of `~/.bash_profile`. + **Zsh note**: Modifiy your `~/.zshrc` file instead of `~/.bash_profile`. 4. Restart your shell so the path changes take effect. You can now begin using rbenv. @@ -168,7 +168,7 @@ Heres what `rbenv init` actually does: 2. Installs autocompletion. This is entirely optional but pretty useful. Sourcing `~/.rbenv/completions/rbenv.bash` will set that - up. There is also a `~/.rbenv/completions/rbenv.zsh` for ZSH + up. There is also a `~/.rbenv/completions/rbenv.zsh` for Zsh users. 3. Initial rehash. From time to time you'll need to rebuild you're @@ -315,7 +315,7 @@ tracker](https://github.com/sstephenson/rbenv/issues). * Added support for debugging rbenv via `set -x` when the `$RBENV_DEBUG` environment variable is set. * Refactored the autocompletion system so that completions are now - built-in to each command and shared between bash and zsh. + built-in to each command and shared between bash and Zsh. * Added support for plugin bundles in `~/.rbenv/plugins` as documented in [issue #102](https://github.com/sstephenson/rbenv/pull/102). * Added `/usr/local/etc/rbenv.d` to the list of directories searched @@ -331,7 +331,7 @@ tracker](https://github.com/sstephenson/rbenv/issues). * Made the `rbenv rehash` command operate atomically. * Modified the `rbenv init` script to automatically run `rbenv rehash` so that shims are recreated whenever a new shell is opened. -* Added initial support for zsh autocompletion. +* Added initial support for Zsh autocompletion. * Removed the dependency on egrep for reading version files. **0.1.1** (August 14, 2011) From 4965a1d1f7d7402c49e733b9d112634ba15c281c Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Wed, 28 Sep 2011 13:35:17 -0500 Subject: [PATCH 168/384] Style --- README.md | 25 ++++++++++++------------- doc/README.mdtoc | 25 ++++++++++++------------- 2 files changed, 24 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index d8bc11c7..569a8304 100644 --- a/README.md +++ b/README.md @@ -177,12 +177,10 @@ profile is doing. `rbenv init` is the only command that crosses the line of loading extra commands into your shell. Coming from rvm, some of you might be -opposed to this idea. - -Heres what `rbenv init` actually does: +opposed to this idea. Here's what `rbenv init` actually does: 1. Sets up your shims path. This is the only requirement for rbenv to - functional properly. You can do this by hand by prepending + function properly. You can do this by hand by prepending `~/.rbenv/shims` to your `$PATH`. 2. Installs autocompletion. This is entirely optional but pretty @@ -190,18 +188,19 @@ Heres what `rbenv init` actually does: up. There is also a `~/.rbenv/completions/rbenv.zsh` for Zsh users. -3. Initial rehash. From time to time you'll need to rebuild you're +3. Rehashes shims. From time to time you'll need to rebuild your shim files. Doing this on init makes sure everything is up to - date. `rbenv rehash` can always be ran manually. + date. You can always run `rbenv rehash` manually. -4. Install sh dispatcher. This bit is also optional but allows rbenv - and plugins to change variables in your current shell. This makes - commands like `rbenv shell` possible. This doesn't do anything - crazy like override `cd` or hack your shell prompt. But for some - reason you may need `rbenv` to be a real script rather than a shell - function. +4. Installs the sh dispatcher. This bit is also optional, but allows + rbenv and plugins to change variables in your current shell, making + commands like `rbenv shell` possible. The sh dispatcher doesn't do + anything crazy like override `cd` or hack your shell prompt, but if + for some reason you need `rbenv` to be a real script rather than a + shell function, you can safely skip it. -Run `rbenv init -` for yourself to see exactly whats its doing. +Run `rbenv init -` for yourself to see exactly what happens under the +hood. ## 3 Usage diff --git a/doc/README.mdtoc b/doc/README.mdtoc index 96e32e95..f6a33066 100644 --- a/doc/README.mdtoc +++ b/doc/README.mdtoc @@ -158,12 +158,10 @@ profile is doing. `rbenv init` is the only command that crosses the line of loading extra commands into your shell. Coming from rvm, some of you might be -opposed to this idea. - -Heres what `rbenv init` actually does: +opposed to this idea. Here's what `rbenv init` actually does: 1. Sets up your shims path. This is the only requirement for rbenv to - functional properly. You can do this by hand by prepending + function properly. You can do this by hand by prepending `~/.rbenv/shims` to your `$PATH`. 2. Installs autocompletion. This is entirely optional but pretty @@ -171,18 +169,19 @@ Heres what `rbenv init` actually does: up. There is also a `~/.rbenv/completions/rbenv.zsh` for Zsh users. -3. Initial rehash. From time to time you'll need to rebuild you're +3. Rehashes shims. From time to time you'll need to rebuild your shim files. Doing this on init makes sure everything is up to - date. `rbenv rehash` can always be ran manually. + date. You can always run `rbenv rehash` manually. -4. Install sh dispatcher. This bit is also optional but allows rbenv - and plugins to change variables in your current shell. This makes - commands like `rbenv shell` possible. This doesn't do anything - crazy like override `cd` or hack your shell prompt. But for some - reason you may need `rbenv` to be a real script rather than a shell - function. +4. Installs the sh dispatcher. This bit is also optional, but allows + rbenv and plugins to change variables in your current shell, making + commands like `rbenv shell` possible. The sh dispatcher doesn't do + anything crazy like override `cd` or hack your shell prompt, but if + for some reason you need `rbenv` to be a real script rather than a + shell function, you can safely skip it. -Run `rbenv init -` for yourself to see exactly whats its doing. +Run `rbenv init -` for yourself to see exactly what happens under the +hood. ## Usage ## From 2cd12e3fa6bfd0dc86c761ef5a6135f61183a785 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Wed, 28 Sep 2011 13:38:03 -0500 Subject: [PATCH 169/384] rbenv 0.2.0 --- README.md | 2 +- doc/README.mdtoc | 2 +- libexec/rbenv | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 569a8304..a3f77c78 100644 --- a/README.md +++ b/README.md @@ -314,7 +314,7 @@ tracker](https://github.com/sstephenson/rbenv/issues). ### 4.1 Version History -**HEAD** +**0.2.0** (September 28, 2011) * Renamed `rbenv set-default` to `rbenv global` and `rbenv set-local` to `rbenv local`. The `set-` commands are deprecated and will be diff --git a/doc/README.mdtoc b/doc/README.mdtoc index f6a33066..14ad7509 100644 --- a/doc/README.mdtoc +++ b/doc/README.mdtoc @@ -295,7 +295,7 @@ tracker](https://github.com/sstephenson/rbenv/issues). ### Version History ### -**HEAD** +**0.2.0** (September 28, 2011) * Renamed `rbenv set-default` to `rbenv global` and `rbenv set-local` to `rbenv local`. The `set-` commands are deprecated and will be diff --git a/libexec/rbenv b/libexec/rbenv index f6b07b92..71924c99 100755 --- a/libexec/rbenv +++ b/libexec/rbenv @@ -53,7 +53,7 @@ shopt -u nullglob command="$1" case "$command" in "" | "-h" | "--help" ) - echo -e "rbenv 0.2.0-pre\n$(rbenv-help)" >&2 + echo -e "rbenv 0.2.0\n$(rbenv-help)" >&2 ;; * ) command_path="$(command -v "rbenv-$command" || true)" From 7a929b8a8462c4756fff951587b2569c85099c30 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Wed, 28 Sep 2011 13:41:10 -0500 Subject: [PATCH 170/384] Indentation --- README.md | 6 +++--- doc/README.mdtoc | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index a3f77c78..8036d64c 100644 --- a/README.md +++ b/README.md @@ -120,9 +120,9 @@ easy to fork and contribute any changes back upstream. $ make $ make install - The [ruby-build](https://github.com/sstephenson/ruby-build) - provides an `rbenv install` command that simplifies the process of - installing new Ruby versions to: + The [ruby-build](https://github.com/sstephenson/ruby-build) + provides an `rbenv install` command that simplifies the process of + installing new Ruby versions to: $ rbenv install 1.9.2-p290 diff --git a/doc/README.mdtoc b/doc/README.mdtoc index 14ad7509..f45af87c 100644 --- a/doc/README.mdtoc +++ b/doc/README.mdtoc @@ -101,9 +101,9 @@ easy to fork and contribute any changes back upstream. $ make $ make install - The [ruby-build](https://github.com/sstephenson/ruby-build) - provides an `rbenv install` command that simplifies the process of - installing new Ruby versions to: + The [ruby-build](https://github.com/sstephenson/ruby-build) + provides an `rbenv install` command that simplifies the process of + installing new Ruby versions to: $ rbenv install 1.9.2-p290 From ddd4db1b0566ca64a9d0ea61597f7571d36894e9 Mon Sep 17 00:00:00 2001 From: Eric Skogen Date: Fri, 30 Sep 2011 21:54:09 -0500 Subject: [PATCH 171/384] Fix command to modify ~/.bash_profile in user's home directory (~/, instead of in-place) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8036d64c..8b0f1fe1 100644 --- a/README.md +++ b/README.md @@ -104,7 +104,7 @@ easy to fork and contribute any changes back upstream. 3. Add rbenv init to your shell to enable shims and autocompletion. - $ echo 'eval "$(rbenv init -)"' >> .bash_profile + $ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile **Zsh note**: Modifiy your `~/.zshrc` file instead of `~/.bash_profile`. From fb0ec9e15728b8d61af693cf465660269b8a2b7b Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Sat, 1 Oct 2011 11:05:31 -0500 Subject: [PATCH 172/384] Be explicit about ~ --- README.md | 2 +- doc/README.mdtoc | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 8b0f1fe1..3ceabdd8 100644 --- a/README.md +++ b/README.md @@ -98,7 +98,7 @@ easy to fork and contribute any changes back upstream. 2. Add `~/.rbenv/bin` to your `$PATH` for access to the `rbenv` command-line utility. - $ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> .bash_profile + $ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile **Zsh note**: Modifiy your `~/.zshrc` file instead of `~/.bash_profile`. diff --git a/doc/README.mdtoc b/doc/README.mdtoc index f45af87c..0b493d54 100644 --- a/doc/README.mdtoc +++ b/doc/README.mdtoc @@ -79,13 +79,13 @@ easy to fork and contribute any changes back upstream. 2. Add `~/.rbenv/bin` to your `$PATH` for access to the `rbenv` command-line utility. - $ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> .bash_profile + $ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile **Zsh note**: Modifiy your `~/.zshrc` file instead of `~/.bash_profile`. 3. Add rbenv init to your shell to enable shims and autocompletion. - $ echo 'eval "$(rbenv init -)"' >> .bash_profile + $ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile **Zsh note**: Modifiy your `~/.zshrc` file instead of `~/.bash_profile`. From e49be969aba1aec998ab3da38e9a09a2cf881b9e Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Sat, 1 Oct 2011 12:15:20 -0500 Subject: [PATCH 173/384] Ensure RBENV_DIR is always an absolute path Otherwise, `RBENV_DIR=bin rbenv version-file` loops indefinitely --- libexec/rbenv | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libexec/rbenv b/libexec/rbenv index 71924c99..15c02e0a 100755 --- a/libexec/rbenv +++ b/libexec/rbenv @@ -29,6 +29,8 @@ export RBENV_ROOT if [ -z "${RBENV_DIR}" ]; then RBENV_DIR="$(pwd)" +else + RBENV_DIR="$(abs_dirname "$RBENV_DIR")" fi export RBENV_DIR From 2bbe2099ebbec953ec2bf7f00d4eff5e3a347930 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Sat, 1 Oct 2011 12:20:58 -0500 Subject: [PATCH 174/384] Missing word --- README.md | 2 +- doc/README.mdtoc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3ceabdd8..c21a51da 100644 --- a/README.md +++ b/README.md @@ -120,7 +120,7 @@ easy to fork and contribute any changes back upstream. $ make $ make install - The [ruby-build](https://github.com/sstephenson/ruby-build) + The [ruby-build](https://github.com/sstephenson/ruby-build) project provides an `rbenv install` command that simplifies the process of installing new Ruby versions to: diff --git a/doc/README.mdtoc b/doc/README.mdtoc index 0b493d54..1b114e0b 100644 --- a/doc/README.mdtoc +++ b/doc/README.mdtoc @@ -101,7 +101,7 @@ easy to fork and contribute any changes back upstream. $ make $ make install - The [ruby-build](https://github.com/sstephenson/ruby-build) + The [ruby-build](https://github.com/sstephenson/ruby-build) project provides an `rbenv install` command that simplifies the process of installing new Ruby versions to: From 01a0ad0b69c69f6a6a9fc66496f3eaf460db51fb Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Sat, 1 Oct 2011 12:26:19 -0500 Subject: [PATCH 175/384] rbenv 0.2.1 --- README.md | 7 +++++++ doc/README.mdtoc | 7 +++++++ libexec/rbenv | 2 +- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c21a51da..9f704ae8 100644 --- a/README.md +++ b/README.md @@ -314,6 +314,13 @@ tracker](https://github.com/sstephenson/rbenv/issues). ### 4.1 Version History +**0.2.1** (October 1, 2011) + +* Changed the `rbenv` command to ensure that `RBENV_DIR` is always an + absolute path. This fixes an issue where Ruby scripts using the + `ruby-local-exec` wrapper would go into an infinite loop when + invoked with a relative path from the command line. + **0.2.0** (September 28, 2011) * Renamed `rbenv set-default` to `rbenv global` and `rbenv set-local` diff --git a/doc/README.mdtoc b/doc/README.mdtoc index 1b114e0b..34158206 100644 --- a/doc/README.mdtoc +++ b/doc/README.mdtoc @@ -295,6 +295,13 @@ tracker](https://github.com/sstephenson/rbenv/issues). ### Version History ### +**0.2.1** (October 1, 2011) + +* Changed the `rbenv` command to ensure that `RBENV_DIR` is always an + absolute path. This fixes an issue where Ruby scripts using the + `ruby-local-exec` wrapper would go into an infinite loop when + invoked with a relative path from the command line. + **0.2.0** (September 28, 2011) * Renamed `rbenv set-default` to `rbenv global` and `rbenv set-local` diff --git a/libexec/rbenv b/libexec/rbenv index 15c02e0a..a80ede8b 100755 --- a/libexec/rbenv +++ b/libexec/rbenv @@ -55,7 +55,7 @@ shopt -u nullglob command="$1" case "$command" in "" | "-h" | "--help" ) - echo -e "rbenv 0.2.0\n$(rbenv-help)" >&2 + echo -e "rbenv 0.2.1\n$(rbenv-help)" >&2 ;; * ) command_path="$(command -v "rbenv-$command" || true)" From be7dcc0ad84ad8abc5652b1e80dedff098a53a08 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Thu, 10 Nov 2011 10:54:30 -0600 Subject: [PATCH 176/384] Add `rbenv root` Prints $RBENV_ROOT (defaults to ~/.rbenv) --- libexec/rbenv-root | 2 ++ 1 file changed, 2 insertions(+) create mode 100755 libexec/rbenv-root diff --git a/libexec/rbenv-root b/libexec/rbenv-root new file mode 100755 index 00000000..cf02c058 --- /dev/null +++ b/libexec/rbenv-root @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +echo $RBENV_ROOT From 4cc6665d0aa159fa7799b1d3e017052ff6eca844 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Mon, 14 Nov 2011 12:52:10 -0600 Subject: [PATCH 177/384] Zsh users need to modify ~/.zshenv, not ~/.zshrc --- README.md | 4 ++-- doc/README.mdtoc | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 9f704ae8..bd576f44 100644 --- a/README.md +++ b/README.md @@ -100,13 +100,13 @@ easy to fork and contribute any changes back upstream. $ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile - **Zsh note**: Modifiy your `~/.zshrc` file instead of `~/.bash_profile`. + **Zsh note**: Modifiy your `~/.zshenv` file instead of `~/.bash_profile`. 3. Add rbenv init to your shell to enable shims and autocompletion. $ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile - **Zsh note**: Modifiy your `~/.zshrc` file instead of `~/.bash_profile`. + **Zsh note**: Modifiy your `~/.zshenv` file instead of `~/.bash_profile`. 4. Restart your shell so the path changes take effect. You can now begin using rbenv. diff --git a/doc/README.mdtoc b/doc/README.mdtoc index 34158206..d23fa740 100644 --- a/doc/README.mdtoc +++ b/doc/README.mdtoc @@ -81,13 +81,13 @@ easy to fork and contribute any changes back upstream. $ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile - **Zsh note**: Modifiy your `~/.zshrc` file instead of `~/.bash_profile`. + **Zsh note**: Modifiy your `~/.zshenv` file instead of `~/.bash_profile`. 3. Add rbenv init to your shell to enable shims and autocompletion. $ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile - **Zsh note**: Modifiy your `~/.zshrc` file instead of `~/.bash_profile`. + **Zsh note**: Modifiy your `~/.zshenv` file instead of `~/.bash_profile`. 4. Restart your shell so the path changes take effect. You can now begin using rbenv. From 0324b118ee03b2bfe19f0f9cc91d163c83d2c487 Mon Sep 17 00:00:00 2001 From: Mathias Lafeldt Date: Mon, 14 Nov 2011 21:45:43 +0100 Subject: [PATCH 178/384] rbenv-rehash: remove superfluous trap signals A trap on the special signal EXIT is executed before the shell terminates. EXIT actually covers SIGINT and SIGTERM as well, and we don't need any extra traps for them. See bash(1) and "help trap" in bash. --- libexec/rbenv-rehash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libexec/rbenv-rehash b/libexec/rbenv-rehash index cb7713ef..8bdf7ed2 100755 --- a/libexec/rbenv-rehash +++ b/libexec/rbenv-rehash @@ -22,7 +22,7 @@ set +o noclobber # If we were able to obtain a lock, register a trap to clean up the # prototype shim when the process exits. -trap remove_prototype_shim SIGINT SIGTERM EXIT +trap remove_prototype_shim EXIT remove_prototype_shim() { rm -f "$PROTOTYPE_SHIM_PATH" From 9dde161b652b31185966accb225a5f05b4643704 Mon Sep 17 00:00:00 2001 From: Mathias Lafeldt Date: Mon, 14 Nov 2011 22:07:41 +0100 Subject: [PATCH 179/384] rbenv-rehash: use $OLDPWD to restore previous working directory $OLDPWD is a standard shell variable that contains the previous working directory as set by the "cd" command. No need to save $PWD to some custom variable. (We could also have used "cd -" but it prints out $OLDPWD too.) --- libexec/rbenv-rehash | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/libexec/rbenv-rehash b/libexec/rbenv-rehash index 8bdf7ed2..13f9b1cf 100755 --- a/libexec/rbenv-rehash +++ b/libexec/rbenv-rehash @@ -55,9 +55,6 @@ make_shims() { done } -# Save the working directory. -CUR_PATH=$PWD - # Empty out the shims directory and make it the working directory. rm -f "$SHIM_PATH"/* cd "$SHIM_PATH" @@ -68,7 +65,7 @@ shopt -s nullglob make_shims ../versions/*/bin/* # Restore the previous working directory. -cd "$CUR_PATH" +cd "$OLDPWD" for script in $(rbenv-hooks rehash); do source "$script" From dfc7645609bb2e579546de51ed05f978766c8e6d Mon Sep 17 00:00:00 2001 From: Per Velschow Date: Fri, 18 Nov 2011 21:21:16 +0100 Subject: [PATCH 180/384] Quoting the argument to greadlink to make it work with paths containing spaces. --- libexec/rbenv | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libexec/rbenv b/libexec/rbenv index a80ede8b..e9894c85 100755 --- a/libexec/rbenv +++ b/libexec/rbenv @@ -3,7 +3,7 @@ set -e [ -n "$RBENV_DEBUG" ] && set -x resolve_link() { - $(type -p greadlink readlink | head -1) $1 + $(type -p greadlink readlink | head -1) "$1" } abs_dirname() { From 65f0be0c20bbfae55d55263568cc7b6e3c672cbe Mon Sep 17 00:00:00 2001 From: richo Date: Sat, 10 Dec 2011 14:17:44 +1100 Subject: [PATCH 181/384] Bail on completion init if we're not an interactive shell Based on the approach by @imajes --- completions/rbenv.zsh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/completions/rbenv.zsh b/completions/rbenv.zsh index f1a41ad9..4739ac10 100644 --- a/completions/rbenv.zsh +++ b/completions/rbenv.zsh @@ -1,3 +1,7 @@ +if [[ ! -o interactive ]]; then + return +fi + compctl -K _rbenv rbenv _rbenv() { From 7e83e07cf31b68f0173cb108d687506979130289 Mon Sep 17 00:00:00 2001 From: Michael Grubb Date: Thu, 15 Dec 2011 14:54:38 -0600 Subject: [PATCH 182/384] Made ksh portability changes Added specific message for ksh in identifying the proper shell initialization file. Changed rbenv functiond definition to be more portable. Shell functions should be defined by using the function command or using the parenthesis grammar, but using both is not portable: rbenv() {... -or- function rbenv { ... --- libexec/rbenv-init | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libexec/rbenv-init b/libexec/rbenv-init index a83cee40..d16065f7 100755 --- a/libexec/rbenv-init +++ b/libexec/rbenv-init @@ -41,6 +41,9 @@ if [ -z "$print" ]; then zsh ) profile='~/.zshrc' ;; + ksh ) + profile='~/.profile' + ;; * ) profile='your profile' ;; @@ -71,7 +74,7 @@ echo 'rbenv rehash 2>/dev/null' commands=(`rbenv commands --sh`) IFS="|" cat < Date: Sat, 24 Dec 2011 15:16:37 -0500 Subject: [PATCH 183/384] Ensure shims don't disappear when rehashed --- libexec/rbenv-rehash | 94 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 84 insertions(+), 10 deletions(-) diff --git a/libexec/rbenv-rehash b/libexec/rbenv-rehash index cb7713ef..67a14b3b 100755 --- a/libexec/rbenv-rehash +++ b/libexec/rbenv-rehash @@ -43,26 +43,93 @@ SH chmod +x "$PROTOTYPE_SHIM_PATH" } -# Make shims by iterating over every filename argument and creating a -# hard link from the prototype shim to a file of the same name in the -# shims directory, if one does not already exist. +# 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. make_shims() { - local glob="$@" + local shims="$@" - for file in $glob; do + for file in $shims; do local shim="${file##*/}" + register_shim "$shim" + done +} + +# Create an empty array for the list of registered shims. +registered_shims=() + +# 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. +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+="$shim" + else + local length="${#shim}" + local char i + + for ((i=0; i Date: Sat, 24 Dec 2011 17:49:22 -0500 Subject: [PATCH 184/384] Go with paren-style function definition --- libexec/rbenv-init | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libexec/rbenv-init b/libexec/rbenv-init index d16065f7..73aeadf1 100755 --- a/libexec/rbenv-init +++ b/libexec/rbenv-init @@ -74,7 +74,7 @@ echo 'rbenv rehash 2>/dev/null' commands=(`rbenv commands --sh`) IFS="|" cat < Date: Sun, 25 Dec 2011 16:41:15 -0500 Subject: [PATCH 185/384] Properly expand RBENV_DIR and ensure it exists --- libexec/rbenv | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libexec/rbenv b/libexec/rbenv index e9894c85..4ef98d8d 100755 --- a/libexec/rbenv +++ b/libexec/rbenv @@ -30,7 +30,12 @@ export RBENV_ROOT if [ -z "${RBENV_DIR}" ]; then RBENV_DIR="$(pwd)" else - RBENV_DIR="$(abs_dirname "$RBENV_DIR")" + cd "$RBENV_DIR" 2>/dev/null || { + echo "rbenv: cannot change working directory to \`$RBENV_DIR'" + exit 1 + } >&2 + RBENV_DIR="$(pwd)" + cd "$OLDPWD" fi export RBENV_DIR From 5052a4161ced198f4008f4c9ef5edfe35701207c Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Sun, 25 Dec 2011 16:53:59 -0500 Subject: [PATCH 186/384] Update readme screenshot to use `global` instead of `set-default` (fixes #165) --- README.md | 2 +- doc/README.mdtoc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index bd576f44..ecc5b4ad 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ rbenv lets you easily switch between multiple versions of Ruby. It's simple, unobtrusive, and follows the UNIX tradition of single-purpose tools that do one thing well. - + ### rbenv _does…_ diff --git a/doc/README.mdtoc b/doc/README.mdtoc index d23fa740..fd7a7124 100644 --- a/doc/README.mdtoc +++ b/doc/README.mdtoc @@ -4,7 +4,7 @@ rbenv lets you easily switch between multiple versions of Ruby. It's simple, unobtrusive, and follows the UNIX tradition of single-purpose tools that do one thing well. - + ### rbenv _does…_ From cd2094ff71cf2e9b7805a74dfd97ab84b92461ce Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Sun, 25 Dec 2011 20:39:11 -0500 Subject: [PATCH 187/384] Remove deprecated set-default and set-local commands --- libexec/rbenv-set-default | 9 --------- libexec/rbenv-set-local | 9 --------- 2 files changed, 18 deletions(-) delete mode 100755 libexec/rbenv-set-default delete mode 100755 libexec/rbenv-set-local diff --git a/libexec/rbenv-set-default b/libexec/rbenv-set-default deleted file mode 100755 index a1fec3db..00000000 --- a/libexec/rbenv-set-default +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/env bash -set -e - -{ echo "rbenv: warning: \`set-default' has been renamed to \`global'" - echo " and will be removed in v0.3.0" - echo -} >&2 - -exec rbenv-global "$@" diff --git a/libexec/rbenv-set-local b/libexec/rbenv-set-local deleted file mode 100755 index 28d5961f..00000000 --- a/libexec/rbenv-set-local +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/env bash -set -e - -{ echo "rbenv: warning: \`set-local' has been renamed to \`local'" - echo " and will be removed in v0.3.0" - echo -} >&2 - -exec rbenv-local "$@" From ee5ad02d42690f572d4a89386e84e6b3c04df054 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Sun, 25 Dec 2011 20:59:24 -0500 Subject: [PATCH 188/384] Add --no-rehash option to rbenv-init (#170) --- libexec/rbenv-init | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/libexec/rbenv-init b/libexec/rbenv-init index 73aeadf1..ed440d13 100755 --- a/libexec/rbenv-init +++ b/libexec/rbenv-init @@ -8,6 +8,12 @@ if [ "$1" = "-" ]; then shift fi +no_rehash="" +if [ "$1" = "--no-rehash" ]; then + no_rehash=1 + shift +fi + shell="$1" if [ -z "$shell" ]; then shell="$(basename "$SHELL")" @@ -69,7 +75,9 @@ bash | zsh ) ;; esac -echo 'rbenv rehash 2>/dev/null' +if [ -z "$no_rehash" ]; then + echo 'rbenv rehash 2>/dev/null' +fi commands=(`rbenv commands --sh`) IFS="|" From b10bdb1e78a1a38fa468c1231ac2149f472f7b05 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Sun, 25 Dec 2011 21:32:48 -0500 Subject: [PATCH 189/384] rbenv 0.3.0 --- README.md | 18 ++++++++++++++++++ doc/README.mdtoc | 18 ++++++++++++++++++ libexec/rbenv | 2 +- 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ecc5b4ad..0d402bd8 100644 --- a/README.md +++ b/README.md @@ -314,6 +314,24 @@ tracker](https://github.com/sstephenson/rbenv/issues). ### 4.1 Version History +**0.3.0** (December 25, 2011) + +* Added an `rbenv root` command which prints the value of + `$RBENV_ROOT`, or the default root directory if it's unset. +* Clarified Zsh installation instructions in the readme. +* Removed some redundant code in `rbenv rehash`. +* Fixed an issue with calling `readlink` for paths with spaces. +* Changed Zsh initialization code to install completion hooks only for + interactive shells. +* Added preliminary support for ksh. +* `rbenv rehash` creates or removes shims only when necessary instead + of removing and re-creating all shims on each invocation. +* Fixed that `RBENV_DIR`, when specified, would be incorrectly + expanded to its parent directory. +* Removed the deprecated `set-default` and `set-local` commands. +* Added a `--no-rehash` option to `rbenv init` for skipping the + automatic rehash when opening a new shell. + **0.2.1** (October 1, 2011) * Changed the `rbenv` command to ensure that `RBENV_DIR` is always an diff --git a/doc/README.mdtoc b/doc/README.mdtoc index fd7a7124..4215127e 100644 --- a/doc/README.mdtoc +++ b/doc/README.mdtoc @@ -295,6 +295,24 @@ tracker](https://github.com/sstephenson/rbenv/issues). ### Version History ### +**0.3.0** (December 25, 2011) + +* Added an `rbenv root` command which prints the value of + `$RBENV_ROOT`, or the default root directory if it's unset. +* Clarified Zsh installation instructions in the readme. +* Removed some redundant code in `rbenv rehash`. +* Fixed an issue with calling `readlink` for paths with spaces. +* Changed Zsh initialization code to install completion hooks only for + interactive shells. +* Added preliminary support for ksh. +* `rbenv rehash` creates or removes shims only when necessary instead + of removing and re-creating all shims on each invocation. +* Fixed that `RBENV_DIR`, when specified, would be incorrectly + expanded to its parent directory. +* Removed the deprecated `set-default` and `set-local` commands. +* Added a `--no-rehash` option to `rbenv init` for skipping the + automatic rehash when opening a new shell. + **0.2.1** (October 1, 2011) * Changed the `rbenv` command to ensure that `RBENV_DIR` is always an diff --git a/libexec/rbenv b/libexec/rbenv index 4ef98d8d..5fe84333 100755 --- a/libexec/rbenv +++ b/libexec/rbenv @@ -60,7 +60,7 @@ shopt -u nullglob command="$1" case "$command" in "" | "-h" | "--help" ) - echo -e "rbenv 0.2.1\n$(rbenv-help)" >&2 + echo -e "rbenv 0.3.0\n$(rbenv-help)" >&2 ;; * ) command_path="$(command -v "rbenv-$command" || true)" From 114b81c9a45bff79ce4cadad7285ffa02afff2d4 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Mon, 26 Dec 2011 20:12:16 -0600 Subject: [PATCH 190/384] Use `if` instead of inline `&&` so `rbenv rehash` exits with a zero status --- libexec/rbenv-rehash | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libexec/rbenv-rehash b/libexec/rbenv-rehash index 1f4fc91f..5757dcfe 100755 --- a/libexec/rbenv-rehash +++ b/libexec/rbenv-rehash @@ -120,7 +120,9 @@ remove_stale_shims() { local var for shim in *; do var="$(shim_variable_name "$shim")" - [ -z "${!var}" ] && rm -f "$shim" + if [ -z "${!var}" ]; then + rm -f "$shim" + fi done } From 5d0a6630b94f4a1e2aae8828788a76432f5ace09 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Fri, 30 Dec 2011 13:40:22 -0600 Subject: [PATCH 191/384] Account for path entries with spaces in remove_from_path --- libexec/rbenv-which | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libexec/rbenv-which b/libexec/rbenv-which index 768e8451..c4966c7a 100755 --- a/libexec/rbenv-which +++ b/libexec/rbenv-which @@ -27,7 +27,10 @@ remove_from_path() { return fi - for path in ${PATH//:/$'\n'}; do + local paths + IFS=: paths=($PATH) + + for path in "${paths[@]}"; do path="$(expand_path "$path" || true)" if [ -n "$path" ] && [ "$path" != "$path_to_remove" ]; then result="${result}${path}:" From f40bc773d231acfcf83a3c9b71eba67ed1cc4bef Mon Sep 17 00:00:00 2001 From: John Williams Date: Tue, 17 Jan 2012 08:50:40 -0600 Subject: [PATCH 192/384] Allow init arguments to be in any order. --- libexec/rbenv-init | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/libexec/rbenv-init b/libexec/rbenv-init index ed440d13..5c120250 100755 --- a/libexec/rbenv-init +++ b/libexec/rbenv-init @@ -3,16 +3,19 @@ set -e [ -n "$RBENV_DEBUG" ] && set -x print="" -if [ "$1" = "-" ]; then - print=1 - shift -fi - no_rehash="" -if [ "$1" = "--no-rehash" ]; then - no_rehash=1 - shift -fi +for args in "$@" +do + if [ "$args" = "-" ]; then + print=1 + shift + fi + + if [ "$args" = "--no-rehash" ]; then + no_rehash=1 + shift + fi +done shell="$1" if [ -z "$shell" ]; then From d1bfeee33495a4e0dd6a03d9189bba9fb5d3ca3f Mon Sep 17 00:00:00 2001 From: Antonio Terceiro Date: Thu, 26 Jan 2012 20:23:31 -0200 Subject: [PATCH 193/384] Add /usr/lib/rbenv/hooks to hook search path This will help with the packaging of rbenv plugin that contain hooks in Debian. --- libexec/rbenv | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libexec/rbenv b/libexec/rbenv index 5fe84333..b0470f2f 100755 --- a/libexec/rbenv +++ b/libexec/rbenv @@ -48,7 +48,7 @@ for plugin_bin in "${RBENV_ROOT}/plugins/"*/bin; do done export PATH="${bin_path}:${PATH}" -hook_path="${RBENV_HOOK_PATH}:${RBENV_ROOT}/rbenv.d:/usr/local/etc/rbenv.d:/etc/rbenv.d" +hook_path="${RBENV_HOOK_PATH}:${RBENV_ROOT}/rbenv.d:/usr/local/etc/rbenv.d:/etc/rbenv.d:/usr/lib/rbenv/hooks" for plugin_hook in "${RBENV_ROOT}/plugins/"*/etc/rbenv.d; do hook_path="${hook_path}:${plugin_hook}" done From 34813ef32cbb00dc0fe9bb4a801f9d7fd5ea9e9e Mon Sep 17 00:00:00 2001 From: Jussi Virtanen Date: Sun, 29 Jan 2012 11:25:14 +0200 Subject: [PATCH 194/384] Fix typos in documentation --- README.md | 4 ++-- doc/README.mdtoc | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 0d402bd8..923f1415 100644 --- a/README.md +++ b/README.md @@ -100,13 +100,13 @@ easy to fork and contribute any changes back upstream. $ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile - **Zsh note**: Modifiy your `~/.zshenv` file instead of `~/.bash_profile`. + **Zsh note**: Modify your `~/.zshenv` file instead of `~/.bash_profile`. 3. Add rbenv init to your shell to enable shims and autocompletion. $ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile - **Zsh note**: Modifiy your `~/.zshenv` file instead of `~/.bash_profile`. + **Zsh note**: Modify your `~/.zshenv` file instead of `~/.bash_profile`. 4. Restart your shell so the path changes take effect. You can now begin using rbenv. diff --git a/doc/README.mdtoc b/doc/README.mdtoc index 4215127e..4efea542 100644 --- a/doc/README.mdtoc +++ b/doc/README.mdtoc @@ -81,13 +81,13 @@ easy to fork and contribute any changes back upstream. $ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile - **Zsh note**: Modifiy your `~/.zshenv` file instead of `~/.bash_profile`. + **Zsh note**: Modify your `~/.zshenv` file instead of `~/.bash_profile`. 3. Add rbenv init to your shell to enable shims and autocompletion. $ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile - **Zsh note**: Modifiy your `~/.zshenv` file instead of `~/.bash_profile`. + **Zsh note**: Modify your `~/.zshenv` file instead of `~/.bash_profile`. 4. Restart your shell so the path changes take effect. You can now begin using rbenv. From e92213142205f18fc57868460746c106f5128727 Mon Sep 17 00:00:00 2001 From: Daryl Manning Date: Fri, 3 Feb 2012 17:48:20 +1100 Subject: [PATCH 195/384] Added in section 2.4 on uninstalling rubies from .rbenv/versions to the README. --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index 0d402bd8..8d308ca8 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,7 @@ tools that do one thing well. * [2.1.1 Upgrading](#section_2.1.1) * [2.2 Homebrew on Mac OS X](#section_2.2) * [2.3 Neckbeard Configuration](#section_2.3) + * [2.4 Uninstalling Rubies](#section_2.4) * [3 Usage](#section_3) * [3.1 rbenv global](#section_3.1) * [3.2 rbenv local](#section_3.2) @@ -202,6 +203,15 @@ opposed to this idea. Here's what `rbenv init` actually does: Run `rbenv init -` for yourself to see exactly what happens under the hood. +### 2.4 Uninstalling Rubies + +As time goes on, ruby versions you install will accumulate in your +`~/.rbenv/versions` directory. + +There is no uninstall or remove command in rbenv, so removing old +versions is a simple matter of `rm -rf` the directory of the relevant +ruby version you want removed under `~/.rbenv/versions` + ## 3 Usage Like `git`, the `rbenv` command delegates to subcommands based on its From b7e9569ccb489a6e24a7b0cc9975bc4e6ea71fd5 Mon Sep 17 00:00:00 2001 From: Daryl Manning Date: Fri, 3 Feb 2012 17:52:09 +1100 Subject: [PATCH 196/384] Embrassing typo in the anchor link neme != name. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8d308ca8..c5bf74db 100644 --- a/README.md +++ b/README.md @@ -203,7 +203,7 @@ opposed to this idea. Here's what `rbenv init` actually does: Run `rbenv init -` for yourself to see exactly what happens under the hood. -### 2.4 Uninstalling Rubies +### 2.4 Uninstalling Rubies As time goes on, ruby versions you install will accumulate in your `~/.rbenv/versions` directory. From 9b286ecbfd9b498ba19600d68334d9ca16f2ee75 Mon Sep 17 00:00:00 2001 From: Daryl Manning Date: Fri, 3 Feb 2012 17:54:07 +1100 Subject: [PATCH 197/384] And better codify the rbenv command just for good measure. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c5bf74db..5d08032e 100644 --- a/README.md +++ b/README.md @@ -208,7 +208,7 @@ hood. As time goes on, ruby versions you install will accumulate in your `~/.rbenv/versions` directory. -There is no uninstall or remove command in rbenv, so removing old +There is no uninstall or remove command in `rbenv`, so removing old versions is a simple matter of `rm -rf` the directory of the relevant ruby version you want removed under `~/.rbenv/versions` From 9c43fa916148008f6761781d6497c52bb36c0c46 Mon Sep 17 00:00:00 2001 From: Andrew Marshall Date: Sat, 4 Feb 2012 18:03:39 -0500 Subject: [PATCH 198/384] Prevent $command from leaking outside of function --- libexec/rbenv-init | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libexec/rbenv-init b/libexec/rbenv-init index 5c120250..fae07399 100755 --- a/libexec/rbenv-init +++ b/libexec/rbenv-init @@ -86,7 +86,7 @@ commands=(`rbenv commands --sh`) IFS="|" cat < Date: Thu, 9 Feb 2012 16:20:53 +1100 Subject: [PATCH 199/384] Changed doc/README.mdtoc and built README.md and changed nomenclature to 'ruby versions' as requested. --- README.md | 4 ++-- doc/README.mdtoc | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5d08032e..4c0d3400 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ tools that do one thing well. * [2.1.1 Upgrading](#section_2.1.1) * [2.2 Homebrew on Mac OS X](#section_2.2) * [2.3 Neckbeard Configuration](#section_2.3) - * [2.4 Uninstalling Rubies](#section_2.4) + * [2.4 Uninstalling Ruby Versions](#section_2.4) * [3 Usage](#section_3) * [3.1 rbenv global](#section_3.1) * [3.2 rbenv local](#section_3.2) @@ -203,7 +203,7 @@ opposed to this idea. Here's what `rbenv init` actually does: Run `rbenv init -` for yourself to see exactly what happens under the hood. -### 2.4 Uninstalling Rubies +### 2.4 Uninstalling Ruby Versions As time goes on, ruby versions you install will accumulate in your `~/.rbenv/versions` directory. diff --git a/doc/README.mdtoc b/doc/README.mdtoc index 4215127e..0bc1abc8 100644 --- a/doc/README.mdtoc +++ b/doc/README.mdtoc @@ -183,6 +183,15 @@ opposed to this idea. Here's what `rbenv init` actually does: Run `rbenv init -` for yourself to see exactly what happens under the hood. +### Uninstalling Ruby Versions ### + +As time goes on, ruby versions you install will accumulate in your +`~/.rbenv/versions` directory. + +There is no uninstall or remove command in `rbenv`, so removing old +versions is a simple matter of `rm -rf` the directory of the relevant +ruby version you want removed under `~/.rbenv/versions` + ## Usage ## Like `git`, the `rbenv` command delegates to subcommands based on its From d3700dfd703a570d370cc9cb2e01395d8764ac5b Mon Sep 17 00:00:00 2001 From: Gabriel Horner Date: Fri, 23 Mar 2012 16:21:53 -0400 Subject: [PATCH 200/384] help for versions and commands, including their options --- libexec/rbenv-help | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/libexec/rbenv-help b/libexec/rbenv-help index 7204b2a1..e1cbaf57 100755 --- a/libexec/rbenv-help +++ b/libexec/rbenv-help @@ -34,6 +34,12 @@ Some useful rbenv commands are: See 'rbenv help ' for information on a specific command. For full documentation, see: https://github.com/sstephenson/rbenv#readme" ;; +commands) echo "usage: rbenv commands + rbenv commands --sh + rbenv commands --no-sh + +List all rbenv commands." +;; global) echo "usage: rbenv global Sets the global Ruby version. You can override the global version at @@ -65,6 +71,11 @@ project-specific versions and the global version. $(print_set_version)" ;; +versions) echo "usage: rbenv versions + rbenv versions --bare + +Lists all Ruby versions known by rbenv." +;; which) echo "usage: rbenv which Displays the full path to the binary that rbenv will execute when you From 3a94daeaf848211d93b6e83617623e468555c205 Mon Sep 17 00:00:00 2001 From: Alec Chen Date: Mon, 23 Apr 2012 22:11:19 +0800 Subject: [PATCH 201/384] remove "+=" operator to support bash-3.0 --- libexec/rbenv-rehash | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libexec/rbenv-rehash b/libexec/rbenv-rehash index 5757dcfe..eebc4d3c 100755 --- a/libexec/rbenv-rehash +++ b/libexec/rbenv-rehash @@ -85,7 +85,7 @@ shim_variable_name() { if [[ ! "$shim" =~ [^[:alnum:]_-] ]]; then shim="${shim//_/_5f}" shim="${shim//-/_2d}" - result+="$shim" + result="$result$shim" else local length="${#shim}" local char i @@ -93,9 +93,9 @@ shim_variable_name() { for ((i=0; i Date: Sat, 12 May 2012 22:38:56 +0200 Subject: [PATCH 202/384] Fixed broken link to RVM in documentation --- README.md | 4 ++-- doc/README.mdtoc | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 923f1415..e673e28d 100644 --- a/README.md +++ b/README.md @@ -30,8 +30,8 @@ tools that do one thing well. [rbenv-gemset](https://github.com/jamis/rbenv-gemset) plugin. * **Require changes to Ruby libraries for compatibility.** The simplicity of rbenv means as long as it's in your `$PATH`, - [nothing](https://rvm.beginrescueend.com/integration/bundler/) - [else](https://rvm.beginrescueend.com/integration/capistrano/) + [nothing](https://rvm.io/integration/bundler/) + [else](https://rvm.io/integration/capistrano/) needs to know about it. * **Prompt you with warnings when you switch to a project.** Instead of executing arbitrary code, rbenv reads just the version name diff --git a/doc/README.mdtoc b/doc/README.mdtoc index 4efea542..4657a3b9 100644 --- a/doc/README.mdtoc +++ b/doc/README.mdtoc @@ -30,8 +30,8 @@ tools that do one thing well. [rbenv-gemset](https://github.com/jamis/rbenv-gemset) plugin. * **Require changes to Ruby libraries for compatibility.** The simplicity of rbenv means as long as it's in your `$PATH`, - [nothing](https://rvm.beginrescueend.com/integration/bundler/) - [else](https://rvm.beginrescueend.com/integration/capistrano/) + [nothing](https://rvm.io/integration/bundler/) + [else](https://rvm.io/integration/capistrano/) needs to know about it. * **Prompt you with warnings when you switch to a project.** Instead of executing arbitrary code, rbenv reads just the version name From 183c780698f22e573b9a0be2977b2b527e93c17c Mon Sep 17 00:00:00 2001 From: Eric Date: Tue, 28 Aug 2012 12:37:15 -0600 Subject: [PATCH 203/384] Installation Step 1 is a one liner Not a big change, just thought it's always good to make it easier for a beginner --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 923f1415..e40ad271 100644 --- a/README.md +++ b/README.md @@ -92,8 +92,7 @@ easy to fork and contribute any changes back upstream. 1. Check out rbenv into `~/.rbenv`. - $ cd - $ git clone git://github.com/sstephenson/rbenv.git .rbenv + $ git clone git://github.com/sstephenson/rbenv.git ~/.rbenv 2. Add `~/.rbenv/bin` to your `$PATH` for access to the `rbenv` command-line utility. From 02332d78f38d9baef7374841d736331dc5eaff09 Mon Sep 17 00:00:00 2001 From: Brian Olsen Date: Fri, 5 Oct 2012 04:28:25 +0200 Subject: [PATCH 204/384] 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 b745a51f30041ad8258ee50af944d033ca5f072c Mon Sep 17 00:00:00 2001 From: Matt Bridges Date: Sat, 17 Nov 2012 01:57:23 -0600 Subject: [PATCH 205/384] Update README.md Changing Ruby versions references to latest versions to keep somewhat up-to-date. --- README.md | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 923f1415..e80e7bff 100644 --- a/README.md +++ b/README.md @@ -63,11 +63,11 @@ tools that do one thing well. rbenv operates on the per-user directory `~/.rbenv`. Version names in rbenv correspond to subdirectories of `~/.rbenv/versions`. For example, you might have `~/.rbenv/versions/1.8.7-p354` and -`~/.rbenv/versions/1.9.3-rc1`. +`~/.rbenv/versions/1.9.3-p327`. Each version is a working tree with its own binaries, like `~/.rbenv/versions/1.8.7-p354/bin/ruby` and -`~/.rbenv/versions/1.9.3-rc1/bin/irb`. rbenv makes _shim binaries_ +`~/.rbenv/versions/1.9.3-p327/bin/irb`. rbenv makes _shim binaries_ for every such binary across all installed versions of Ruby. These shims are simple wrapper scripts that live in `~/.rbenv/shims` @@ -114,9 +114,9 @@ easy to fork and contribute any changes back upstream. $ exec $SHELL 5. Install Ruby versions into `~/.rbenv/versions`. For example, to - install Ruby 1.9.2-p290, download and unpack the source, then run: + install Ruby 1.9.3-p327, download and unpack the source, then run: - $ ./configure --prefix=$HOME/.rbenv/versions/1.9.2-p290 + $ ./configure --prefix=$HOME/.rbenv/versions/1.9.3-p327 $ make $ make install @@ -124,7 +124,7 @@ easy to fork and contribute any changes back upstream. provides an `rbenv install` command that simplifies the process of installing new Ruby versions to: - $ rbenv install 1.9.2-p290 + $ rbenv install 1.9.3-p327 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, @@ -214,7 +214,7 @@ the version name to the `~/.rbenv/version` file. This version can be overridden by a per-project `.rbenv-version` file, or by setting the `RBENV_VERSION` environment variable. - $ rbenv global 1.9.2-p290 + $ rbenv global 1.9.3-p327 The special version name `system` tells rbenv to use the system Ruby (detected by searching your `$PATH`). @@ -243,7 +243,7 @@ Sets a shell-specific Ruby version by setting the `RBENV_VERSION` environment variable in your shell. This version overrides both project-specific versions and the global version. - $ rbenv shell jruby-1.6.4 + $ rbenv shell jruby-1.7.0 When run without a version number, `rbenv shell` reports the current value of `RBENV_VERSION`. You can also unset the shell version: @@ -255,7 +255,7 @@ the installation instructions) in order to use this command. If you prefer not to use shell integration, you may simply set the `RBENV_VERSION` variable yourself: - $ export RBENV_VERSION=jruby-1.6.4 + $ export RBENV_VERSION=jruby-1.7.0 ### 3.4 rbenv versions @@ -265,8 +265,8 @@ the currently active version. $ rbenv versions 1.8.7-p352 1.9.2-p290 - * 1.9.3-rc1 (set by /Users/sam/.rbenv/global) - jruby-1.6.4 + * 1.9.3-p327 (set by /Users/sam/.rbenv/global) + jruby-1.7.0 rbx-1.2.4 ree-1.8.7-2011.03 @@ -292,15 +292,15 @@ Displays the full path to the binary that rbenv will execute when you run the given command. $ rbenv which irb - /Users/sam/.rbenv/versions/1.9.2-p290/bin/irb + /Users/sam/.rbenv/versions/1.9.3-p327/bin/irb ### 3.8 rbenv whence Lists all Ruby versions with the given command installed. $ rbenv whence rackup - 1.9.3-rc1 - jruby-1.6.4 + 1.9.3-p327 + jruby-1.7.0 ree-1.8.7-2011.03 ## 4 Development From fc3a634e2203b7ffa931dc7e1b85dd76222032af Mon Sep 17 00:00:00 2001 From: Guillermo Iguaran Date: Tue, 11 Dec 2012 15:56:03 -0500 Subject: [PATCH 206/384] Update README: use last version of jruby in examples --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index ccaa7486..5658f237 100644 --- a/README.md +++ b/README.md @@ -242,7 +242,7 @@ Sets a shell-specific Ruby version by setting the `RBENV_VERSION` environment variable in your shell. This version overrides both project-specific versions and the global version. - $ rbenv shell jruby-1.7.0 + $ rbenv shell jruby-1.7.1 When run without a version number, `rbenv shell` reports the current value of `RBENV_VERSION`. You can also unset the shell version: @@ -254,7 +254,7 @@ the installation instructions) in order to use this command. If you prefer not to use shell integration, you may simply set the `RBENV_VERSION` variable yourself: - $ export RBENV_VERSION=jruby-1.7.0 + $ export RBENV_VERSION=jruby-1.7.1 ### 3.4 rbenv versions @@ -265,7 +265,7 @@ the currently active version. 1.8.7-p352 1.9.2-p290 * 1.9.3-p327 (set by /Users/sam/.rbenv/global) - jruby-1.7.0 + jruby-1.7.1 rbx-1.2.4 ree-1.8.7-2011.03 @@ -299,7 +299,7 @@ Lists all Ruby versions with the given command installed. $ rbenv whence rackup 1.9.3-p327 - jruby-1.7.0 + jruby-1.7.1 ree-1.8.7-2011.03 ## 4 Development From 2df165c49e892e2133624af93b23bbb0e1dd828a Mon Sep 17 00:00:00 2001 From: Guillermo Iguaran Date: Tue, 11 Dec 2012 16:06:02 -0500 Subject: [PATCH 207/384] Sync doc/README.mdtoc with the actual README All the changes to documentation should be done in doc/README.mdtoc --- doc/README.mdtoc | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/doc/README.mdtoc b/doc/README.mdtoc index 4efea542..9ea0ca67 100644 --- a/doc/README.mdtoc +++ b/doc/README.mdtoc @@ -44,11 +44,11 @@ tools that do one thing well. rbenv operates on the per-user directory `~/.rbenv`. Version names in rbenv correspond to subdirectories of `~/.rbenv/versions`. For example, you might have `~/.rbenv/versions/1.8.7-p354` and -`~/.rbenv/versions/1.9.3-rc1`. +`~/.rbenv/versions/1.9.3-p327`. Each version is a working tree with its own binaries, like `~/.rbenv/versions/1.8.7-p354/bin/ruby` and -`~/.rbenv/versions/1.9.3-rc1/bin/irb`. rbenv makes _shim binaries_ +`~/.rbenv/versions/1.9.3-p327/bin/irb`. rbenv makes _shim binaries_ for every such binary across all installed versions of Ruby. These shims are simple wrapper scripts that live in `~/.rbenv/shims` @@ -73,8 +73,7 @@ easy to fork and contribute any changes back upstream. 1. Check out rbenv into `~/.rbenv`. - $ cd - $ git clone git://github.com/sstephenson/rbenv.git .rbenv + $ git clone git://github.com/sstephenson/rbenv.git ~/.rbenv 2. Add `~/.rbenv/bin` to your `$PATH` for access to the `rbenv` command-line utility. @@ -95,9 +94,9 @@ easy to fork and contribute any changes back upstream. $ exec $SHELL 5. Install Ruby versions into `~/.rbenv/versions`. For example, to - install Ruby 1.9.2-p290, download and unpack the source, then run: + install Ruby 1.9.3-p327, download and unpack the source, then run: - $ ./configure --prefix=$HOME/.rbenv/versions/1.9.2-p290 + $ ./configure --prefix=$HOME/.rbenv/versions/1.9.3-p327 $ make $ make install @@ -105,7 +104,7 @@ easy to fork and contribute any changes back upstream. provides an `rbenv install` command that simplifies the process of installing new Ruby versions to: - $ rbenv install 1.9.2-p290 + $ rbenv install 1.9.3-p327 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, @@ -195,7 +194,7 @@ the version name to the `~/.rbenv/version` file. This version can be overridden by a per-project `.rbenv-version` file, or by setting the `RBENV_VERSION` environment variable. - $ rbenv global 1.9.2-p290 + $ rbenv global 1.9.3-p327 The special version name `system` tells rbenv to use the system Ruby (detected by searching your `$PATH`). @@ -224,7 +223,7 @@ Sets a shell-specific Ruby version by setting the `RBENV_VERSION` environment variable in your shell. This version overrides both project-specific versions and the global version. - $ rbenv shell jruby-1.6.4 + $ rbenv shell jruby-1.7.1 When run without a version number, `rbenv shell` reports the current value of `RBENV_VERSION`. You can also unset the shell version: @@ -236,7 +235,7 @@ the installation instructions) in order to use this command. If you prefer not to use shell integration, you may simply set the `RBENV_VERSION` variable yourself: - $ export RBENV_VERSION=jruby-1.6.4 + $ export RBENV_VERSION=jruby-1.7.1 ### rbenv versions ### @@ -246,8 +245,8 @@ the currently active version. $ rbenv versions 1.8.7-p352 1.9.2-p290 - * 1.9.3-rc1 (set by /Users/sam/.rbenv/global) - jruby-1.6.4 + * 1.9.3-p327 (set by /Users/sam/.rbenv/global) + jruby-1.7.1 rbx-1.2.4 ree-1.8.7-2011.03 @@ -273,15 +272,15 @@ Displays the full path to the binary that rbenv will execute when you run the given command. $ rbenv which irb - /Users/sam/.rbenv/versions/1.9.2-p290/bin/irb + /Users/sam/.rbenv/versions/1.9.3-p327/bin/irb ### rbenv whence ### Lists all Ruby versions with the given command installed. $ rbenv whence rackup - 1.9.3-rc1 - jruby-1.6.4 + 1.9.3-p327 + jruby-1.7.1 ree-1.8.7-2011.03 ## Development ## From 47c8a0e0b84c741770e96500046094d14f65f93c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohnic=CC=81?= Date: Mon, 8 Oct 2012 14:48:31 +0200 Subject: [PATCH 208/384] fix `versions` in case current version doesn't exist `rbenv-versions` tries to read the current version to display a marker next to it, but if that fails the whole script aborts. This change makes it so that the failures from `rbenv-version-name` are tolerated. It also makes the `--bare` mode never call it in the first place, because it doesn't need to display a marker. --- libexec/rbenv-versions | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/libexec/rbenv-versions b/libexec/rbenv-versions index 2fb8fc07..2a762f24 100755 --- a/libexec/rbenv-versions +++ b/libexec/rbenv-versions @@ -2,24 +2,22 @@ set -e [ -n "$RBENV_DEBUG" ] && set -x -RBENV_VERSION_NAME="$(rbenv-version-name)" - if [ "$1" = "--bare" ]; then hit_prefix="" miss_prefix="" - print_version="$RBENV_VERSION_NAME" + current_version="" else hit_prefix="* " miss_prefix=" " - print_version="$(rbenv-version)" + current_version="$(rbenv-version-name || true)" fi for path in "${RBENV_ROOT}/versions/"*; do if [ -d "$path" ]; then version="${path##*/}" - if [ "$version" == "$RBENV_VERSION_NAME" ]; then - echo "${hit_prefix}${print_version}" + if [ "$version" == "$current_version" ]; then + echo "${hit_prefix}$(rbenv-version)" else echo "${miss_prefix}${version}" fi From 0ff3ca8a1252fb8d107d9186da2d8fed9e5c211d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohnic=CC=81?= Date: Mon, 8 Oct 2012 14:47:52 +0200 Subject: [PATCH 209/384] fix obsolete usage instruction --- libexec/rbenv-version-file-write | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libexec/rbenv-version-file-write b/libexec/rbenv-version-file-write index 7c0fc7db..def9465a 100755 --- a/libexec/rbenv-version-file-write +++ b/libexec/rbenv-version-file-write @@ -6,7 +6,7 @@ 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 + echo "usage: rbenv version-file-write FILENAME VERSION" >&2 exit 1 fi From 7f1aefa09bdf7dd03cabc693e6250ae6748ed9e7 Mon Sep 17 00:00:00 2001 From: Javier Candeira Date: Mon, 10 Dec 2012 09:53:57 +1100 Subject: [PATCH 210/384] fix install instructions for ubuntu (using version 12.04, but should work for all versions) --- README.md | 14 +++++++++++--- doc/README.mdtoc | 14 +++++++++++--- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 79852d6a..5fca4028 100644 --- a/README.md +++ b/README.md @@ -102,16 +102,24 @@ easy to fork and contribute any changes back upstream. **Zsh note**: Modify your `~/.zshenv` file instead of `~/.bash_profile`. + **Ubuntu note**: Ubuntu uses `~/.profile` for enabling certain path + changes. This file won't be read if you create a `~/.bash_profile`. + Therefore, it's recommended that you add this line and the one in + point 3 below to your `~/.profile`. This has the added advantage + of working under both bash and zsh. + 3. Add rbenv init to your shell to enable shims and autocompletion. $ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile **Zsh note**: Modify your `~/.zshenv` file instead of `~/.bash_profile`. + + **Ubuntu note**: Same as Ubuntu note for point 2 above. -4. Restart your shell so the path changes take effect. You can now - begin using rbenv. +4. Restart your shell as a login shell so the path changes take effect. + You can now begin using rbenv. - $ exec $SHELL + $ exec $SHELL -l 5. Install Ruby versions into `~/.rbenv/versions`. For example, to install Ruby 1.9.3-p327, download and unpack the source, then run: diff --git a/doc/README.mdtoc b/doc/README.mdtoc index ac2c4bdf..12802a67 100644 --- a/doc/README.mdtoc +++ b/doc/README.mdtoc @@ -82,16 +82,24 @@ easy to fork and contribute any changes back upstream. **Zsh note**: Modify your `~/.zshenv` file instead of `~/.bash_profile`. + **Ubuntu note**: Ubuntu uses `~/.profile` for enabling certain path + changes. This file won't be read if you create a `~/.bash_profile`. + Therefore, it's recommended that you add this line and the one in + point 3 below to your `~/.profile`. This has the added advantage + of working under both bash and zsh. + 3. Add rbenv init to your shell to enable shims and autocompletion. $ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile **Zsh note**: Modify your `~/.zshenv` file instead of `~/.bash_profile`. + + **Ubuntu note**: Same as Ubuntu note for point 2 above. -4. Restart your shell so the path changes take effect. You can now - begin using rbenv. +4. Restart your shell as a login shell so the path changes take effect. + You can now begin using rbenv. - $ exec $SHELL + $ exec $SHELL -l 5. Install Ruby versions into `~/.rbenv/versions`. For example, to install Ruby 1.9.3-p327, download and unpack the source, then run: From da562ad74cf00f66b92e33562a8a062ceb6085e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohnic=CC=81?= Date: Wed, 12 Dec 2012 02:43:48 +0100 Subject: [PATCH 211/384] replace build system with generated table of contents Gets rid of `doc/README.mdtoc` and its build script. Since GitHub.com renders anchors for each heading, all we have to do is put a simple table of contents into `README.md` itself, and everything will get linked up nicely. Pros of this approach: * We don't have to point out to people not to edit `README.md` anymore * We don't have to run the build script each time README gets edited Cons of this change: * The "chapter" numbers are lost. They were silly anyway. `doc/mdtoc` renders a Markdown table of contents for a Markdown file. `doc/filter-toc` filters that down to only headings after ToC. This script can be used to easily insert ToC into the current document when editing `README.md` with, e.g., Vim: :read !doc/filter-toc % --- README.md | 76 ++++----- doc/README.mdtoc | 411 ----------------------------------------------- doc/build | 4 - doc/filter-toc | 4 + doc/mdtoc | 33 ++++ doc/mdtoc.rb | 82 ---------- 6 files changed, 75 insertions(+), 535 deletions(-) delete mode 100644 doc/README.mdtoc delete mode 100755 doc/build create mode 100755 doc/filter-toc create mode 100755 doc/mdtoc delete mode 100644 doc/mdtoc.rb diff --git a/README.md b/README.md index 5fca4028..c35ef65c 100644 --- a/README.md +++ b/README.md @@ -39,27 +39,27 @@ tools that do one thing well. ## Table of Contents - * [1 How It Works](#section_1) - * [2 Installation](#section_2) - * [2.1 Basic GitHub Checkout](#section_2.1) - * [2.1.1 Upgrading](#section_2.1.1) - * [2.2 Homebrew on Mac OS X](#section_2.2) - * [2.3 Neckbeard Configuration](#section_2.3) - * [2.4 Uninstalling Ruby Versions](#section_2.4) - * [3 Usage](#section_3) - * [3.1 rbenv global](#section_3.1) - * [3.2 rbenv local](#section_3.2) - * [3.3 rbenv shell](#section_3.3) - * [3.4 rbenv versions](#section_3.4) - * [3.5 rbenv version](#section_3.5) - * [3.6 rbenv rehash](#section_3.6) - * [3.7 rbenv which](#section_3.7) - * [3.8 rbenv whence](#section_3.8) - * [4 Development](#section_4) - * [4.1 Version History](#section_4.1) - * [4.2 License](#section_4.2) +* [How It Works](#how-it-works) +* [Installation](#installation) + * [Basic GitHub Checkout](#basic-github-checkout) + * [Upgrading](#upgrading) + * [Homebrew on Mac OS X](#homebrew-on-mac-os-x) + * [Neckbeard Configuration](#neckbeard-configuration) + * [Uninstalling Ruby Versions](#uninstalling-ruby-versions) +* [Usage](#usage) + * [rbenv global](#rbenv-global) + * [rbenv local](#rbenv-local) + * [rbenv shell](#rbenv-shell) + * [rbenv versions](#rbenv-versions) + * [rbenv version](#rbenv-version) + * [rbenv rehash](#rbenv-rehash) + * [rbenv which](#rbenv-which) + * [rbenv whence](#rbenv-whence) +* [Development](#development) + * [Version History](#version-history) + * [License](#license) -## 1 How It Works +## How It Works ## rbenv operates on the per-user directory `~/.rbenv`. Version names in rbenv correspond to subdirectories of `~/.rbenv/versions`. For @@ -79,14 +79,14 @@ and then execute the corresponding binary. Because of the simplicity of the shim approach, all you need to use rbenv is `~/.rbenv/shims` in your `$PATH`. -## 2 Installation +## Installation ## **Compatibility note**: rbenv is _incompatible_ with rvm. Things will appear to work until you try to install a gem. The problem is that rvm actually overrides the `gem` command with a shell function! Please remove any references to rvm before using rbenv. -### 2.1 Basic GitHub Checkout +### Basic GitHub Checkout ### This will get you going with the latest version of rbenv and make it easy to fork and contribute any changes back upstream. @@ -140,7 +140,7 @@ easy to fork and contribute any changes back upstream. $ rbenv rehash -#### 2.1.1 Upgrading +#### Upgrading #### If you've installed rbenv using the instructions above, you can upgrade your installation at any time using git. @@ -162,7 +162,7 @@ tag: v0.2.0 $ git checkout v0.2.0 -### 2.2 Homebrew on Mac OS X +### Homebrew on Mac OS X ### You can also install rbenv using the [Homebrew](http://mxcl.github.com/homebrew/) package manager on Mac OS @@ -178,7 +178,7 @@ Afterwards you'll still need to add `eval "$(rbenv init -)"` to your profile as stated in the caveats. You'll only ever have to do this once. -### 2.3 Neckbeard Configuration +### Neckbeard Configuration ### Skip this section unless you must know what every line in your shell profile is doing. @@ -210,7 +210,7 @@ opposed to this idea. Here's what `rbenv init` actually does: Run `rbenv init -` for yourself to see exactly what happens under the hood. -### 2.4 Uninstalling Ruby Versions +### Uninstalling Ruby Versions ### As time goes on, ruby versions you install will accumulate in your `~/.rbenv/versions` directory. @@ -219,12 +219,12 @@ There is no uninstall or remove command in `rbenv`, so removing old versions is a simple matter of `rm -rf` the directory of the relevant ruby version you want removed under `~/.rbenv/versions` -## 3 Usage +## Usage ## Like `git`, the `rbenv` command delegates to subcommands based on its first argument. The most common subcommands are: -### 3.1 rbenv global +### rbenv global ### Sets the global version of Ruby to be used in all shells by writing the version name to the `~/.rbenv/version` file. This version can be @@ -239,7 +239,7 @@ The special version name `system` tells rbenv to use the system Ruby When run without a version number, `rbenv global` reports the currently configured global version. -### 3.2 rbenv local +### rbenv local ### Sets a local per-project Ruby version by writing the version name to an `.rbenv-version` file in the current directory. This version @@ -254,7 +254,7 @@ configured local version. You can also unset the local version: $ rbenv local --unset -### 3.3 rbenv shell +### rbenv shell ### Sets a shell-specific Ruby version by setting the `RBENV_VERSION` environment variable in your shell. This version overrides both @@ -274,7 +274,7 @@ prefer not to use shell integration, you may simply set the $ export RBENV_VERSION=jruby-1.7.1 -### 3.4 rbenv versions +### rbenv versions ### Lists all Ruby versions known to rbenv, and shows an asterisk next to the currently active version. @@ -287,7 +287,7 @@ the currently active version. rbx-1.2.4 ree-1.8.7-2011.03 -### 3.5 rbenv version +### rbenv version ### Displays the currently active Ruby version, along with information on how it was set. @@ -295,7 +295,7 @@ how it was set. $ rbenv version 1.8.7-p352 (set by /Volumes/37signals/basecamp/.rbenv-version) -### 3.6 rbenv rehash +### rbenv rehash ### Installs shims for all Ruby binaries known to rbenv (i.e., `~/.rbenv/versions/*/bin/*`). Run this command after you install a new @@ -303,7 +303,7 @@ version of Ruby, or install a gem that provides binaries. $ rbenv rehash -### 3.7 rbenv which +### rbenv which ### Displays the full path to the binary that rbenv will execute when you run the given command. @@ -311,7 +311,7 @@ run the given command. $ rbenv which irb /Users/sam/.rbenv/versions/1.9.3-p327/bin/irb -### 3.8 rbenv whence +### rbenv whence ### Lists all Ruby versions with the given command installed. @@ -320,7 +320,7 @@ Lists all Ruby versions with the given command installed. jruby-1.7.1 ree-1.8.7-2011.03 -## 4 Development +## Development ## The rbenv source code is [hosted on GitHub](https://github.com/sstephenson/rbenv). It's clean, modular, @@ -329,7 +329,7 @@ and easy to understand, even if you're not a shell hacker. Please feel free to submit pull requests and file bugs on the [issue tracker](https://github.com/sstephenson/rbenv/issues). -### 4.1 Version History +### Version History ### **0.3.0** (December 25, 2011) @@ -405,7 +405,7 @@ tracker](https://github.com/sstephenson/rbenv/issues). * Initial public release. -### 4.2 License +### License ### (The MIT license) diff --git a/doc/README.mdtoc b/doc/README.mdtoc deleted file mode 100644 index 12802a67..00000000 --- a/doc/README.mdtoc +++ /dev/null @@ -1,411 +0,0 @@ -# Simple Ruby Version Management: rbenv - -rbenv lets you easily switch between multiple versions of Ruby. It's -simple, unobtrusive, and follows the UNIX tradition of single-purpose -tools that do one thing well. - - - -### rbenv _does…_ - -* Let you **change the global Ruby version** on a per-user basis. -* Provide support for **per-project Ruby versions**. -* Allow you to **override the Ruby version** with an environment - variable. - -### In contrast with rvm, rbenv _does not…_ - -* **Need to be loaded into your shell.** Instead, rbenv's shim - approach works by adding a directory to your `$PATH`. -* **Override shell commands like `cd`.** That's dangerous and - error-prone. -* **Have a configuration file.** There's nothing to configure except - which version of Ruby you want to use. -* **Install Ruby.** You can build and install Ruby yourself, or use - [ruby-build](https://github.com/sstephenson/ruby-build) to - automate the process. -* **Manage gemsets.** [Bundler](http://gembundler.com/) is a better - way to manage application dependencies. If you have projects that - are not yet using Bundler you can install the - [rbenv-gemset](https://github.com/jamis/rbenv-gemset) plugin. -* **Require changes to Ruby libraries for compatibility.** The - simplicity of rbenv means as long as it's in your `$PATH`, - [nothing](https://rvm.io/integration/bundler/) - [else](https://rvm.io/integration/capistrano/) - needs to know about it. -* **Prompt you with warnings when you switch to a project.** Instead - of executing arbitrary code, rbenv reads just the version name - from each project. There's nothing to "trust." - -## Table of Contents - -## How It Works ## - -rbenv operates on the per-user directory `~/.rbenv`. Version names in -rbenv correspond to subdirectories of `~/.rbenv/versions`. For -example, you might have `~/.rbenv/versions/1.8.7-p354` and -`~/.rbenv/versions/1.9.3-p327`. - -Each version is a working tree with its own binaries, like -`~/.rbenv/versions/1.8.7-p354/bin/ruby` and -`~/.rbenv/versions/1.9.3-p327/bin/irb`. rbenv makes _shim binaries_ -for every such binary across all installed versions of Ruby. - -These shims are simple wrapper scripts that live in `~/.rbenv/shims` -and detect which Ruby version you want to use. They insert the -directory for the selected version at the beginning of your `$PATH` -and then execute the corresponding binary. - -Because of the simplicity of the shim approach, all you need to use -rbenv is `~/.rbenv/shims` in your `$PATH`. - -## Installation ## - -**Compatibility note**: rbenv is _incompatible_ with rvm. Things will - appear to work until you try to install a gem. The problem is that - rvm actually overrides the `gem` command with a shell function! - Please remove any references to rvm before using rbenv. - -### Basic GitHub Checkout ### - -This will get you going with the latest version of rbenv and make it -easy to fork and contribute any changes back upstream. - -1. Check out rbenv into `~/.rbenv`. - - $ git clone git://github.com/sstephenson/rbenv.git ~/.rbenv - -2. Add `~/.rbenv/bin` to your `$PATH` for access to the `rbenv` - command-line utility. - - $ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile - - **Zsh note**: Modify your `~/.zshenv` file instead of `~/.bash_profile`. - - **Ubuntu note**: Ubuntu uses `~/.profile` for enabling certain path - changes. This file won't be read if you create a `~/.bash_profile`. - Therefore, it's recommended that you add this line and the one in - point 3 below to your `~/.profile`. This has the added advantage - of working under both bash and zsh. - -3. Add rbenv init to your shell to enable shims and autocompletion. - - $ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile - - **Zsh note**: Modify your `~/.zshenv` file instead of `~/.bash_profile`. - - **Ubuntu note**: Same as Ubuntu note for point 2 above. - -4. Restart your shell as a login shell so the path changes take effect. - You can now begin using rbenv. - - $ exec $SHELL -l - -5. Install Ruby versions into `~/.rbenv/versions`. For example, to - install Ruby 1.9.3-p327, download and unpack the source, then run: - - $ ./configure --prefix=$HOME/.rbenv/versions/1.9.3-p327 - $ make - $ make install - - The [ruby-build](https://github.com/sstephenson/ruby-build) project - provides an `rbenv install` command that simplifies the process of - installing new Ruby versions to: - - $ rbenv install 1.9.3-p327 - -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). - - $ rbenv rehash - -#### Upgrading #### - -If you've installed rbenv using the instructions above, you can -upgrade your installation at any time using git. - -To upgrade to the latest development version of rbenv, use `git pull`: - - $ cd ~/.rbenv - $ git pull - -To upgrade to a specific release of rbenv, check out the corresponding -tag: - - $ cd ~/.rbenv - $ git fetch - $ git tag - v0.1.0 - v0.1.1 - v0.1.2 - v0.2.0 - $ git checkout v0.2.0 - -### Homebrew on Mac OS X ### - -You can also install rbenv using the -[Homebrew](http://mxcl.github.com/homebrew/) package manager on Mac OS -X. - - $ brew update - $ brew install rbenv - $ brew install ruby-build - -The same commands can be used for upgrading. - -Afterwards you'll still need to add `eval "$(rbenv init -)"` to your -profile as stated in the caveats. You'll only ever have to do this -once. - -### Neckbeard Configuration ### - -Skip this section unless you must know what every line in your shell -profile is doing. - -`rbenv init` is the only command that crosses the line of loading -extra commands into your shell. Coming from rvm, some of you might be -opposed to this idea. Here's what `rbenv init` actually does: - -1. Sets up your shims path. This is the only requirement for rbenv to - function properly. You can do this by hand by prepending - `~/.rbenv/shims` to your `$PATH`. - -2. Installs autocompletion. This is entirely optional but pretty - useful. Sourcing `~/.rbenv/completions/rbenv.bash` will set that - up. There is also a `~/.rbenv/completions/rbenv.zsh` for Zsh - users. - -3. Rehashes shims. From time to time you'll need to rebuild your - shim files. Doing this on init makes sure everything is up to - date. You can always run `rbenv rehash` manually. - -4. Installs the sh dispatcher. This bit is also optional, but allows - rbenv and plugins to change variables in your current shell, making - commands like `rbenv shell` possible. The sh dispatcher doesn't do - anything crazy like override `cd` or hack your shell prompt, but if - for some reason you need `rbenv` to be a real script rather than a - shell function, you can safely skip it. - -Run `rbenv init -` for yourself to see exactly what happens under the -hood. - -### Uninstalling Ruby Versions ### - -As time goes on, ruby versions you install will accumulate in your -`~/.rbenv/versions` directory. - -There is no uninstall or remove command in `rbenv`, so removing old -versions is a simple matter of `rm -rf` the directory of the relevant -ruby version you want removed under `~/.rbenv/versions` - -## Usage ## - -Like `git`, the `rbenv` command delegates to subcommands based on its -first argument. The most common subcommands are: - -### rbenv global ### - -Sets the global version of Ruby to be used in all shells by writing -the version name to the `~/.rbenv/version` file. This version can be -overridden by a per-project `.rbenv-version` file, or by setting the -`RBENV_VERSION` environment variable. - - $ rbenv global 1.9.3-p327 - -The special version name `system` tells rbenv to use the system Ruby -(detected by searching your `$PATH`). - -When run without a version number, `rbenv global` reports the -currently configured global version. - -### rbenv local ### - -Sets a local per-project Ruby version by writing the version name to -an `.rbenv-version` file in the current directory. This version -overrides the global, and can be overridden itself by setting the -`RBENV_VERSION` environment variable or with the `rbenv shell` -command. - - $ rbenv local rbx-1.2.4 - -When run without a version number, `rbenv local` reports the currently -configured local version. You can also unset the local version: - - $ rbenv local --unset - -### rbenv shell ### - -Sets a shell-specific Ruby version by setting the `RBENV_VERSION` -environment variable in your shell. This version overrides both -project-specific versions and the global version. - - $ rbenv shell jruby-1.7.1 - -When run without a version number, `rbenv shell` reports the current -value of `RBENV_VERSION`. You can also unset the shell version: - - $ rbenv shell --unset - -Note that you'll need rbenv's shell integration enabled (step 3 of -the installation instructions) in order to use this command. If you -prefer not to use shell integration, you may simply set the -`RBENV_VERSION` variable yourself: - - $ export RBENV_VERSION=jruby-1.7.1 - -### rbenv versions ### - -Lists all Ruby versions known to rbenv, and shows an asterisk next to -the currently active version. - - $ rbenv versions - 1.8.7-p352 - 1.9.2-p290 - * 1.9.3-p327 (set by /Users/sam/.rbenv/global) - jruby-1.7.1 - rbx-1.2.4 - ree-1.8.7-2011.03 - -### rbenv version ### - -Displays the currently active Ruby version, along with information on -how it was set. - - $ rbenv version - 1.8.7-p352 (set by /Volumes/37signals/basecamp/.rbenv-version) - -### rbenv rehash ### - -Installs shims for all Ruby binaries known to rbenv (i.e., -`~/.rbenv/versions/*/bin/*`). Run this command after you install a new -version of Ruby, or install a gem that provides binaries. - - $ rbenv rehash - -### rbenv which ### - -Displays the full path to the binary that rbenv will execute when you -run the given command. - - $ rbenv which irb - /Users/sam/.rbenv/versions/1.9.3-p327/bin/irb - -### rbenv whence ### - -Lists all Ruby versions with the given command installed. - - $ rbenv whence rackup - 1.9.3-p327 - jruby-1.7.1 - ree-1.8.7-2011.03 - -## Development ## - -The rbenv source code is [hosted on -GitHub](https://github.com/sstephenson/rbenv). It's clean, modular, -and easy to understand, even if you're not a shell hacker. - -Please feel free to submit pull requests and file bugs on the [issue -tracker](https://github.com/sstephenson/rbenv/issues). - -### Version History ### - -**0.3.0** (December 25, 2011) - -* Added an `rbenv root` command which prints the value of - `$RBENV_ROOT`, or the default root directory if it's unset. -* Clarified Zsh installation instructions in the readme. -* Removed some redundant code in `rbenv rehash`. -* Fixed an issue with calling `readlink` for paths with spaces. -* Changed Zsh initialization code to install completion hooks only for - interactive shells. -* Added preliminary support for ksh. -* `rbenv rehash` creates or removes shims only when necessary instead - of removing and re-creating all shims on each invocation. -* Fixed that `RBENV_DIR`, when specified, would be incorrectly - expanded to its parent directory. -* Removed the deprecated `set-default` and `set-local` commands. -* Added a `--no-rehash` option to `rbenv init` for skipping the - automatic rehash when opening a new shell. - -**0.2.1** (October 1, 2011) - -* Changed the `rbenv` command to ensure that `RBENV_DIR` is always an - absolute path. This fixes an issue where Ruby scripts using the - `ruby-local-exec` wrapper would go into an infinite loop when - invoked with a relative path from the command line. - -**0.2.0** (September 28, 2011) - -* Renamed `rbenv set-default` to `rbenv global` and `rbenv set-local` - to `rbenv local`. The `set-` commands are deprecated and will be - removed in the next major release. -* rbenv now uses `greadlink` on Solaris. -* Added a `ruby-local-exec` command which can be used in shebangs in - place of `#!/usr/bin/env ruby` to properly set the project-specific - Ruby version regardless of current working directory. -* Fixed an issue with `rbenv rehash` when no binaries are present. -* Added support for `rbenv-sh-*` commands, which run inside the - current shell instead of in a child process. -* Added an `rbenv shell` command for conveniently setting the - `$RBENV_VERSION` environment variable. -* Added support for storing rbenv versions and shims in directories - other than `~/.rbenv` with the `$RBENV_ROOT` environment variable. -* Added support for debugging rbenv via `set -x` when the - `$RBENV_DEBUG` environment variable is set. -* Refactored the autocompletion system so that completions are now - built-in to each command and shared between bash and Zsh. -* Added support for plugin bundles in `~/.rbenv/plugins` as documented - in [issue #102](https://github.com/sstephenson/rbenv/pull/102). -* Added `/usr/local/etc/rbenv.d` to the list of directories searched - for rbenv hooks. -* Added support for an `$RBENV_DIR` environment variable which - defaults to the current working directory for specifying where rbenv - searches for local version files. - -**0.1.2** (August 16, 2011) - -* Fixed rbenv to be more resilient against nonexistent entries in - `$PATH`. -* Made the `rbenv rehash` command operate atomically. -* Modified the `rbenv init` script to automatically run `rbenv - rehash` so that shims are recreated whenever a new shell is opened. -* Added initial support for Zsh autocompletion. -* Removed the dependency on egrep for reading version files. - -**0.1.1** (August 14, 2011) - -* Fixed a syntax error in the `rbenv help` command. -* Removed `-e` from the shebang in favor of `set -e` at the top of - each file for compatibility with operating systems that do not - support more than one argument in the shebang. - -**0.1.0** (August 11, 2011) - -* Initial public release. - -### License ### - -(The MIT license) - -Copyright (c) 2011 Sam Stephenson - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/doc/build b/doc/build deleted file mode 100755 index 3d542d44..00000000 --- a/doc/build +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh -e - -ruby mdtoc.rb README.mdtoc > ../README.md - diff --git a/doc/filter-toc b/doc/filter-toc new file mode 100755 index 00000000..761288be --- /dev/null +++ b/doc/filter-toc @@ -0,0 +1,4 @@ +#!/bin/bash +# Render Markdown ToC with only headings appearing after "Table of Contents" +dir="$(dirname "$0")" +"$dir"/mdtoc "$1" | sed -n '/table-of-contents/,$p' | grep -v table-of-contents diff --git a/doc/mdtoc b/doc/mdtoc new file mode 100755 index 00000000..5d635542 --- /dev/null +++ b/doc/mdtoc @@ -0,0 +1,33 @@ +#!/usr/bin/env ruby +require 'escape_utils' + +start_at_level = 2 + +headers = Hash.new(0) + +anchor = lambda { |title| + href = title.downcase + href.gsub!(/[^\w\- ]/, '') # remove punctuation + href.gsub!(' ', '-') # replace spaces with dash + href = EscapeUtils.escape_uri(href) # escape extended UTF-8 chars + + uniq = (headers[href] > 0) ? "-#{headers[href]}" : '' + headers[href] += 1 + + href + uniq +} + +ARGF.each_line do |line| + if line =~ /^(#+) (.+?)#*$/ + level = $1.size + next if level < start_at_level + title = $2.strip + href = anchor.call title + + puts "%s* [%s](#%s)" % [ + ' ' * (level - start_at_level), + title, + href + ] + end +end diff --git a/doc/mdtoc.rb b/doc/mdtoc.rb deleted file mode 100644 index 3c5a1735..00000000 --- a/doc/mdtoc.rb +++ /dev/null @@ -1,82 +0,0 @@ -#!/usr/bin/env ruby - -# A little Markdown filter that scans your document for headings, -# numbers them, adds anchors, and inserts a table of contents. -# -# To use it, make sure the headings you want numbered and linked are -# in this format: -# -# ### Title ### -# -# I.e. they must have an equal number of octothorpes around the title -# text. (In Markdown, `#` means `h1`, `##` means `h2`, and so on.) -# The table of contents will be inserted before the first such -# heading. -# -# Released into the public domain. -# Sam Stephenson -# 2011-04-30 - -def mdtoc(markdown) - titles = [] - lines = markdown.split($/) - start = nil - - # First pass: Scan the Markdown source looking for titles of the - # format: `### Title ###`. Record the line number, header level - # (number of octothorpes), and text of each matching title. - lines.each_with_index do |line, line_no| - if line.match(/^(\#{1,6})\s+(.+?)\s+\1$/) - titles << [line_no, $1.length, $2] - start ||= line_no - end - end - - last_section = nil - last_level = nil - - # Second pass: Iterate over all matched titles and compute their - # corresponding section numbers. Then replace the titles with - # annotated anchors. - titles.each do |title_info| - line_no, level, text = title_info - - if last_section - section = last_section.dup - - if last_level < level - section << 1 - else - (last_level - level).times { section.pop } - section[-1] += 1 - end - else - section = [1] - end - - name = section.join(".") - lines[line_no] = %(#{"#" * level} #{name} #{text}) - - title_info << section - last_section = section - last_level = level - end - - # Third pass: Iterate over matched titles once more to produce the - # table of contents. Then insert it immediately above the first - # matched title. - if start - toc = titles.map do |(line_no, level, text, section)| - name = section.join(".") - %(#{" " * (section.length * 3)}* [#{name} #{text}](#section_#{name})) - end + [""] - - lines.insert(start, *toc) - end - - lines.join("\n") -end - -if __FILE__ == $0 - puts mdtoc($<.read) -end From 0a9e2baef14b6838d886d412f426358f55076d6c Mon Sep 17 00:00:00 2001 From: Joe Atzberger Date: Tue, 11 Dec 2012 20:35:30 -0500 Subject: [PATCH 212/384] fix documentation about manually compiling Ruby ./configure doesn't exist by default in repo: use autoconf to create it. --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c35ef65c..8f9c896f 100644 --- a/README.md +++ b/README.md @@ -122,8 +122,10 @@ easy to fork and contribute any changes back upstream. $ exec $SHELL -l 5. Install Ruby versions into `~/.rbenv/versions`. For example, to - install Ruby 1.9.3-p327, download and unpack the source, then run: + install Ruby 1.9.2-p327, download and unpack the [source](https://github.com/ruby/ruby), + then run: + $ [ -f ./configure ] || autoconf $ ./configure --prefix=$HOME/.rbenv/versions/1.9.3-p327 $ make $ make install From 349236c932f8c2ef5f7a9ee90fbb07f92558a02f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohnic=CC=81?= Date: Wed, 12 Dec 2012 23:46:10 +0100 Subject: [PATCH 213/384] tweak docs & add syntax highlighting to instructions --- README.md | 105 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 61 insertions(+), 44 deletions(-) diff --git a/README.md b/README.md index 8f9c896f..9b371758 100644 --- a/README.md +++ b/README.md @@ -22,8 +22,7 @@ tools that do one thing well. * **Have a configuration file.** There's nothing to configure except which version of Ruby you want to use. * **Install Ruby.** You can build and install Ruby yourself, or use - [ruby-build](https://github.com/sstephenson/ruby-build) to - automate the process. + [ruby-build][] to automate the process. * **Manage gemsets.** [Bundler](http://gembundler.com/) is a better way to manage application dependencies. If you have projects that are not yet using Bundler you can install the @@ -76,9 +75,6 @@ and detect which Ruby version you want to use. They insert the directory for the selected version at the beginning of your `$PATH` and then execute the corresponding binary. -Because of the simplicity of the shim approach, all you need to use -rbenv is `~/.rbenv/shims` in your `$PATH`. - ## Installation ## **Compatibility note**: rbenv is _incompatible_ with rvm. Things will @@ -86,6 +82,9 @@ rbenv is `~/.rbenv/shims` in your `$PATH`. rvm actually overrides the `gem` command with a shell function! Please remove any references to rvm before using rbenv. +If you're on Mac OS X, consider +[installing with Homebrew](#homebrew-on-mac-os-x). + ### Basic GitHub Checkout ### This will get you going with the latest version of rbenv and make it @@ -93,12 +92,16 @@ easy to fork and contribute any changes back upstream. 1. Check out rbenv into `~/.rbenv`. - $ git clone git://github.com/sstephenson/rbenv.git ~/.rbenv + ~~~ sh + $ git clone git://github.com/sstephenson/rbenv.git ~/.rbenv + ~~~ 2. Add `~/.rbenv/bin` to your `$PATH` for access to the `rbenv` command-line utility. - $ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile + ~~~ sh + $ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile + ~~~ **Zsh note**: Modify your `~/.zshenv` file instead of `~/.bash_profile`. @@ -108,9 +111,11 @@ easy to fork and contribute any changes back upstream. point 3 below to your `~/.profile`. This has the added advantage of working under both bash and zsh. -3. Add rbenv init to your shell to enable shims and autocompletion. +3. Add `rbenv init` to your shell to enable shims and autocompletion. - $ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile + ~~~ sh + $ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile + ~~~ **Zsh note**: Modify your `~/.zshenv` file instead of `~/.bash_profile`. @@ -119,62 +124,70 @@ easy to fork and contribute any changes back upstream. 4. Restart your shell as a login shell so the path changes take effect. You can now begin using rbenv. - $ exec $SHELL -l + ~~~ sh + $ exec $SHELL -l + ~~~ 5. Install Ruby versions into `~/.rbenv/versions`. For example, to - install Ruby 1.9.2-p327, download and unpack the [source](https://github.com/ruby/ruby), - then run: + manually compile Ruby [from source](https://github.com/ruby/ruby), + download it and run: - $ [ -f ./configure ] || autoconf - $ ./configure --prefix=$HOME/.rbenv/versions/1.9.3-p327 - $ make - $ make install + ~~~ sh + $ [ -f ./configure ] || autoconf + $ ./configure --prefix=$HOME/.rbenv/versions/1.9.3-p327 + $ make + $ make install + ~~~ - The [ruby-build](https://github.com/sstephenson/ruby-build) project - provides an `rbenv install` command that simplifies the process of - installing new Ruby versions to: + 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 + ~~~ 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). - $ rbenv rehash + ~~~ + $ rbenv rehash + ~~~ #### Upgrading #### -If you've installed rbenv using the instructions above, you can -upgrade your installation at any time using git. +If you've installed rbenv manually using git, you can upgrade your +installation to the cutting-edge version at any time. -To upgrade to the latest development version of rbenv, use `git pull`: +~~~ sh +$ cd ~/.rbenv +$ git pull +~~~ - $ cd ~/.rbenv - $ git pull +To use a specific release of rbenv, check out the corresponding tag: -To upgrade to a specific release of rbenv, check out the corresponding -tag: - - $ cd ~/.rbenv - $ git fetch - $ git tag - v0.1.0 - v0.1.1 - v0.1.2 - v0.2.0 - $ git checkout v0.2.0 +~~~ sh +$ cd ~/.rbenv +$ git fetch +$ git tag +v0.1.0 +v0.1.1 +v0.1.2 +v0.2.0 +$ git checkout v0.2.0 +~~~ ### Homebrew on Mac OS X ### -You can also install rbenv using the -[Homebrew](http://mxcl.github.com/homebrew/) package manager on Mac OS -X. +You can also install rbenv using the [Homebrew][] on Mac OS X. - $ brew update - $ brew install rbenv - $ brew install ruby-build +~~~ +$ brew update +$ brew install rbenv +$ brew install ruby-build +~~~ -The same commands can be used for upgrading. +To later update these installs, use `upgrade` instead of `install`. Afterwards you'll still need to add `eval "$(rbenv init -)"` to your profile as stated in the caveats. You'll only ever have to do this @@ -431,3 +444,7 @@ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + + [ruby-build]: https://github.com/sstephenson/ruby-build + [homebrew]: http://mxcl.github.com/homebrew/ From cf2813600391341ea13d927667b1f08cb0769610 Mon Sep 17 00:00:00 2001 From: Ruben Verborgh Date: Mon, 13 Aug 2012 19:08:39 +0200 Subject: [PATCH 214/384] speed up rbenv-init Use `rbenv-commands` instead of `rbenv commands`. The latter unnecessarily goes through `rbenv` executable. Fixes #254 --- libexec/rbenv-init | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libexec/rbenv-init b/libexec/rbenv-init index fae07399..95b6c403 100755 --- a/libexec/rbenv-init +++ b/libexec/rbenv-init @@ -82,7 +82,7 @@ if [ -z "$no_rehash" ]; then echo 'rbenv rehash 2>/dev/null' fi -commands=(`rbenv commands --sh`) +commands=(`rbenv-commands --sh`) IFS="|" cat < Date: Thu, 13 Dec 2012 00:40:29 +0100 Subject: [PATCH 215/384] rbenv --version --- libexec/rbenv | 5 ++++- libexec/rbenv---version | 10 ++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100755 libexec/rbenv---version diff --git a/libexec/rbenv b/libexec/rbenv index b0470f2f..d368d459 100755 --- a/libexec/rbenv +++ b/libexec/rbenv @@ -60,7 +60,10 @@ shopt -u nullglob command="$1" case "$command" in "" | "-h" | "--help" ) - echo -e "rbenv 0.3.0\n$(rbenv-help)" >&2 + echo -e "rbenv $(rbenv---version)\n$(rbenv-help)" >&2 + ;; +"-v" ) + exec rbenv---version ;; * ) command_path="$(command -v "rbenv-$command" || true)" diff --git a/libexec/rbenv---version b/libexec/rbenv---version new file mode 100755 index 00000000..fcf94d69 --- /dev/null +++ b/libexec/rbenv---version @@ -0,0 +1,10 @@ +#!/usr/bin/env bash +set -e +[ -n "$RBENV_DEBUG" ] && set -x + +version=v0.3.0 + +cd "$RBENV_ROOT" +git_revision="$(git describe --tags HEAD 2>/dev/null || true)" + +echo ${git_revision:-$version} From 99551dd1eced9233485b6bd508ac34abd821f2d4 Mon Sep 17 00:00:00 2001 From: Roy Liu Date: Mon, 30 Jul 2012 20:38:01 -0400 Subject: [PATCH 216/384] fix rbenv-which with system ruby Don't have `command -v` abort the whole script prematurely. --- libexec/rbenv-which | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libexec/rbenv-which b/libexec/rbenv-which index c4966c7a..204988b2 100755 --- a/libexec/rbenv-which +++ b/libexec/rbenv-which @@ -50,7 +50,7 @@ fi if [ "$RBENV_VERSION" = "system" ]; then PATH="$(remove_from_path "${RBENV_ROOT}/shims")" - RBENV_COMMAND_PATH="$(command -v "$RBENV_COMMAND")" + RBENV_COMMAND_PATH="$(command -v "$RBENV_COMMAND" || true)" else RBENV_COMMAND_PATH="${RBENV_ROOT}/versions/${RBENV_VERSION}/bin/${RBENV_COMMAND}" fi From 21391c8d2f8781c840b538babf869ad5a1157f37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohnic=CC=81?= Date: Thu, 13 Dec 2012 01:45:06 +0100 Subject: [PATCH 217/384] put up a note why `version-file-read` is tricky --- libexec/rbenv-version-file-read | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libexec/rbenv-version-file-read b/libexec/rbenv-version-file-read index 9a3cd05b..d6027c4c 100755 --- a/libexec/rbenv-version-file-read +++ b/libexec/rbenv-version-file-read @@ -5,8 +5,8 @@ set -e VERSION_FILE="$1" if [ -e "$VERSION_FILE" ]; then - # Read and print the first non-whitespace word from the specified - # version file. + # Read the first non-whitespace word from the specified version file. + # Be careful not to load it whole in case there's something crazy in it. version="" while read -a words; do word="${words[0]}" From e548877ead42cd474bc1c58bdd02fd1bdbc82828 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohnic=CC=81?= Date: Thu, 13 Dec 2012 01:52:13 +0100 Subject: [PATCH 218/384] have `versions` also list "system" if it exists Closes #263 --- libexec/rbenv-versions | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/libexec/rbenv-versions b/libexec/rbenv-versions index 2a762f24..a64e8537 100755 --- a/libexec/rbenv-versions +++ b/libexec/rbenv-versions @@ -12,14 +12,21 @@ else current_version="$(rbenv-version-name || true)" fi +print_version() { + if [ "$1" == "$current_version" ]; then + echo "${hit_prefix}$(rbenv-version)" + else + echo "${miss_prefix}$1" + fi +} + +# detect if there is system ruby +if RBENV_VERSION=system rbenv-which ruby >/dev/null 2>&1; then + print_version system +fi + for path in "${RBENV_ROOT}/versions/"*; do if [ -d "$path" ]; then - version="${path##*/}" - - if [ "$version" == "$current_version" ]; then - echo "${hit_prefix}$(rbenv-version)" - else - echo "${miss_prefix}${version}" - fi + print_version "${path##*/}" fi done From 1f7722088da0a7ebef84e969f145d92ecf559329 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohnic=CC=81?= Date: Thu, 13 Dec 2012 02:58:41 +0100 Subject: [PATCH 219/384] make `shell` return an error code in case of failure Fixes #274 --- libexec/rbenv-sh-shell | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/libexec/rbenv-sh-shell b/libexec/rbenv-sh-shell index a216cb29..34a0a354 100755 --- a/libexec/rbenv-sh-shell +++ b/libexec/rbenv-sh-shell @@ -23,10 +23,13 @@ fi if [ "$version" = "--unset" ]; then echo "unset RBENV_VERSION" - exit 1 + exit fi # Make sure the specified version is installed. -rbenv-prefix "$version" >/dev/null - -echo "export RBENV_VERSION=\"${version}\"" +if rbenv-prefix "$version" >/dev/null; then + echo "export RBENV_VERSION=\"${version}\"" +else + echo "return 1" + exit 1 +fi From 9289af013216fdd3679b15b73b9d78e3af35b9e4 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Wed, 12 Dec 2012 21:38:57 -0600 Subject: [PATCH 220/384] Don't include `system` in `rbenv versions --bare` output --- libexec/rbenv-versions | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libexec/rbenv-versions b/libexec/rbenv-versions index a64e8537..346800a3 100755 --- a/libexec/rbenv-versions +++ b/libexec/rbenv-versions @@ -6,10 +6,12 @@ if [ "$1" = "--bare" ]; then hit_prefix="" miss_prefix="" current_version="" + include_system="" else hit_prefix="* " miss_prefix=" " current_version="$(rbenv-version-name || true)" + include_system="1" fi print_version() { @@ -20,8 +22,8 @@ print_version() { fi } -# detect if there is system ruby -if RBENV_VERSION=system rbenv-which ruby >/dev/null 2>&1; then +# Include "system" in the non-bare output, if it exists +if [ -n "$include_system" ] && RBENV_VERSION=system rbenv-which ruby >/dev/null 2>&1; then print_version system fi From 7fe9231e64d7ba28b7da4c36c3aa48676f66dac1 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Wed, 12 Dec 2012 21:40:05 -0600 Subject: [PATCH 221/384] Fix `rbenv prefix` for `system` version Should be `/usr` or `/usr/local`, not `/usr/bin` or `/usr/local/bin` --- libexec/rbenv-prefix | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libexec/rbenv-prefix b/libexec/rbenv-prefix index e6094aec..1762f23e 100755 --- a/libexec/rbenv-prefix +++ b/libexec/rbenv-prefix @@ -16,7 +16,8 @@ fi if [ "$RBENV_VERSION" = "system" ]; then RUBY_PATH="$(rbenv-which ruby)" - echo "${RUBY_PATH%/*}" + RUBY_PATH="${RUBY_PATH%/*}" + echo "${RUBY_PATH%/bin}" exit fi From b8715bfee6fe11aa1a09397859b55a01bfe33ac7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohnic=CC=81?= Date: Thu, 13 Dec 2012 05:48:28 +0100 Subject: [PATCH 222/384] foundation for a help system where each command holds its own docs Docs are comprised from "Usage", "Summary" and "Help" sections, where "Help" can span multiple commented lines. If it is missing, "Summary" is shown in its place. References #204, references #206 --- libexec/rbenv-commands | 2 + libexec/rbenv-help | 84 ++++++++++++++++++++++++------------------ libexec/rbenv-rehash | 2 + libexec/rbenv-versions | 2 + libexec/rbenv-whence | 4 +- libexec/rbenv-which | 6 ++- 6 files changed, 63 insertions(+), 37 deletions(-) diff --git a/libexec/rbenv-commands b/libexec/rbenv-commands index 297f8d99..67bc7fb9 100755 --- a/libexec/rbenv-commands +++ b/libexec/rbenv-commands @@ -1,4 +1,6 @@ #!/usr/bin/env bash +# Usage: rbenv commands [ --sh | --no-sh ] +# Summary: List all rbenv commands set -e [ -n "$RBENV_DEBUG" ] && set -x diff --git a/libexec/rbenv-help b/libexec/rbenv-help index e1cbaf57..7a710512 100755 --- a/libexec/rbenv-help +++ b/libexec/rbenv-help @@ -2,6 +2,51 @@ set -e [ -n "$RBENV_DEBUG" ] && set -x +# content from single commented line marked with a word such as "Usage" or "Summary" +extract_line() { + grep "^# ${1}:" "$2" | head -1 | cut -d ' ' -f3- +} + +# content of multiple consecutive commented lines starting with a word such as "Help" +extract_section() { + sed -En "/^# ${1}: /,/^[^#]/s/^# ?//p" "$2" | sed "1s/${1}: //" +} + +# print aligned command names with help summary +print_summary() { + if [ ! -h "$1" ]; then + local summary=$(extract_line Summary "$1") + if [ -n "$summary" ]; then + local name=$(basename "$1") + echo "${name#rbenv-}" | awk '{ printf " %-14s ", $1 }' + echo -n $summary + echo + else + return 1 + fi + fi +} + +print_help() { + local usage="$(extract_line Usage "$1")" + local halp="$(extract_section Help "$1")" + [ -z "$halp" ] && halp="$(extract_line Summary "$1")" + + if [ -n "$usage" ]; then + echo usage: $usage + [ -n "$halp" ] && echo && echo "$halp" + else + echo "Sorry, this command isn't documented yet." >&2 + return 1 + fi +} + +print_summaries() { + for command in $1; do + print_summary "$(command -v rbenv-"$command")" + done +} + print_set_version() { echo " should be a string matching a Ruby version known by rbenv." @@ -21,25 +66,11 @@ case "$1" in "") echo "usage: rbenv [] Some useful rbenv commands are: - commands List all rbenv commands - rehash Rehash rbenv shims (run this after installing binaries) - global Set or show the global Ruby version - local Set or show the local directory-specific Ruby version - shell Set or show the shell-specific Ruby version - version Show the current Ruby version - versions List all Ruby versions known by rbenv - which Show the full path for the given Ruby command - whence List all Ruby versions with the given command +$(print_summaries "commands rehash global local shell version versions which whence") See 'rbenv help ' for information on a specific command. For full documentation, see: https://github.com/sstephenson/rbenv#readme" ;; -commands) echo "usage: rbenv commands - rbenv commands --sh - rbenv commands --no-sh - -List all rbenv commands." -;; global) echo "usage: rbenv global Sets the global Ruby version. You can override the global version at @@ -71,29 +102,12 @@ project-specific versions and the global version. $(print_set_version)" ;; -versions) echo "usage: rbenv versions - rbenv versions --bare - -Lists all Ruby versions known by rbenv." -;; -which) echo "usage: rbenv which - -Displays the full path to the binary that rbenv will execute when you -run the given command." -;; -whence) echo "usage: rbenv whence - -Lists all Ruby versions with the given command installed." -;; *) command_path="$(command -v "rbenv-$1" || true)" if [ -n "$command_path" ]; then - echo "Sorry, the \`$1' command isn't documented yet." - echo - echo "You can view the command's source here:" - echo "$command_path" - echo + print_help "$command_path" else - echo "rbenv: no such command \`$1'" + echo "rbenv: no such command \`$1'" >&2 + exit 1 fi esac diff --git a/libexec/rbenv-rehash b/libexec/rbenv-rehash index eebc4d3c..13bd7938 100755 --- a/libexec/rbenv-rehash +++ b/libexec/rbenv-rehash @@ -1,4 +1,6 @@ #!/usr/bin/env bash +# Usage: rbenv rehash +# Summary: Rehash rbenv shims (run this after installing binaries) set -e [ -n "$RBENV_DEBUG" ] && set -x diff --git a/libexec/rbenv-versions b/libexec/rbenv-versions index 346800a3..46b8a021 100755 --- a/libexec/rbenv-versions +++ b/libexec/rbenv-versions @@ -1,4 +1,6 @@ #!/usr/bin/env bash +# Usage: rbenv versions [--bare] +# Summary: List all Ruby versions known by rbenv set -e [ -n "$RBENV_DEBUG" ] && set -x diff --git a/libexec/rbenv-whence b/libexec/rbenv-whence index 8a926877..5e49d527 100755 --- a/libexec/rbenv-whence +++ b/libexec/rbenv-whence @@ -1,4 +1,6 @@ #!/usr/bin/env bash +# Usage: rbenv whence [--path] COMMAND +# Summary: List all Ruby versions with the given command installed set -e [ -n "$RBENV_DEBUG" ] && set -x @@ -27,7 +29,7 @@ whence() { RBENV_COMMAND="$1" if [ -z "$RBENV_COMMAND" ]; then - echo "usage: rbenv whence [--path] COMMAND" >&2 + rbenv-help whence | head -1 >&2 exit 1 fi diff --git a/libexec/rbenv-which b/libexec/rbenv-which index 204988b2..3cdddd01 100755 --- a/libexec/rbenv-which +++ b/libexec/rbenv-which @@ -1,4 +1,8 @@ #!/usr/bin/env bash +# Usage: rbenv which COMMAND +# Summary: Display full path to a binary +# Help: Displays the full path to the binary that rbenv will execute when you +# run the given command. set -e [ -n "$RBENV_DEBUG" ] && set -x @@ -44,7 +48,7 @@ RBENV_VERSION="$(rbenv-version-name)" RBENV_COMMAND="$1" if [ -z "$RBENV_COMMAND" ]; then - echo "usage: rbenv which COMMAND" >&2 + rbenv-help which | head -1 >&2 exit 1 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 223/384] 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 224/384] 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 225/384] 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 226/384] 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 227/384] 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 228/384] 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 229/384] 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 230/384] 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 231/384] 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 232/384] 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" "$@" From 4c19dc22d7b1f674058acb95d51bde417dc80a62 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Sat, 29 Dec 2012 12:06:20 -0600 Subject: [PATCH 233/384] Improve syntax for inline documentation and allow for multi-line usage --- libexec/rbenv-commands | 5 +- libexec/rbenv-global | 13 +++ libexec/rbenv-help | 195 ++++++++++++++++++++++------------------- libexec/rbenv-local | 19 ++++ libexec/rbenv-rehash | 3 +- libexec/rbenv-sh-shell | 14 +++ libexec/rbenv-version | 2 + libexec/rbenv-versions | 3 +- libexec/rbenv-whence | 3 +- libexec/rbenv-which | 10 ++- 10 files changed, 170 insertions(+), 97 deletions(-) diff --git a/libexec/rbenv-commands b/libexec/rbenv-commands index 67bc7fb9..58aab012 100755 --- a/libexec/rbenv-commands +++ b/libexec/rbenv-commands @@ -1,6 +1,7 @@ #!/usr/bin/env bash -# Usage: rbenv commands [ --sh | --no-sh ] -# Summary: List all rbenv commands +# Summary: List all available rbenv commands +# Usage: rbenv commands [--sh|--no-sh] + set -e [ -n "$RBENV_DEBUG" ] && set -x diff --git a/libexec/rbenv-global b/libexec/rbenv-global index 2f68f2ec..c003359b 100755 --- a/libexec/rbenv-global +++ b/libexec/rbenv-global @@ -1,4 +1,17 @@ #!/usr/bin/env bash +# +# Summary: Set or show the global Ruby version +# +# Usage: rbenv global +# +# Sets the global Ruby version. You can override the global version at +# any time by setting a directory-specific version with `rbenv local' +# or by setting the `RBENV_VERSION' environment variable. +# +# should be a string matching a Ruby version known to rbenv. +# The special version string `system' will use your default system Ruby. +# Run `rbenv versions' for a list of available Ruby versions. + set -e [ -n "$RBENV_DEBUG" ] && set -x diff --git a/libexec/rbenv-help b/libexec/rbenv-help index 7a710512..00eaab15 100755 --- a/libexec/rbenv-help +++ b/libexec/rbenv-help @@ -2,112 +2,129 @@ set -e [ -n "$RBENV_DEBUG" ] && set -x -# content from single commented line marked with a word such as "Usage" or "Summary" -extract_line() { - grep "^# ${1}:" "$2" | head -1 | cut -d ' ' -f3- +command_path() { + local command="$1" + command -v rbenv-"$command" || command -v rbenv-sh-"$command" || true } -# content of multiple consecutive commented lines starting with a word such as "Help" -extract_section() { - sed -En "/^# ${1}: /,/^[^#]/s/^# ?//p" "$2" | sed "1s/${1}: //" +extract_initial_comment_block() { + sed -ne " + /^#/ !{ + q + } + + s/^#$/# / + + /^# / { + s/^# // + p + } + " } -# print aligned command names with help summary -print_summary() { - if [ ! -h "$1" ]; then - local summary=$(extract_line Summary "$1") - if [ -n "$summary" ]; then - local name=$(basename "$1") - echo "${name#rbenv-}" | awk '{ printf " %-14s ", $1 }' - echo -n $summary - echo - else - return 1 - fi +collect_documentation() { + awk ' + /^Summary:/ { + summary = substr($0, 10) + next + } + + /^Usage:/ { + reading_usage = 1 + usage = usage "\n" $0 + next + } + + /^( *$| )/ && reading_usage { + usage = usage "\n" $0 + next + } + + /^([^ ]|$)/ { + reading_usage = 0 + help = help "\n" $0 + } + + function escape(str) { + gsub(/[`\\$"]/, "\\\\&", str) + return str + } + + function trim(str) { + gsub(/^\n*/, "", str) + gsub(/\n*$/, "", str) + return str + } + + END { + if (usage || summary) { + print "summary=\"" escape(summary) "\"" + print "usage=\"" escape(trim(usage)) "\"" + print "help=\"" escape(trim(help)) "\"" + } + } + ' +} + +documentation_for() { + local filename="$(command_path "$1")" + if [ -n "$filename" ]; then + extract_initial_comment_block < "$filename" | collect_documentation fi } +print_summary() { + local command="$1" + local summary usage help + eval "$(documentation_for "$command")" + + if [ -n "$summary" ]; then + printf " %-9s %s\n" "$command" "$summary" + else + return 1 + fi +} + +print_summaries() { + for command; do + print_summary "$command" + done +} + print_help() { - local usage="$(extract_line Usage "$1")" - local halp="$(extract_section Help "$1")" - [ -z "$halp" ] && halp="$(extract_line Summary "$1")" + local command="$1" + local summary usage help + eval "$(documentation_for "$command")" + [ -n "$help" ] || help="$summary" if [ -n "$usage" ]; then - echo usage: $usage - [ -n "$halp" ] && echo && echo "$halp" + echo "$usage" + if [ -n "$help" ]; then + echo + echo "$help" + echo + fi else echo "Sorry, this command isn't documented yet." >&2 return 1 fi } -print_summaries() { - for command in $1; do - print_summary "$(command -v rbenv-"$command")" - done -} - -print_set_version() { - echo " should be a string matching a Ruby version known by rbenv." - - local versions="$(rbenv-versions --bare)" - if [ -z "$versions" ]; then - echo "There are currently no Ruby versions installed for rbenv." - else - echo "The currently installed Ruby versions are:" - echo "$versions" | sed 's/^/ /' - fi - +if [ -z "$1" ]; then + rbenv---version + echo "Usage: rbenv []" echo - echo "The special version string 'system' will use your default system Ruby." -} - -case "$1" in -"") echo "usage: rbenv [] - -Some useful rbenv commands are: -$(print_summaries "commands rehash global local shell version versions which whence") - -See 'rbenv help ' for information on a specific command. -For full documentation, see: https://github.com/sstephenson/rbenv#readme" -;; -global) echo "usage: rbenv global - -Sets the global Ruby version. You can override the global version at -any time by setting a directory-specific version with \`rbenv local' -or by setting the RBENV_VERSION environment variable. - -$(print_set_version)" -;; -local) echo "usage: rbenv local - rbenv local --unset - -Sets the local directory-specific Ruby version by writing the version -name to a file named '.rbenv-version'. - -When you run a Ruby command, rbenv will look for an '.rbenv-version' -file in the current directory and each parent directory. If no such -file is found in the tree, rbenv will use the global Ruby version -specified with \`rbenv global', or the version specified in the -RBENV_VERSION environment variable. - -$(print_set_version)" -;; -shell) echo "usage: rbenv shell - rbenv shell --unset - -Sets a shell-specific Ruby version by setting the 'RBENV_VERSION' -environment variable in your shell. This version overrides both -project-specific versions and the global version. - -$(print_set_version)" -;; -*) - command_path="$(command -v "rbenv-$1" || true)" - if [ -n "$command_path" ]; then - print_help "$command_path" + echo "Some useful rbenv commands are:" + print_summaries commands rehash global local shell version versions which whence + echo + echo "See \`rbenv help ' for information on a specific command." + echo "For full documentation, see: https://github.com/sstephenson/rbenv#readme" +else + command="$1" + if [ -n "$(command_path "$command")" ]; then + print_help "$command" else - echo "rbenv: no such command \`$1'" >&2 + echo "rbenv: no such command \`$command'" >&2 exit 1 fi -esac +fi diff --git a/libexec/rbenv-local b/libexec/rbenv-local index 9b102c5c..a0b3fe76 100755 --- a/libexec/rbenv-local +++ b/libexec/rbenv-local @@ -1,4 +1,23 @@ #!/usr/bin/env bash +# +# Summary: Set or show the local directory-specific Ruby version +# +# Usage: rbenv local +# rbenv local --unset +# +# Sets the local directory-specific Ruby version by writing the version +# name to a file named `.rbenv-version'. +# +# When you run a Ruby command, rbenv will look for an `.rbenv-version' +# file in the current directory and each parent directory. If no such +# file is found in the tree, rbenv will use the global Ruby version +# specified with `rbenv global', or the version specified in the +# RBENV_VERSION environment variable. +# +# should be a string matching a Ruby version known to rbenv. +# The special version string `system' will use your default system Ruby. +# Run `rbenv versions' for a list of available Ruby versions. + set -e [ -n "$RBENV_DEBUG" ] && set -x diff --git a/libexec/rbenv-rehash b/libexec/rbenv-rehash index 916323a3..0f147385 100755 --- a/libexec/rbenv-rehash +++ b/libexec/rbenv-rehash @@ -1,6 +1,7 @@ #!/usr/bin/env bash -# Usage: rbenv rehash # Summary: Rehash rbenv shims (run this after installing binaries) +# Usage: rbenv rehash + set -e [ -n "$RBENV_DEBUG" ] && set -x diff --git a/libexec/rbenv-sh-shell b/libexec/rbenv-sh-shell index 34a0a354..d49eaa52 100755 --- a/libexec/rbenv-sh-shell +++ b/libexec/rbenv-sh-shell @@ -1,4 +1,18 @@ #!/usr/bin/env bash +# +# Summary: Set or show the shell-specific Ruby version +# +# Usage: rbenv shell +# rbenv shell --unset +# +# Sets a shell-specific Ruby version by setting the `RBENV_VERSION' +# environment variable in your shell. This version overrides both +# project-specific versions and the global version. +# +# should be a string matching a Ruby version known to rbenv. +# The special version string `system' will use your default system Ruby. +# Run `rbenv versions' for a list of available Ruby versions. + set -e [ -n "$RBENV_DEBUG" ] && set -x diff --git a/libexec/rbenv-version b/libexec/rbenv-version index 7251a4c9..82624ff1 100755 --- a/libexec/rbenv-version +++ b/libexec/rbenv-version @@ -1,4 +1,6 @@ #!/usr/bin/env bash +# Summary: Show the current Ruby version + set -e [ -n "$RBENV_DEBUG" ] && set -x diff --git a/libexec/rbenv-versions b/libexec/rbenv-versions index 46b8a021..3fcf1ef9 100755 --- a/libexec/rbenv-versions +++ b/libexec/rbenv-versions @@ -1,6 +1,7 @@ #!/usr/bin/env bash -# Usage: rbenv versions [--bare] # Summary: List all Ruby versions known by rbenv +# Usage: rbenv versions [--bare] + set -e [ -n "$RBENV_DEBUG" ] && set -x diff --git a/libexec/rbenv-whence b/libexec/rbenv-whence index 5e49d527..5bb499b9 100755 --- a/libexec/rbenv-whence +++ b/libexec/rbenv-whence @@ -1,6 +1,7 @@ #!/usr/bin/env bash -# Usage: rbenv whence [--path] COMMAND # Summary: List all Ruby versions with the given command installed +# Usage: rbenv whence [--path] COMMAND + set -e [ -n "$RBENV_DEBUG" ] && set -x diff --git a/libexec/rbenv-which b/libexec/rbenv-which index 3cdddd01..6c62f5ca 100755 --- a/libexec/rbenv-which +++ b/libexec/rbenv-which @@ -1,8 +1,12 @@ #!/usr/bin/env bash -# Usage: rbenv which COMMAND -# Summary: Display full path to a binary -# Help: Displays the full path to the binary that rbenv will execute when you +# +# Summary: Display the full path to a binary +# +# Usage: rbenv which +# +# Displays the full path to the binary that rbenv will execute when you # run the given command. + set -e [ -n "$RBENV_DEBUG" ] && set -x From e2e474c59ddecadffa7c318ee2fe2f23d4cd25a5 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Sat, 29 Dec 2012 12:12:47 -0600 Subject: [PATCH 234/384] Add `rbenv help --usage` --- libexec/rbenv-help | 24 +++++++++++++++++++++--- libexec/rbenv-whence | 2 +- libexec/rbenv-which | 2 +- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/libexec/rbenv-help b/libexec/rbenv-help index 00eaab15..fd7f1816 100755 --- a/libexec/rbenv-help +++ b/libexec/rbenv-help @@ -110,9 +110,23 @@ print_help() { fi } -if [ -z "$1" ]; then - rbenv---version +print_usage() { + local command="$1" + local summary usage help + eval "$(documentation_for "$command")" + [ -z "$usage" ] || echo "$usage" +} + +unset usage +if [ "$1" = "--usage" ]; then + usage="1" + shift +fi + +if [ -z "$1" ] || [ "$1" == "rbenv" ]; then + [ -n "$usage" ] || rbenv---version echo "Usage: rbenv []" + [ -z "$usage" ] || exit echo echo "Some useful rbenv commands are:" print_summaries commands rehash global local shell version versions which whence @@ -122,7 +136,11 @@ if [ -z "$1" ]; then else command="$1" if [ -n "$(command_path "$command")" ]; then - print_help "$command" + if [ -n "$usage" ]; then + print_usage "$command" + else + print_help "$command" + fi else echo "rbenv: no such command \`$command'" >&2 exit 1 diff --git a/libexec/rbenv-whence b/libexec/rbenv-whence index 5bb499b9..6c3486ca 100755 --- a/libexec/rbenv-whence +++ b/libexec/rbenv-whence @@ -30,7 +30,7 @@ whence() { RBENV_COMMAND="$1" if [ -z "$RBENV_COMMAND" ]; then - rbenv-help whence | head -1 >&2 + rbenv-help --usage whence >&2 exit 1 fi diff --git a/libexec/rbenv-which b/libexec/rbenv-which index 6c62f5ca..7fa32a9f 100755 --- a/libexec/rbenv-which +++ b/libexec/rbenv-which @@ -52,7 +52,7 @@ RBENV_VERSION="$(rbenv-version-name)" RBENV_COMMAND="$1" if [ -z "$RBENV_COMMAND" ]; then - rbenv-help which | head -1 >&2 + rbenv-help --usage which >&2 exit 1 fi From 57df94573846567a5da0608acc916783c7813a24 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Sat, 29 Dec 2012 12:19:06 -0600 Subject: [PATCH 235/384] Don't print version before help summary (bare `rbenv` already does this) --- libexec/rbenv-help | 1 - 1 file changed, 1 deletion(-) diff --git a/libexec/rbenv-help b/libexec/rbenv-help index fd7f1816..d43782c4 100755 --- a/libexec/rbenv-help +++ b/libexec/rbenv-help @@ -124,7 +124,6 @@ if [ "$1" = "--usage" ]; then fi if [ -z "$1" ] || [ "$1" == "rbenv" ]; then - [ -n "$usage" ] || rbenv---version echo "Usage: rbenv []" [ -z "$usage" ] || exit echo From 2b21e22e976ae905bb80585ccfe9a57e1dcc64de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohnic=CC=81?= Date: Sat, 29 Dec 2012 22:03:04 +0100 Subject: [PATCH 236/384] display help for commands that have Summary but not Usage A command doesn't have to specify Usage docs if it doesn't accept any arguments. The default usage for a command will be printed as: Usage: rbenv ${command} --- libexec/rbenv-help | 8 ++++++-- libexec/rbenv-rehash | 1 - 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/libexec/rbenv-help b/libexec/rbenv-help index d43782c4..3bba20ad 100755 --- a/libexec/rbenv-help +++ b/libexec/rbenv-help @@ -97,8 +97,12 @@ print_help() { eval "$(documentation_for "$command")" [ -n "$help" ] || help="$summary" - if [ -n "$usage" ]; then - echo "$usage" + if [ -n "$usage" -o -n "$summary" ]; then + if [ -n "$usage" ]; then + echo "$usage" + else + echo "Usage: rbenv ${command}" + fi if [ -n "$help" ]; then echo echo "$help" diff --git a/libexec/rbenv-rehash b/libexec/rbenv-rehash index 0f147385..a50819dd 100755 --- a/libexec/rbenv-rehash +++ b/libexec/rbenv-rehash @@ -1,6 +1,5 @@ #!/usr/bin/env bash # Summary: Rehash rbenv shims (run this after installing binaries) -# Usage: rbenv rehash set -e [ -n "$RBENV_DEBUG" ] && set -x From 5cc6b0e3d3d9559b3134a42f02ac3ca3be752790 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohnic=CC=81?= Date: Sat, 29 Dec 2012 22:48:28 +0100 Subject: [PATCH 237/384] allow indented lines in help text Before, lines of help that were indented were stripped away. --- libexec/rbenv-help | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libexec/rbenv-help b/libexec/rbenv-help index 3bba20ad..8f90e2b5 100755 --- a/libexec/rbenv-help +++ b/libexec/rbenv-help @@ -40,7 +40,7 @@ collect_documentation() { next } - /^([^ ]|$)/ { + { reading_usage = 0 help = help "\n" $0 } From 3436bddaea90ff8ee403530891f836b2719dbf7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohnic=CC=81?= Date: Sat, 29 Dec 2012 23:34:53 +0100 Subject: [PATCH 238/384] new-style documentation for most commands --- libexec/rbenv---version | 9 +++++++++ libexec/rbenv-completions | 4 +++- libexec/rbenv-exec | 16 +++++++++++++++- libexec/rbenv-help | 12 ++++++++++++ libexec/rbenv-hooks | 5 ++++- libexec/rbenv-init | 4 ++++ libexec/rbenv-prefix | 6 ++++++ libexec/rbenv-root | 1 + libexec/rbenv-shims | 3 +++ libexec/rbenv-version | 5 ++++- libexec/rbenv-version-file | 1 + libexec/rbenv-version-file-read | 1 + libexec/rbenv-version-file-write | 4 +++- libexec/rbenv-version-name | 1 + libexec/rbenv-version-origin | 1 + libexec/rbenv-versions | 4 +++- libexec/rbenv-whence | 2 +- libexec/rbenv-which | 2 +- 18 files changed, 73 insertions(+), 8 deletions(-) diff --git a/libexec/rbenv---version b/libexec/rbenv---version index aa9b829d..7d65d41d 100755 --- a/libexec/rbenv---version +++ b/libexec/rbenv---version @@ -1,4 +1,13 @@ #!/usr/bin/env bash +# Summary: Display the version of rbenv +# +# Displays the current revision info of rbenv from git if available, or falls +# back to the version of the last release. +# +# The format of the git revision is: +# ${version}-${num_commits}-g${git_sha} +# where `num_commits` is the number of commits since `version` was tagged. + set -e [ -n "$RBENV_DEBUG" ] && set -x diff --git a/libexec/rbenv-completions b/libexec/rbenv-completions index 4bc21a3c..d5cbac32 100755 --- a/libexec/rbenv-completions +++ b/libexec/rbenv-completions @@ -1,10 +1,12 @@ #!/usr/bin/env bash +# Usage: rbenv completions COMMAND [arg1 arg2...] + set -e [ -n "$RBENV_DEBUG" ] && set -x COMMAND="$1" if [ -z "$COMMAND" ]; then - echo "usage: rbenv completions COMMAND [arg1 arg2...]" >&2 + rbenv-help --usage completions >&2 exit 1 fi diff --git a/libexec/rbenv-exec b/libexec/rbenv-exec index 5c1aacd8..23b75d82 100755 --- a/libexec/rbenv-exec +++ b/libexec/rbenv-exec @@ -1,4 +1,18 @@ #!/usr/bin/env bash +# +# Summary: Run an executable with the right Ruby version +# +# Usage: rbenv exec COMMAND [arg1 arg2...] +# +# Runs an executable by first preparing PATH so that the selected Ruby version +# is prepended to it. +# +# For example, doing: +# RBENV_VERSION=1.9.3-p327 rbenv exec bundle install +# +# has an effect is if this was done: +# PATH=~/.rbenv/versions/1.9.3-p327:"$PATH" bundle install + set -e [ -n "$RBENV_DEBUG" ] && set -x @@ -11,7 +25,7 @@ export RBENV_VERSION="$(rbenv-version-name)" RBENV_COMMAND="$1" if [ -z "$RBENV_COMMAND" ]; then - echo "usage: rbenv exec COMMAND [arg1 arg2...]" >&2 + rbenv-help --usage exec >&2 exit 1 fi diff --git a/libexec/rbenv-help b/libexec/rbenv-help index 8f90e2b5..cdb37100 100755 --- a/libexec/rbenv-help +++ b/libexec/rbenv-help @@ -1,4 +1,16 @@ #!/usr/bin/env bash +# +# Summary: Display help for a command +# +# Usage: rbenv help [--usage] COMMAND +# +# Parses and displays help contents from a command's source file. +# +# A command is considered documented if it starts with a comment block that has +# at least one of the following sections: `Summary' and `Usage'. Usage +# instructions can span multiple lines as long as subsequent lines are indented. +# Everything else in the comment is considered to be regular help contents. + set -e [ -n "$RBENV_DEBUG" ] && set -x diff --git a/libexec/rbenv-hooks b/libexec/rbenv-hooks index 47ee910a..3221c6ff 100755 --- a/libexec/rbenv-hooks +++ b/libexec/rbenv-hooks @@ -1,4 +1,7 @@ #!/usr/bin/env bash +# Summary: List hook scripts for a rbenv command +# Usage: rbenv hooks COMMAND + set -e [ -n "$RBENV_DEBUG" ] && set -x @@ -12,7 +15,7 @@ fi RBENV_COMMAND="$1" if [ -z "$RBENV_COMMAND" ]; then - echo "usage: rbenv hooks COMMAND" >&2 + rbenv-help --usage hooks >&2 exit 1 fi diff --git a/libexec/rbenv-init b/libexec/rbenv-init index 16916cd5..6d53a23e 100755 --- a/libexec/rbenv-init +++ b/libexec/rbenv-init @@ -1,4 +1,8 @@ #!/usr/bin/env bash +# Summary: Configure shell environment for rbenv +# Usage: rbenv init [SHELL] +# rbenv init - [--no-rehash] [SHELL] + set -e [ -n "$RBENV_DEBUG" ] && set -x diff --git a/libexec/rbenv-prefix b/libexec/rbenv-prefix index 1762f23e..f68f1496 100755 --- a/libexec/rbenv-prefix +++ b/libexec/rbenv-prefix @@ -1,4 +1,10 @@ #!/usr/bin/env bash +# Summary: Display prefix for a Ruby version +# Usage: rbenv prefix [] +# +# Displays the directory where a Ruby version is installed. If no version is +# given, it uses the currently selected version. + set -e [ -n "$RBENV_DEBUG" ] && set -x diff --git a/libexec/rbenv-root b/libexec/rbenv-root index cf02c058..e632d9d1 100755 --- a/libexec/rbenv-root +++ b/libexec/rbenv-root @@ -1,2 +1,3 @@ #!/usr/bin/env bash +# Summary: Display rbenv directory where versions and shims are kept echo $RBENV_ROOT diff --git a/libexec/rbenv-shims b/libexec/rbenv-shims index 6691e60d..713ca5ab 100755 --- a/libexec/rbenv-shims +++ b/libexec/rbenv-shims @@ -1,4 +1,7 @@ #!/usr/bin/env bash +# Summary: List existing rbenv shims +# Usage: rbenv shims [--short] + set -e [ -n "$RBENV_DEBUG" ] && set -x diff --git a/libexec/rbenv-version b/libexec/rbenv-version index 82624ff1..9ec7ac91 100755 --- a/libexec/rbenv-version +++ b/libexec/rbenv-version @@ -1,5 +1,8 @@ #!/usr/bin/env bash -# Summary: Show the current Ruby version +# Summary: Show the current Ruby version and its origin +# +# Shows the current Ruby version and where it's set from. To obtain only the +# version string, use `rbenv version-name'. set -e [ -n "$RBENV_DEBUG" ] && set -x diff --git a/libexec/rbenv-version-file b/libexec/rbenv-version-file index e9451f42..1beea0f0 100755 --- a/libexec/rbenv-version-file +++ b/libexec/rbenv-version-file @@ -1,4 +1,5 @@ #!/usr/bin/env bash +# Summary: Detect the file that sets the current rbenv version set -e [ -n "$RBENV_DEBUG" ] && set -x diff --git a/libexec/rbenv-version-file-read b/libexec/rbenv-version-file-read index d6027c4c..518bc477 100755 --- a/libexec/rbenv-version-file-read +++ b/libexec/rbenv-version-file-read @@ -1,4 +1,5 @@ #!/usr/bin/env bash +# Usage: rbenv version-file-read FILE set -e [ -n "$RBENV_DEBUG" ] && set -x diff --git a/libexec/rbenv-version-file-write b/libexec/rbenv-version-file-write index def9465a..da6a1c9a 100755 --- a/libexec/rbenv-version-file-write +++ b/libexec/rbenv-version-file-write @@ -1,4 +1,6 @@ #!/usr/bin/env bash +# Usage: rbenv version-file-write FILENAME VERSION + set -e [ -n "$RBENV_DEBUG" ] && set -x @@ -6,7 +8,7 @@ RBENV_VERSION_FILE="$1" RBENV_VERSION="$2" if [ -z "$RBENV_VERSION" ] || [ -z "$RBENV_VERSION_FILE" ]; then - echo "usage: rbenv version-file-write FILENAME VERSION" >&2 + rbenv-help --usage version-file-write >&2 exit 1 fi diff --git a/libexec/rbenv-version-name b/libexec/rbenv-version-name index f65fa1d4..cd1d18fd 100755 --- a/libexec/rbenv-version-name +++ b/libexec/rbenv-version-name @@ -1,4 +1,5 @@ #!/usr/bin/env bash +# Summary: Show the current Ruby version set -e [ -n "$RBENV_DEBUG" ] && set -x diff --git a/libexec/rbenv-version-origin b/libexec/rbenv-version-origin index 9b029b0c..ceef0f9d 100755 --- a/libexec/rbenv-version-origin +++ b/libexec/rbenv-version-origin @@ -1,4 +1,5 @@ #!/usr/bin/env bash +# Summary: Show where the current Ruby version is set from set -e [ -n "$RBENV_DEBUG" ] && set -x diff --git a/libexec/rbenv-versions b/libexec/rbenv-versions index 3fcf1ef9..5bfa72e9 100755 --- a/libexec/rbenv-versions +++ b/libexec/rbenv-versions @@ -1,6 +1,8 @@ #!/usr/bin/env bash -# Summary: List all Ruby versions known by rbenv +# Summary: List all Ruby versions available to rbenv # Usage: rbenv versions [--bare] +# +# Lists all Ruby versions found in `$RBENV_ROOT/versions/*'. set -e [ -n "$RBENV_DEBUG" ] && set -x diff --git a/libexec/rbenv-whence b/libexec/rbenv-whence index 6c3486ca..822ae0e4 100755 --- a/libexec/rbenv-whence +++ b/libexec/rbenv-whence @@ -1,5 +1,5 @@ #!/usr/bin/env bash -# Summary: List all Ruby versions with the given command installed +# Summary: List all Ruby versions that contain the given executable # Usage: rbenv whence [--path] COMMAND set -e diff --git a/libexec/rbenv-which b/libexec/rbenv-which index 7fa32a9f..fe8cc286 100755 --- a/libexec/rbenv-which +++ b/libexec/rbenv-which @@ -1,6 +1,6 @@ #!/usr/bin/env bash # -# Summary: Display the full path to a binary +# Summary: Display the full path to an executable # # Usage: rbenv which # From 19666f25986f27f9610570ac9000c68fd605aad1 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Sat, 29 Dec 2012 21:50:38 -0600 Subject: [PATCH 239/384] Wrap documentation comments at 70 columns --- libexec/rbenv---version | 7 ++++--- libexec/rbenv-exec | 4 ++-- libexec/rbenv-help | 9 +++++---- libexec/rbenv-prefix | 4 ++-- libexec/rbenv-version | 4 ++-- 5 files changed, 15 insertions(+), 13 deletions(-) diff --git a/libexec/rbenv---version b/libexec/rbenv---version index 7d65d41d..c1313e45 100755 --- a/libexec/rbenv---version +++ b/libexec/rbenv---version @@ -1,12 +1,13 @@ #!/usr/bin/env bash # Summary: Display the version of rbenv # -# Displays the current revision info of rbenv from git if available, or falls -# back to the version of the last release. +# Displays the current revision info of rbenv from git if available, +# or falls back to the version of the last release. # # The format of the git revision is: # ${version}-${num_commits}-g${git_sha} -# where `num_commits` is the number of commits since `version` was tagged. +# where `num_commits` is the number of commits since `version` was +# tagged. set -e [ -n "$RBENV_DEBUG" ] && set -x diff --git a/libexec/rbenv-exec b/libexec/rbenv-exec index 23b75d82..60880704 100755 --- a/libexec/rbenv-exec +++ b/libexec/rbenv-exec @@ -4,8 +4,8 @@ # # Usage: rbenv exec COMMAND [arg1 arg2...] # -# Runs an executable by first preparing PATH so that the selected Ruby version -# is prepended to it. +# Runs an executable by first preparing PATH so that the selected Ruby +# version is prepended to it. # # For example, doing: # RBENV_VERSION=1.9.3-p327 rbenv exec bundle install diff --git a/libexec/rbenv-help b/libexec/rbenv-help index cdb37100..0c39b696 100755 --- a/libexec/rbenv-help +++ b/libexec/rbenv-help @@ -6,10 +6,11 @@ # # Parses and displays help contents from a command's source file. # -# A command is considered documented if it starts with a comment block that has -# at least one of the following sections: `Summary' and `Usage'. Usage -# instructions can span multiple lines as long as subsequent lines are indented. -# Everything else in the comment is considered to be regular help contents. +# A command is considered documented if it starts with a comment block +# that has at least one of the following sections: `Summary' and +# `Usage'. Usage instructions can span multiple lines as long as +# subsequent lines are indented. Everything else in the comment is +# considered to be regular help contents. set -e [ -n "$RBENV_DEBUG" ] && set -x diff --git a/libexec/rbenv-prefix b/libexec/rbenv-prefix index f68f1496..0b16fd9e 100755 --- a/libexec/rbenv-prefix +++ b/libexec/rbenv-prefix @@ -2,8 +2,8 @@ # Summary: Display prefix for a Ruby version # Usage: rbenv prefix [] # -# Displays the directory where a Ruby version is installed. If no version is -# given, it uses the currently selected version. +# Displays the directory where a Ruby version is installed. If no +# version is given, it uses the currently selected version. set -e [ -n "$RBENV_DEBUG" ] && set -x diff --git a/libexec/rbenv-version b/libexec/rbenv-version index 9ec7ac91..40d15392 100755 --- a/libexec/rbenv-version +++ b/libexec/rbenv-version @@ -1,8 +1,8 @@ #!/usr/bin/env bash # Summary: Show the current Ruby version and its origin # -# Shows the current Ruby version and where it's set from. To obtain only the -# version string, use `rbenv version-name'. +# Shows the current Ruby version and where it's set from. To obtain +# only the version string, use `rbenv version-name'. set -e [ -n "$RBENV_DEBUG" ] && set -x From 37eca782cc828fa0d4470e300d1411964a2ca6ef Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Sat, 29 Dec 2012 22:05:04 -0600 Subject: [PATCH 240/384] Documentation tweaks --- libexec/rbenv---version | 6 +++--- libexec/rbenv-completions | 2 +- libexec/rbenv-exec | 14 +++++++------- libexec/rbenv-help | 8 ++++---- libexec/rbenv-init | 5 ++--- libexec/rbenv-prefix | 3 ++- libexec/rbenv-rehash | 2 +- libexec/rbenv-root | 2 +- libexec/rbenv-version | 5 +++-- libexec/rbenv-version-file-read | 2 +- libexec/rbenv-version-file-write | 2 +- libexec/rbenv-version-origin | 2 +- 12 files changed, 27 insertions(+), 26 deletions(-) diff --git a/libexec/rbenv---version b/libexec/rbenv---version index c1313e45..222ad004 100755 --- a/libexec/rbenv---version +++ b/libexec/rbenv---version @@ -1,11 +1,11 @@ #!/usr/bin/env bash # Summary: Display the version of rbenv # -# Displays the current revision info of rbenv from git if available, -# or falls back to the version of the last release. +# Displays the version number of this rbenv release, including the +# current revision from git, if available. # # The format of the git revision is: -# ${version}-${num_commits}-g${git_sha} +# -- # where `num_commits` is the number of commits since `version` was # tagged. diff --git a/libexec/rbenv-completions b/libexec/rbenv-completions index d5cbac32..2cc14e67 100755 --- a/libexec/rbenv-completions +++ b/libexec/rbenv-completions @@ -1,5 +1,5 @@ #!/usr/bin/env bash -# Usage: rbenv completions COMMAND [arg1 arg2...] +# Usage: rbenv completions [arg1 arg2...] set -e [ -n "$RBENV_DEBUG" ] && set -x diff --git a/libexec/rbenv-exec b/libexec/rbenv-exec index 60880704..45dbbf80 100755 --- a/libexec/rbenv-exec +++ b/libexec/rbenv-exec @@ -1,17 +1,17 @@ #!/usr/bin/env bash # -# Summary: Run an executable with the right Ruby version +# Summary: Run an executable with the selected Ruby version # -# Usage: rbenv exec COMMAND [arg1 arg2...] +# Usage: rbenv exec [arg1 arg2...] # # Runs an executable by first preparing PATH so that the selected Ruby -# version is prepended to it. +# version's `bin' directory is at the front. # -# For example, doing: -# RBENV_VERSION=1.9.3-p327 rbenv exec bundle install +# For example, if the currently selected Ruby version is 1.9.3-p327: +# rbenv exec bundle install # -# has an effect is if this was done: -# PATH=~/.rbenv/versions/1.9.3-p327:"$PATH" bundle install +# is equivalent to: +# PATH="$RBENV_ROOT/versions/1.9.3-p327/bin:$PATH" bundle install set -e [ -n "$RBENV_DEBUG" ] && set -x diff --git a/libexec/rbenv-help b/libexec/rbenv-help index 0c39b696..e42a123a 100755 --- a/libexec/rbenv-help +++ b/libexec/rbenv-help @@ -7,10 +7,10 @@ # Parses and displays help contents from a command's source file. # # A command is considered documented if it starts with a comment block -# that has at least one of the following sections: `Summary' and -# `Usage'. Usage instructions can span multiple lines as long as -# subsequent lines are indented. Everything else in the comment is -# considered to be regular help contents. +# that has a `Summary:' or `Usage:' section. Usage instructions can +# span multiple lines as long as subsequent lines are indented. +# The remainder of the comment block is displayed as extended +# documentation. set -e [ -n "$RBENV_DEBUG" ] && set -x diff --git a/libexec/rbenv-init b/libexec/rbenv-init index 6d53a23e..0ae9cf47 100755 --- a/libexec/rbenv-init +++ b/libexec/rbenv-init @@ -1,7 +1,6 @@ #!/usr/bin/env bash -# Summary: Configure shell environment for rbenv -# Usage: rbenv init [SHELL] -# rbenv init - [--no-rehash] [SHELL] +# Summary: Configure the shell environment for rbenv +# Usage: eval "$(rbenv init - [--no-rehash] [])" set -e [ -n "$RBENV_DEBUG" ] && set -x diff --git a/libexec/rbenv-prefix b/libexec/rbenv-prefix index 0b16fd9e..a0aebab2 100755 --- a/libexec/rbenv-prefix +++ b/libexec/rbenv-prefix @@ -3,7 +3,8 @@ # Usage: rbenv prefix [] # # Displays the directory where a Ruby version is installed. If no -# version is given, it uses the currently selected version. +# version is given, `rbenv prefix' displays the location of the +# currently selected version. set -e [ -n "$RBENV_DEBUG" ] && set -x diff --git a/libexec/rbenv-rehash b/libexec/rbenv-rehash index a50819dd..aa924efe 100755 --- a/libexec/rbenv-rehash +++ b/libexec/rbenv-rehash @@ -1,5 +1,5 @@ #!/usr/bin/env bash -# Summary: Rehash rbenv shims (run this after installing binaries) +# Summary: Rehash rbenv shims (run this after installing executables) set -e [ -n "$RBENV_DEBUG" ] && set -x diff --git a/libexec/rbenv-root b/libexec/rbenv-root index e632d9d1..64fc90b8 100755 --- a/libexec/rbenv-root +++ b/libexec/rbenv-root @@ -1,3 +1,3 @@ #!/usr/bin/env bash -# Summary: Display rbenv directory where versions and shims are kept +# Summary: Display the root directory where versions and shims are kept echo $RBENV_ROOT diff --git a/libexec/rbenv-version b/libexec/rbenv-version index 40d15392..d1fefcc5 100755 --- a/libexec/rbenv-version +++ b/libexec/rbenv-version @@ -1,8 +1,9 @@ #!/usr/bin/env bash # Summary: Show the current Ruby version and its origin # -# Shows the current Ruby version and where it's set from. To obtain -# only the version string, use `rbenv version-name'. +# Shows the currently selected Ruby version and how it was +# selected. To obtain only the version string, use `rbenv +# version-name'. set -e [ -n "$RBENV_DEBUG" ] && set -x diff --git a/libexec/rbenv-version-file-read b/libexec/rbenv-version-file-read index 518bc477..69ec78b9 100755 --- a/libexec/rbenv-version-file-read +++ b/libexec/rbenv-version-file-read @@ -1,5 +1,5 @@ #!/usr/bin/env bash -# Usage: rbenv version-file-read FILE +# Usage: rbenv version-file-read set -e [ -n "$RBENV_DEBUG" ] && set -x diff --git a/libexec/rbenv-version-file-write b/libexec/rbenv-version-file-write index da6a1c9a..04a0febb 100755 --- a/libexec/rbenv-version-file-write +++ b/libexec/rbenv-version-file-write @@ -1,5 +1,5 @@ #!/usr/bin/env bash -# Usage: rbenv version-file-write FILENAME VERSION +# Usage: rbenv version-file-write set -e [ -n "$RBENV_DEBUG" ] && set -x diff --git a/libexec/rbenv-version-origin b/libexec/rbenv-version-origin index ceef0f9d..ae7abf9c 100755 --- a/libexec/rbenv-version-origin +++ b/libexec/rbenv-version-origin @@ -1,5 +1,5 @@ #!/usr/bin/env bash -# Summary: Show where the current Ruby version is set from +# Summary: Explain how the current Ruby version is set set -e [ -n "$RBENV_DEBUG" ] && set -x From 51467dc4a3f838b2e9b8e2689737f1a4931d353d Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Sun, 30 Dec 2012 15:30:37 -0600 Subject: [PATCH 241/384] Include `install` and `uninstall` in help if ruby-build is installed --- libexec/rbenv-help | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/libexec/rbenv-help b/libexec/rbenv-help index e42a123a..ca3607d9 100755 --- a/libexec/rbenv-help +++ b/libexec/rbenv-help @@ -93,8 +93,6 @@ print_summary() { if [ -n "$summary" ]; then printf " %-9s %s\n" "$command" "$summary" - else - return 1 fi } @@ -145,7 +143,7 @@ if [ -z "$1" ] || [ "$1" == "rbenv" ]; then [ -z "$usage" ] || exit echo echo "Some useful rbenv commands are:" - print_summaries commands rehash global local shell version versions which whence + print_summaries commands global local shell install uninstall rehash version versions which whence echo echo "See \`rbenv help ' for information on a specific command." echo "For full documentation, see: https://github.com/sstephenson/rbenv#readme" From 4b6c91e82762737ffefef343179670b60b608cfa Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Sun, 30 Dec 2012 16:00:53 -0600 Subject: [PATCH 242/384] Usage consistency --- libexec/rbenv-hooks | 4 ++-- libexec/rbenv-whence | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libexec/rbenv-hooks b/libexec/rbenv-hooks index 3221c6ff..794b9437 100755 --- a/libexec/rbenv-hooks +++ b/libexec/rbenv-hooks @@ -1,6 +1,6 @@ #!/usr/bin/env bash -# Summary: List hook scripts for a rbenv command -# Usage: rbenv hooks COMMAND +# Summary: List hook scripts for a given rbenv command +# Usage: rbenv hooks set -e [ -n "$RBENV_DEBUG" ] && set -x diff --git a/libexec/rbenv-whence b/libexec/rbenv-whence index 822ae0e4..df1d6604 100755 --- a/libexec/rbenv-whence +++ b/libexec/rbenv-whence @@ -1,6 +1,6 @@ #!/usr/bin/env bash # Summary: List all Ruby versions that contain the given executable -# Usage: rbenv whence [--path] COMMAND +# Usage: rbenv whence [--path] set -e [ -n "$RBENV_DEBUG" ] && set -x From b974bf54dc070b9b0fb5744dae54327238564d4e Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Sun, 30 Dec 2012 18:35:08 -0600 Subject: [PATCH 243/384] Prefer .ruby-version to .rbenv-version for reading local versions --- libexec/rbenv-version-file | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libexec/rbenv-version-file b/libexec/rbenv-version-file index 1beea0f0..2413834f 100755 --- a/libexec/rbenv-version-file +++ b/libexec/rbenv-version-file @@ -6,7 +6,10 @@ set -e find_local_version_file() { local root="$1" while [ -n "$root" ]; do - if [ -e "${root}/.rbenv-version" ]; then + if [ -e "${root}/.ruby-version" ]; then + echo "${root}/.ruby-version" + exit + elif [ -e "${root}/.rbenv-version" ]; then echo "${root}/.rbenv-version" exit fi From 5e52fae7c175c653d95e80435584754f2b418e0f Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Sun, 30 Dec 2012 19:01:30 -0600 Subject: [PATCH 244/384] Accept "ruby-" version prefix but print a warning to stderr --- libexec/rbenv-version-name | 12 ++++++++++-- libexec/rbenv-versions | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/libexec/rbenv-version-name b/libexec/rbenv-version-name index cd1d18fd..46e3ae7c 100755 --- a/libexec/rbenv-version-name +++ b/libexec/rbenv-version-name @@ -13,10 +13,18 @@ if [ -z "$RBENV_VERSION" ] || [ "$RBENV_VERSION" = "system" ]; then exit fi -RBENV_VERSION_PATH="${RBENV_ROOT}/versions/${RBENV_VERSION}" +version_exists() { + local version="$1" + [ -d "${RBENV_ROOT}/versions/${version}" ] +} -if [ -d "$RBENV_VERSION_PATH" ]; then +if version_exists "$RBENV_VERSION"; then echo "$RBENV_VERSION" +elif version_exists "${RBENV_VERSION#ruby-}"; then + { echo "rbenv: ignoring extraneous \`ruby-' prefix in version \`${RBENV_VERSION}'" + echo "(set by $(rbenv-version-origin))" + } >&2 + echo "${RBENV_VERSION#ruby-}" else echo "rbenv: version \`$RBENV_VERSION' is not installed" >&2 exit 1 diff --git a/libexec/rbenv-versions b/libexec/rbenv-versions index 5bfa72e9..ea28e5cd 100755 --- a/libexec/rbenv-versions +++ b/libexec/rbenv-versions @@ -21,7 +21,7 @@ fi print_version() { if [ "$1" == "$current_version" ]; then - echo "${hit_prefix}$(rbenv-version)" + echo "${hit_prefix}$(rbenv-version 2>/dev/null)" else echo "${miss_prefix}$1" fi From d4faae187a7eb8fd6f4b9d2aacdb3352bf7d3fec Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Sun, 30 Dec 2012 21:14:04 -0600 Subject: [PATCH 245/384] Read both .ruby-version and .rbenv-version, but write (and migrate to) .ruby-version --- libexec/rbenv-local | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/libexec/rbenv-local b/libexec/rbenv-local index a0b3fe76..3607bad8 100755 --- a/libexec/rbenv-local +++ b/libexec/rbenv-local @@ -6,14 +6,18 @@ # rbenv local --unset # # Sets the local directory-specific Ruby version by writing the version -# name to a file named `.rbenv-version'. +# name to a file named `.ruby-version'. # -# When you run a Ruby command, rbenv will look for an `.rbenv-version' +# When you run a Ruby command, rbenv will look for a `.ruby-version' # file in the current directory and each parent directory. If no such # file is found in the tree, rbenv will use the global Ruby version # specified with `rbenv global', or the version specified in the # RBENV_VERSION environment variable. # +# For backwards compatibility, rbenv will also read version +# specifications from `.rbenv-version' files, but a `.ruby-version' +# file in the same directory takes precedence. +# # should be a string matching a Ruby version known to rbenv. # The special version string `system' will use your default system Ruby. # Run `rbenv versions' for a list of available Ruby versions. @@ -29,14 +33,18 @@ if [ "$1" = "--complete" ]; then fi RBENV_VERSION="$1" -RBENV_VERSION_FILE=".rbenv-version" if [ "$RBENV_VERSION" = "--unset" ]; then - rm -f "$RBENV_VERSION_FILE" + rm -f .ruby-version .rbenv-version elif [ -n "$RBENV_VERSION" ]; then - rbenv-version-file-write "$RBENV_VERSION_FILE" "$RBENV_VERSION" + if [ "$(RBENV_VERSION= rbenv-version-origin)" -ef .rbenv-version ]; then + echo "rbenv: migrated .rbenv-version file to .ruby-version" >&2 + rm -f .rbenv-version + fi + rbenv-version-file-write .ruby-version "$RBENV_VERSION" else - rbenv-version-file-read "$RBENV_VERSION_FILE" || + rbenv-version-file-read .ruby-version || + rbenv-version-file-read .rbenv-version || { echo "rbenv: no local version configured for this directory" exit 1 } >&2 From d2a8ca7d891cb230f28b970c17f7be0ae3c4e714 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Mon, 31 Dec 2012 09:58:10 -0600 Subject: [PATCH 246/384] Tweak the ruby- prefix warning --- libexec/rbenv-version-name | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libexec/rbenv-version-name b/libexec/rbenv-version-name index 46e3ae7c..3eef70a8 100755 --- a/libexec/rbenv-version-name +++ b/libexec/rbenv-version-name @@ -21,8 +21,8 @@ version_exists() { if version_exists "$RBENV_VERSION"; then echo "$RBENV_VERSION" elif version_exists "${RBENV_VERSION#ruby-}"; then - { echo "rbenv: ignoring extraneous \`ruby-' prefix in version \`${RBENV_VERSION}'" - echo "(set by $(rbenv-version-origin))" + { echo "warning: ignoring extraneous \`ruby-' prefix in version \`${RBENV_VERSION}'" + echo " (set by $(rbenv-version-origin))" } >&2 echo "${RBENV_VERSION#ruby-}" else From 377b176260e1761b9dace3f023da3b5cb58b2815 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Mon, 31 Dec 2012 09:58:28 -0600 Subject: [PATCH 247/384] Document .ruby-version --- README.md | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index d6b449c4..eccffb46 100644 --- a/README.md +++ b/README.md @@ -105,10 +105,10 @@ easy to fork and contribute any changes back upstream. **Zsh note**: Modify your `~/.zshenv` file instead of `~/.bash_profile`. - **Ubuntu note**: Ubuntu uses `~/.profile` for enabling certain path - changes. This file won't be read if you create a `~/.bash_profile`. - Therefore, it's recommended that you add this line and the one in - point 3 below to your `~/.profile`. This has the added advantage + **Ubuntu note**: Ubuntu uses `~/.profile` for enabling certain path + changes. This file won't be read if you create a `~/.bash_profile`. + Therefore, it's recommended that you add this line and the one in + point 3 below to your `~/.profile`. This has the added advantage of working under both bash and zsh. 3. Add `rbenv init` to your shell to enable shims and autocompletion. @@ -118,10 +118,10 @@ easy to fork and contribute any changes back upstream. ~~~ **Zsh note**: Modify your `~/.zshenv` file instead of `~/.bash_profile`. - + **Ubuntu note**: Same as Ubuntu note for point 2 above. -4. Restart your shell as a login shell so the path changes take effect. +4. Restart your shell as a login shell so the path changes take effect. You can now begin using rbenv. ~~~ sh @@ -235,7 +235,7 @@ first argument. The most common subcommands are: Sets the global version of Ruby to be used in all shells by writing the version name to the `~/.rbenv/version` file. This version can be -overridden by a per-project `.rbenv-version` file, or by setting the +overridden by a per-project `.ruby-version` file, or by setting the `RBENV_VERSION` environment variable. $ rbenv global 1.9.3-p327 @@ -249,7 +249,7 @@ currently configured global version. ### rbenv local ### Sets a local per-project Ruby version by writing the version name to -an `.rbenv-version` file in the current directory. This version +a `.ruby-version` file in the current directory. This version overrides the global, and can be overridden itself by setting the `RBENV_VERSION` environment variable or with the `rbenv shell` command. @@ -261,6 +261,11 @@ configured local version. You can also unset the local version: $ rbenv local --unset +Previous versions of rbenv stored local version specifications in a +file named `.rbenv-version`. For backwards compatibility, rbenv will +read a local version specified in an `.rbenv-version` file, but a +`.ruby-version` file in the same directory will take precedence. + ### rbenv shell ### Sets a shell-specific Ruby version by setting the `RBENV_VERSION` @@ -289,7 +294,7 @@ the currently active version. $ rbenv versions 1.8.7-p352 1.9.2-p290 - * 1.9.3-p327 (set by /Users/sam/.rbenv/global) + * 1.9.3-p327 (set by /Users/sam/.rbenv/version) jruby-1.7.1 rbx-1.2.4 ree-1.8.7-2011.03 @@ -300,7 +305,7 @@ Displays the currently active Ruby version, along with information on how it was set. $ rbenv version - 1.8.7-p352 (set by /Volumes/37signals/basecamp/.rbenv-version) + 1.8.7-p352 (set by /Volumes/37signals/basecamp/.ruby-version) ### rbenv rehash ### From 44c2378f2a8bd09df4dfd360e238d5aa7209ea98 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Tue, 1 Jan 2013 13:27:39 -0600 Subject: [PATCH 248/384] Shims include the full path to rbenv This makes it possible to execute rbenv shims without rbenv's bin directory in the path. --- libexec/rbenv-rehash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libexec/rbenv-rehash b/libexec/rbenv-rehash index aa924efe..07608d9d 100755 --- a/libexec/rbenv-rehash +++ b/libexec/rbenv-rehash @@ -57,7 +57,7 @@ if [ "\$program" = "ruby" ]; then fi export RBENV_ROOT="$RBENV_ROOT" -exec rbenv exec "\$program" "\$@" +exec "$(command -v rbenv)" exec "\$program" "\$@" SH chmod +x "$PROTOTYPE_SHIM_PATH" } From 919c4240fc23f47a95ea51bf9c550070435b3d5f Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Wed, 2 Jan 2013 12:51:47 -0600 Subject: [PATCH 249/384] Clarify that .rbenv-version is removed when migrating --- libexec/rbenv-local | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libexec/rbenv-local b/libexec/rbenv-local index 3607bad8..9da44816 100755 --- a/libexec/rbenv-local +++ b/libexec/rbenv-local @@ -38,8 +38,10 @@ if [ "$RBENV_VERSION" = "--unset" ]; then rm -f .ruby-version .rbenv-version elif [ -n "$RBENV_VERSION" ]; then if [ "$(RBENV_VERSION= rbenv-version-origin)" -ef .rbenv-version ]; then - echo "rbenv: migrated .rbenv-version file to .ruby-version" >&2 rm -f .rbenv-version + { echo "rbenv: removed existing \`.rbenv-version' file and migrated" + echo " local version specification to \`.ruby-version' file" + } >&2 fi rbenv-version-file-write .ruby-version "$RBENV_VERSION" else From 3ec34448fac7ae306b23db1b8aae2e2629bf7794 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Wed, 2 Jan 2013 18:56:23 -0600 Subject: [PATCH 250/384] Rewrite the readme pitch --- LICENSE | 2 +- README.md | 85 +++++++++++++++++++++++++------------------------------ 2 files changed, 40 insertions(+), 47 deletions(-) diff --git a/LICENSE b/LICENSE index 63c11cb6..e8f663a6 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2011 Sam Stephenson +Copyright (c) 2013 Sam Stephenson Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/README.md b/README.md index d6b449c4..7830dfac 100644 --- a/README.md +++ b/README.md @@ -1,40 +1,34 @@ # Simple Ruby Version Management: rbenv -rbenv lets you easily switch between multiple versions of Ruby. It's -simple, unobtrusive, and follows the UNIX tradition of single-purpose -tools that do one thing well. +rbenv lets you lock your application to a specific version of Ruby, +ensuring a consistent runtime environment during development and in +production. Use it in conjunction with +[Bundler](http://gembundler.com/) to facilitate painless Ruby upgrades +and bulletproof deployments. - +**Powerful in development.** Easily specify the Ruby version + dependency for your application with a single file and keep all your + teammates on the same page. Transparently run multiple applications + on different versions of Ruby from the command line or with app + servers like [Pow](http://pow.cx). Override the specified Ruby + version at any time just by setting an environment variable. -### rbenv _does…_ +**Rock-solid in production.** Your application's executables are its + interface with ops. With rbenv and [Bundler + binstubs](http://yehudakatz.com/2011/05/30/gem-versioning-and-bundler-doing-it-right/) + you'll never again need to `cd` in a cron job or Chef recipe to + ensure you've selected the right runtime. The Ruby version + dependency information lives in one place—your app's directory—so + upgrades and rollbacks can be atomic. -* Let you **change the global Ruby version** on a per-user basis. -* Provide support for **per-project Ruby versions**. -* Allow you to **override the Ruby version** with an environment - variable. - -### In contrast with rvm, rbenv _does not…_ - -* **Need to be loaded into your shell.** Instead, rbenv's shim - approach works by adding a directory to your `$PATH`. -* **Override shell commands like `cd`.** That's dangerous and - error-prone. -* **Have a configuration file.** There's nothing to configure except - which version of Ruby you want to use. -* **Install Ruby.** You can build and install Ruby yourself, or use - [ruby-build][] to automate the process. -* **Manage gemsets.** [Bundler](http://gembundler.com/) is a better - way to manage application dependencies. If you have projects that - are not yet using Bundler you can install the - [rbenv-gemset](https://github.com/jamis/rbenv-gemset) plugin. -* **Require changes to Ruby libraries for compatibility.** The - simplicity of rbenv means as long as it's in your `$PATH`, - [nothing](https://rvm.io/integration/bundler/) - [else](https://rvm.io/integration/capistrano/) - needs to know about it. -* **Prompt you with warnings when you switch to a project.** Instead - of executing arbitrary code, rbenv reads just the version name - from each project. There's nothing to "trust." +**One thing well.** rbenv is concerned solely with switching Ruby + versions, but a rich plugin ecosystem lets you tailor it to suit + your needs. Compile your own Ruby versions, or use the + [ruby-build](https://github.com/sstephenson/ruby-build) plugin to + automate the process. Specify per-application environment variables + with [rbenv-vars](https://github.com/sstephenson/rbenv-vars). See + more [plugins on the + wiki](https://github.com/sstephenson/rbenv/wiki/Plugins). ## Table of Contents @@ -105,10 +99,10 @@ easy to fork and contribute any changes back upstream. **Zsh note**: Modify your `~/.zshenv` file instead of `~/.bash_profile`. - **Ubuntu note**: Ubuntu uses `~/.profile` for enabling certain path - changes. This file won't be read if you create a `~/.bash_profile`. - Therefore, it's recommended that you add this line and the one in - point 3 below to your `~/.profile`. This has the added advantage + **Ubuntu note**: Ubuntu uses `~/.profile` for enabling certain path + changes. This file won't be read if you create a `~/.bash_profile`. + Therefore, it's recommended that you add this line and the one in + point 3 below to your `~/.profile`. This has the added advantage of working under both bash and zsh. 3. Add `rbenv init` to your shell to enable shims and autocompletion. @@ -118,18 +112,19 @@ easy to fork and contribute any changes back upstream. ~~~ **Zsh note**: Modify your `~/.zshenv` file instead of `~/.bash_profile`. - + **Ubuntu note**: Same as Ubuntu note for point 2 above. -4. Restart your shell as a login shell so the path changes take effect. +4. Restart your shell as a login shell so the path changes take effect. You can now begin using rbenv. ~~~ sh $ exec $SHELL -l ~~~ -5. Install [ruby-build][], which provides an `rbenv install` - command that simplifies the process of installing new Ruby versions. +5. Install [ruby-build](https://github.com/sstephenson/ruby-build), + which provides an `rbenv install` command that simplifies the + process of installing new Ruby versions. ~~~ $ rbenv install 1.9.3-p327 @@ -171,7 +166,9 @@ $ git checkout v0.2.0 ### Homebrew on Mac OS X ### -You can also install rbenv using the [Homebrew][] on Mac OS X. +You can also install rbenv using the +[Homebrew](http://mxcl.github.com/homebrew/) package manager on Mac OS +X. ~~~ $ brew update @@ -416,7 +413,7 @@ tracker](https://github.com/sstephenson/rbenv/issues). (The MIT license) -Copyright (c) 2011 Sam Stephenson +Copyright (c) 2013 Sam Stephenson Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the @@ -436,7 +433,3 @@ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - - - [ruby-build]: https://github.com/sstephenson/ruby-build - [homebrew]: http://mxcl.github.com/homebrew/ From bac149e82424c0e694e3366f505ef09b782584cb Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Wed, 2 Jan 2013 19:00:04 -0700 Subject: [PATCH 251/384] Riff on the readme pitch --- README.md | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 7830dfac..9c253008 100644 --- a/README.md +++ b/README.md @@ -1,33 +1,31 @@ # Simple Ruby Version Management: rbenv -rbenv lets you lock your application to a specific version of Ruby, -ensuring a consistent runtime environment during development and in -production. Use it in conjunction with -[Bundler](http://gembundler.com/) to facilitate painless Ruby upgrades -and bulletproof deployments. +Use rbenv to pick a Ruby version for your application and guarantee +that your development environment matches production. Put rbenv to work +with [Bundler](http://gembundler.com/) for painless Ruby upgrades and +bulletproof deployments. -**Powerful in development.** Easily specify the Ruby version - dependency for your application with a single file and keep all your - teammates on the same page. Transparently run multiple applications - on different versions of Ruby from the command line or with app - servers like [Pow](http://pow.cx). Override the specified Ruby - version at any time just by setting an environment variable. +**Powerful in development.** Specify your app's Ruby version once, + in a single file. Keep all your teammates on the same page. No + headaches running apps on different versions of Ruby. Just Works™ + from the command line and with app servers like [Pow](http://pow.cx). + Override the Ruby version anytime: just set an environment variable. **Rock-solid in production.** Your application's executables are its interface with ops. With rbenv and [Bundler binstubs](http://yehudakatz.com/2011/05/30/gem-versioning-and-bundler-doing-it-right/) you'll never again need to `cd` in a cron job or Chef recipe to ensure you've selected the right runtime. The Ruby version - dependency information lives in one place—your app's directory—so - upgrades and rollbacks can be atomic. + dependency information lives in one place—your app—so upgrades and + rollbacks are atomic, even when you switch versions. **One thing well.** rbenv is concerned solely with switching Ruby - versions, but a rich plugin ecosystem lets you tailor it to suit - your needs. Compile your own Ruby versions, or use the - [ruby-build](https://github.com/sstephenson/ruby-build) plugin to - automate the process. Specify per-application environment variables - with [rbenv-vars](https://github.com/sstephenson/rbenv-vars). See - more [plugins on the + versions. It's simple and predictable. A rich plugin ecosystem lets + you tailor it to suit your needs. Compile your own Ruby versions, or + use the [ruby-build](https://github.com/sstephenson/ruby-build) + plugin to automate the process. Specify per-application environment + variables with [rbenv-vars](https://github.com/sstephenson/rbenv-vars). + See more [plugins on the wiki](https://github.com/sstephenson/rbenv/wiki/Plugins). ## Table of Contents From 253f6ee1d922244859dd000ee42962ff8e648a02 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Wed, 2 Jan 2013 19:01:47 -0700 Subject: [PATCH 252/384] -information in readme pitch --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9c253008..c6e666b7 100644 --- a/README.md +++ b/README.md @@ -16,8 +16,8 @@ bulletproof deployments. binstubs](http://yehudakatz.com/2011/05/30/gem-versioning-and-bundler-doing-it-right/) you'll never again need to `cd` in a cron job or Chef recipe to ensure you've selected the right runtime. The Ruby version - dependency information lives in one place—your app—so upgrades and - rollbacks are atomic, even when you switch versions. + dependency lives in one place—your app—so upgrades and rollbacks are + atomic, even when you switch versions. **One thing well.** rbenv is concerned solely with switching Ruby versions. It's simple and predictable. A rich plugin ecosystem lets From 149f4b4607e9014ae93411dcb8e590005b5e0225 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Thu, 3 Jan 2013 10:00:10 -0600 Subject: [PATCH 253/384] "per-project" -> "application-specific" --- README.md | 12 ++++++------ libexec/rbenv-local | 11 ++++++----- libexec/rbenv-sh-shell | 4 ++-- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 12c36459..d6e07b57 100644 --- a/README.md +++ b/README.md @@ -230,8 +230,8 @@ first argument. The most common subcommands are: Sets the global version of Ruby to be used in all shells by writing the version name to the `~/.rbenv/version` file. This version can be -overridden by a per-project `.ruby-version` file, or by setting the -`RBENV_VERSION` environment variable. +overridden by an application-specific `.ruby-version` file, or by +setting the `RBENV_VERSION` environment variable. $ rbenv global 1.9.3-p327 @@ -243,8 +243,8 @@ currently configured global version. ### rbenv local ### -Sets a local per-project Ruby version by writing the version name to -a `.ruby-version` file in the current directory. This version +Sets a local application-specific Ruby version by writing the version +name to a `.ruby-version` file in the current directory. This version overrides the global, and can be overridden itself by setting the `RBENV_VERSION` environment variable or with the `rbenv shell` command. @@ -264,8 +264,8 @@ read a local version specified in an `.rbenv-version` file, but a ### rbenv shell ### Sets a shell-specific Ruby version by setting the `RBENV_VERSION` -environment variable in your shell. This version overrides both -project-specific versions and the global version. +environment variable in your shell. This version overrides +application-specific versions and the global version. $ rbenv shell jruby-1.7.1 diff --git a/libexec/rbenv-local b/libexec/rbenv-local index 9da44816..34464410 100755 --- a/libexec/rbenv-local +++ b/libexec/rbenv-local @@ -1,18 +1,19 @@ #!/usr/bin/env bash # -# Summary: Set or show the local directory-specific Ruby version +# Summary: Set or show the local application-specific Ruby version # # Usage: rbenv local # rbenv local --unset # -# Sets the local directory-specific Ruby version by writing the version -# name to a file named `.ruby-version'. +# Sets the local application-specific Ruby version by writing the +# version name to a file named `.ruby-version'. # # When you run a Ruby command, rbenv will look for a `.ruby-version' # file in the current directory and each parent directory. If no such # file is found in the tree, rbenv will use the global Ruby version -# specified with `rbenv global', or the version specified in the -# RBENV_VERSION environment variable. +# specified with `rbenv global'. A version specified with the +# `RBENV_VERSION' environment variable takes precedence over local +# and global versions. # # For backwards compatibility, rbenv will also read version # specifications from `.rbenv-version' files, but a `.ruby-version' diff --git a/libexec/rbenv-sh-shell b/libexec/rbenv-sh-shell index d49eaa52..4b89c6c0 100755 --- a/libexec/rbenv-sh-shell +++ b/libexec/rbenv-sh-shell @@ -6,8 +6,8 @@ # rbenv shell --unset # # Sets a shell-specific Ruby version by setting the `RBENV_VERSION' -# environment variable in your shell. This version overrides both -# project-specific versions and the global version. +# environment variable in your shell. This version overrides local +# application-specific versions and the global version. # # should be a string matching a Ruby version known to rbenv. # The special version string `system' will use your default system Ruby. From e56885f4c91e349817c4ac217dd4bfa59bd43cf4 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Thu, 3 Jan 2013 10:06:12 -0600 Subject: [PATCH 254/384] "binary" -> "executable" --- README.md | 22 +++++++++++----------- libexec/rbenv-rehash | 9 +++++---- libexec/rbenv-which | 4 ++-- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index d6e07b57..9aaaded3 100644 --- a/README.md +++ b/README.md @@ -57,15 +57,15 @@ rbenv correspond to subdirectories of `~/.rbenv/versions`. For example, you might have `~/.rbenv/versions/1.8.7-p354` and `~/.rbenv/versions/1.9.3-p327`. -Each version is a working tree with its own binaries, like +Each version is a working tree with its own executables, like `~/.rbenv/versions/1.8.7-p354/bin/ruby` and -`~/.rbenv/versions/1.9.3-p327/bin/irb`. rbenv makes _shim binaries_ -for every such binary across all installed versions of Ruby. +`~/.rbenv/versions/1.9.3-p327/bin/irb`. rbenv makes _shim executables_ +for every such executable across all installed versions of Ruby. These shims are simple wrapper scripts that live in `~/.rbenv/shims` and detect which Ruby version you want to use. They insert the directory for the selected version at the beginning of your `$PATH` -and then execute the corresponding binary. +and then invoke the corresponding executable. ## Installation ## @@ -131,9 +131,9 @@ easy to fork and contribute any changes back upstream. 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). +6. Rebuild the shim executables. You should do this any time you + install a new Ruby executable (for example, when installing a new + Ruby version, or when installing a gem that provides a command). ~~~ $ rbenv rehash @@ -304,16 +304,16 @@ how it was set. ### rbenv rehash ### -Installs shims for all Ruby binaries known to rbenv (i.e., +Installs shims for all Ruby executables known to rbenv (i.e., `~/.rbenv/versions/*/bin/*`). Run this command after you install a new -version of Ruby, or install a gem that provides binaries. +version of Ruby, or install a gem that provides commands. $ rbenv rehash ### rbenv which ### -Displays the full path to the binary that rbenv will execute when you -run the given command. +Displays the full path to the executable that rbenv will invoke when +you run the given command. $ rbenv which irb /Users/sam/.rbenv/versions/1.9.3-p327/bin/irb diff --git a/libexec/rbenv-rehash b/libexec/rbenv-rehash index 07608d9d..8f74b529 100755 --- a/libexec/rbenv-rehash +++ b/libexec/rbenv-rehash @@ -32,9 +32,9 @@ remove_prototype_shim() { # The prototype shim file is a script that re-execs itself, passing # its filename and any arguments to `rbenv exec`. This file is -# hard-linked for every binary and then removed. The linking technique -# is fast, uses less disk space than unique files, and also serves as -# a locking mechanism. +# hard-linked for every executable and then removed. The linking +# technique is fast, uses less disk space than unique files, and also +# serves as a locking mechanism. create_prototype_shim() { cat > "$PROTOTYPE_SHIM_PATH" < # -# Displays the full path to the binary that rbenv will execute when you -# run the given command. +# Displays the full path to the executable that rbenv will invoke when +# you run the given command. set -e [ -n "$RBENV_DEBUG" ] && set -x From 871f0e26df5ea4ea57bcc9097254b5ae67f2669d Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Thu, 3 Jan 2013 10:09:22 -0600 Subject: [PATCH 255/384] Tone down the RVM incompatibility notice --- README.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 9aaaded3..a61dc9e4 100644 --- a/README.md +++ b/README.md @@ -69,10 +69,9 @@ and then invoke the corresponding executable. ## Installation ## -**Compatibility note**: rbenv is _incompatible_ with rvm. Things will - appear to work until you try to install a gem. The problem is that - rvm actually overrides the `gem` command with a shell function! - Please remove any references to rvm before using rbenv. +**Compatibility note**: rbenv is _incompatible_ with RVM. Please make + sure to fully uninstall RVM and remove any references to it from + your shell initialization files before installing rbenv. If you're on Mac OS X, consider [installing with Homebrew](#homebrew-on-mac-os-x). From 9a284a3da410a0b7807995a612d738102cd92afd Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Thu, 3 Jan 2013 10:20:52 -0600 Subject: [PATCH 256/384] Update the uninstallation section --- README.md | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index a61dc9e4..ec216df7 100644 --- a/README.md +++ b/README.md @@ -213,12 +213,17 @@ hood. ### Uninstalling Ruby Versions ### -As time goes on, ruby versions you install will accumulate in your +As time goes on, Ruby versions you install will accumulate in your `~/.rbenv/versions` directory. -There is no uninstall or remove command in `rbenv`, so removing old -versions is a simple matter of `rm -rf` the directory of the relevant -ruby version you want removed under `~/.rbenv/versions` +To remove old Ruby versions, simply `rm -rf` the directory of the +version you want to remove. You can find the directory of a particular +Ruby verison with the `rbenv prefix` command, e.g. `rbenv prefix +1.8.7-p357`. + +The [ruby-build](https://github.com/sstephenson/ruby-build) plugin +provides an `rbenv uninstall` command to automate the removal +process. ## Usage ## From 7e85ae7bd25ab6c30ea2b5323822b1846a3e5c25 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Thu, 3 Jan 2013 10:25:31 -0600 Subject: [PATCH 257/384] "Usage" -> "Command Reference" --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ec216df7..edfd98a4 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ bulletproof deployments. * [Homebrew on Mac OS X](#homebrew-on-mac-os-x) * [Neckbeard Configuration](#neckbeard-configuration) * [Uninstalling Ruby Versions](#uninstalling-ruby-versions) -* [Usage](#usage) +* [Command Reference](#command-reference) * [rbenv global](#rbenv-global) * [rbenv local](#rbenv-local) * [rbenv shell](#rbenv-shell) @@ -225,7 +225,7 @@ The [ruby-build](https://github.com/sstephenson/ruby-build) plugin provides an `rbenv uninstall` command to automate the removal process. -## Usage ## +## Command Reference ## Like `git`, the `rbenv` command delegates to subcommands based on its first argument. The most common subcommands are: From 266d896871cd0374e6fb68c85c01848c101d4278 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Thu, 3 Jan 2013 10:39:48 -0600 Subject: [PATCH 258/384] Prioritize `rbenv local` over `rbenv global` and `rbenv shell` --- README.md | 38 +++++++++++++++++++------------------- libexec/rbenv-help | 2 +- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index edfd98a4..c47d7d15 100644 --- a/README.md +++ b/README.md @@ -38,8 +38,8 @@ bulletproof deployments. * [Neckbeard Configuration](#neckbeard-configuration) * [Uninstalling Ruby Versions](#uninstalling-ruby-versions) * [Command Reference](#command-reference) - * [rbenv global](#rbenv-global) * [rbenv local](#rbenv-local) + * [rbenv global](#rbenv-global) * [rbenv shell](#rbenv-shell) * [rbenv versions](#rbenv-versions) * [rbenv version](#rbenv-version) @@ -230,30 +230,15 @@ process. Like `git`, the `rbenv` command delegates to subcommands based on its first argument. The most common subcommands are: -### rbenv global ### - -Sets the global version of Ruby to be used in all shells by writing -the version name to the `~/.rbenv/version` file. This version can be -overridden by an application-specific `.ruby-version` file, or by -setting the `RBENV_VERSION` environment variable. - - $ rbenv global 1.9.3-p327 - -The special version name `system` tells rbenv to use the system Ruby -(detected by searching your `$PATH`). - -When run without a version number, `rbenv global` reports the -currently configured global version. - ### rbenv local ### Sets a local application-specific Ruby version by writing the version name to a `.ruby-version` file in the current directory. This version -overrides the global, and can be overridden itself by setting the -`RBENV_VERSION` environment variable or with the `rbenv shell` +overrides the global version, and can be overridden itself by setting +the `RBENV_VERSION` environment variable or with the `rbenv shell` command. - $ rbenv local rbx-1.2.4 + $ rbenv local 1.9.3-p327 When run without a version number, `rbenv local` reports the currently configured local version. You can also unset the local version: @@ -265,6 +250,21 @@ file named `.rbenv-version`. For backwards compatibility, rbenv will read a local version specified in an `.rbenv-version` file, but a `.ruby-version` file in the same directory will take precedence. +### rbenv global ### + +Sets the global version of Ruby to be used in all shells by writing +the version name to the `~/.rbenv/version` file. This version can be +overridden by an application-specific `.ruby-version` file, or by +setting the `RBENV_VERSION` environment variable. + + $ rbenv global 1.8.7-p352 + +The special version name `system` tells rbenv to use the system Ruby +(detected by searching your `$PATH`). + +When run without a version number, `rbenv global` reports the +currently configured global version. + ### rbenv shell ### Sets a shell-specific Ruby version by setting the `RBENV_VERSION` diff --git a/libexec/rbenv-help b/libexec/rbenv-help index ca3607d9..6dd6fd6e 100755 --- a/libexec/rbenv-help +++ b/libexec/rbenv-help @@ -143,7 +143,7 @@ if [ -z "$1" ] || [ "$1" == "rbenv" ]; then [ -z "$usage" ] || exit echo echo "Some useful rbenv commands are:" - print_summaries commands global local shell install uninstall rehash version versions which whence + print_summaries commands local global shell install uninstall rehash version versions which whence echo echo "See \`rbenv help ' for information on a specific command." echo "For full documentation, see: https://github.com/sstephenson/rbenv#readme" From 6fe338e563b2d8f975f45fd2070cc07252fc5108 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Thu, 3 Jan 2013 12:40:54 -0600 Subject: [PATCH 259/384] New tagline --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c47d7d15..e82d2d0e 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Simple Ruby Version Management: rbenv +# Groom your Ruby environment with rbenv. Use rbenv to pick a Ruby version for your application and guarantee that your development environment matches production. Put rbenv to work From 5174d14d5c49561f5bc34efe9c7e9fdd9545d315 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Thu, 3 Jan 2013 12:49:03 -0600 Subject: [PATCH 260/384] It's all about the apps --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e82d2d0e..a3655835 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Groom your Ruby environment with rbenv. +# Groom your app’s Ruby environment with rbenv. Use rbenv to pick a Ruby version for your application and guarantee that your development environment matches production. Put rbenv to work From 308aa42b676a314bed44cca72e3309b51c0e607f Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Thu, 3 Jan 2013 21:18:05 -0600 Subject: [PATCH 261/384] Rewrite "How It Works" with @trevorturk --- README.md | 138 +++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 101 insertions(+), 37 deletions(-) diff --git a/README.md b/README.md index a3655835..2e9de59d 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,10 @@ bulletproof deployments. ## Table of Contents * [How It Works](#how-it-works) + * [Understanding PATH](#understanding-path) + * [Understanding Shims](#understanding-shims) + * [Choosing the Ruby Version](#choosing-the-ruby-version) + * [Locating the Ruby Installation](#locating-the-ruby-installation) * [Installation](#installation) * [Basic GitHub Checkout](#basic-github-checkout) * [Upgrading](#upgrading) @@ -50,24 +54,89 @@ bulletproof deployments. * [Version History](#version-history) * [License](#license) -## How It Works ## +## How It Works -rbenv operates on the per-user directory `~/.rbenv`. Version names in -rbenv correspond to subdirectories of `~/.rbenv/versions`. For -example, you might have `~/.rbenv/versions/1.8.7-p354` and -`~/.rbenv/versions/1.9.3-p327`. +At at high level, rbenv intercepts Ruby commands using shim +executables injected into your `PATH`, determines which Ruby version +has been specified by your application, and passes your commands along +to the correct Ruby installation. -Each version is a working tree with its own executables, like -`~/.rbenv/versions/1.8.7-p354/bin/ruby` and -`~/.rbenv/versions/1.9.3-p327/bin/irb`. rbenv makes _shim executables_ -for every such executable across all installed versions of Ruby. +### Understanding PATH -These shims are simple wrapper scripts that live in `~/.rbenv/shims` -and detect which Ruby version you want to use. They insert the -directory for the selected version at the beginning of your `$PATH` -and then invoke the corresponding executable. +When you run a command like `ruby` or `rake`, your operating system +searches through a list of directories to find an executable file with +that name. This list of directories lives in an environment variable +called `PATH`, with each directory in the list separated by a colon: -## Installation ## + /usr/local/bin:/usr/bin:/bin + +Directories in `PATH` are searched from left to right, so a matching +executable in a directory at the beginning of the list takes +precedence over another one at the end. In this example, the +`/usr/local/bin` directory will be searched first, then `/usr/bin`, +then `/bin`. + +### Understanding Shims + +rbenv works by inserting a directory of _shims_ at the front of your +`PATH`: + + ~/.rbenv/shims:/usr/local/bin:/usr/bin:/bin + +Through a process called _rehashing_, rbenv maintains shims in that +directory to match every Ruby command across every installed version +of Ruby—`irb`, `gem`, `rake`, `rails`, `ruby`, and so on. + +Shims are lightweight executables that simply pass your command along +to rbenv. So with rbenv installed, when you run, say, `rake`, your +operating system will do the following: + +* Search your `PATH` for an executable file named `rake` +* Find the rbenv shim named `rake` at the beginning of your `PATH` +* Run the shim named `rake`, which in turn passes the command along to + rbenv + +### Choosing the Ruby Version + +When you execute a shim, rbenv determines which Ruby version to use by +reading it from the following sources, in this order: + +1. The `RBENV_VERSION` environment variable, if specified. You can use + the [`rbenv shell`](#rbenv-shell) command to set this environment + variable in your current shell session. + +2. The application-specific `.ruby-version` file in the current + directory, if present. You can modify the current directory's + `.ruby-version` file with the [`rbenv local`](#rbenv-local) + command. + +3. The first `.ruby-version` file found by searching each parent + directory until reaching the root of your filesystem, if any. + +4. The global `~/.rbenv/version` file. You can modify this file using + the [`rbenv global`](#rbenv-global) command. If the global version + file is not present, rbenv assumes you want to use the "system" + Ruby—i.e. whatever version would be run if rbenv weren't in your + path. + +### Locating the Ruby Installation + +Once rbenv has determined which version of Ruby your application has +specified, it passes the command along to the corresponding Ruby +installation. + +Each Ruby version is installed into its own directory under +`~/.rbenv/versions`. For example, you might have these versions +installed: + +* `~/.rbenv/versions/1.8.7-p371/` +* `~/.rbenv/versions/1.9.3-p327/` +* `~/.rbenv/versions/jruby-1.7.1/` + +Version names to rbenv are simply the names of the directories in +`~/.rbenv/versions`. + +## Installation **Compatibility note**: rbenv is _incompatible_ with RVM. Please make sure to fully uninstall RVM and remove any references to it from @@ -76,7 +145,7 @@ and then invoke the corresponding executable. If you're on Mac OS X, consider [installing with Homebrew](#homebrew-on-mac-os-x). -### Basic GitHub Checkout ### +### Basic GitHub Checkout This will get you going with the latest version of rbenv and make it easy to fork and contribute any changes back upstream. @@ -138,7 +207,7 @@ easy to fork and contribute any changes back upstream. $ rbenv rehash ~~~ -#### Upgrading #### +#### Upgrading If you've installed rbenv manually using git, you can upgrade your installation to the cutting-edge version at any time. @@ -153,15 +222,10 @@ To use a specific release of rbenv, check out the corresponding tag: ~~~ sh $ cd ~/.rbenv $ git fetch -$ git tag -v0.1.0 -v0.1.1 -v0.1.2 -v0.2.0 -$ git checkout v0.2.0 +$ git checkout v0.3.0 ~~~ -### Homebrew on Mac OS X ### +### Homebrew on Mac OS X You can also install rbenv using the [Homebrew](http://mxcl.github.com/homebrew/) package manager on Mac OS @@ -179,7 +243,7 @@ Afterwards you'll still need to add `eval "$(rbenv init -)"` to your profile as stated in the caveats. You'll only ever have to do this once. -### Neckbeard Configuration ### +### Neckbeard Configuration Skip this section unless you must know what every line in your shell profile is doing. @@ -211,7 +275,7 @@ opposed to this idea. Here's what `rbenv init` actually does: Run `rbenv init -` for yourself to see exactly what happens under the hood. -### Uninstalling Ruby Versions ### +### Uninstalling Ruby Versions As time goes on, Ruby versions you install will accumulate in your `~/.rbenv/versions` directory. @@ -225,12 +289,12 @@ The [ruby-build](https://github.com/sstephenson/ruby-build) plugin provides an `rbenv uninstall` command to automate the removal process. -## Command Reference ## +## Command Reference Like `git`, the `rbenv` command delegates to subcommands based on its first argument. The most common subcommands are: -### rbenv local ### +### rbenv local Sets a local application-specific Ruby version by writing the version name to a `.ruby-version` file in the current directory. This version @@ -250,7 +314,7 @@ file named `.rbenv-version`. For backwards compatibility, rbenv will read a local version specified in an `.rbenv-version` file, but a `.ruby-version` file in the same directory will take precedence. -### rbenv global ### +### rbenv global Sets the global version of Ruby to be used in all shells by writing the version name to the `~/.rbenv/version` file. This version can be @@ -265,7 +329,7 @@ The special version name `system` tells rbenv to use the system Ruby When run without a version number, `rbenv global` reports the currently configured global version. -### rbenv shell ### +### rbenv shell Sets a shell-specific Ruby version by setting the `RBENV_VERSION` environment variable in your shell. This version overrides @@ -285,7 +349,7 @@ prefer not to use shell integration, you may simply set the $ export RBENV_VERSION=jruby-1.7.1 -### rbenv versions ### +### rbenv versions Lists all Ruby versions known to rbenv, and shows an asterisk next to the currently active version. @@ -298,7 +362,7 @@ the currently active version. rbx-1.2.4 ree-1.8.7-2011.03 -### rbenv version ### +### rbenv version Displays the currently active Ruby version, along with information on how it was set. @@ -306,7 +370,7 @@ how it was set. $ rbenv version 1.8.7-p352 (set by /Volumes/37signals/basecamp/.ruby-version) -### rbenv rehash ### +### rbenv rehash Installs shims for all Ruby executables known to rbenv (i.e., `~/.rbenv/versions/*/bin/*`). Run this command after you install a new @@ -314,7 +378,7 @@ version of Ruby, or install a gem that provides commands. $ rbenv rehash -### rbenv which ### +### rbenv which Displays the full path to the executable that rbenv will invoke when you run the given command. @@ -322,7 +386,7 @@ you run the given command. $ rbenv which irb /Users/sam/.rbenv/versions/1.9.3-p327/bin/irb -### rbenv whence ### +### rbenv whence Lists all Ruby versions with the given command installed. @@ -331,7 +395,7 @@ Lists all Ruby versions with the given command installed. jruby-1.7.1 ree-1.8.7-2011.03 -## Development ## +## Development The rbenv source code is [hosted on GitHub](https://github.com/sstephenson/rbenv). It's clean, modular, @@ -340,7 +404,7 @@ and easy to understand, even if you're not a shell hacker. Please feel free to submit pull requests and file bugs on the [issue tracker](https://github.com/sstephenson/rbenv/issues). -### Version History ### +### Version History **0.3.0** (December 25, 2011) @@ -416,7 +480,7 @@ tracker](https://github.com/sstephenson/rbenv/issues). * Initial public release. -### License ### +### License (The MIT license) From 9c45206c2877169db55df8a025c77e5489ac5561 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Thu, 3 Jan 2013 21:22:17 -0600 Subject: [PATCH 262/384] Remove unused doc directory --- doc/filter-toc | 4 ---- doc/mdtoc | 33 --------------------------------- 2 files changed, 37 deletions(-) delete mode 100755 doc/filter-toc delete mode 100755 doc/mdtoc diff --git a/doc/filter-toc b/doc/filter-toc deleted file mode 100755 index 761288be..00000000 --- a/doc/filter-toc +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash -# Render Markdown ToC with only headings appearing after "Table of Contents" -dir="$(dirname "$0")" -"$dir"/mdtoc "$1" | sed -n '/table-of-contents/,$p' | grep -v table-of-contents diff --git a/doc/mdtoc b/doc/mdtoc deleted file mode 100755 index 5d635542..00000000 --- a/doc/mdtoc +++ /dev/null @@ -1,33 +0,0 @@ -#!/usr/bin/env ruby -require 'escape_utils' - -start_at_level = 2 - -headers = Hash.new(0) - -anchor = lambda { |title| - href = title.downcase - href.gsub!(/[^\w\- ]/, '') # remove punctuation - href.gsub!(' ', '-') # replace spaces with dash - href = EscapeUtils.escape_uri(href) # escape extended UTF-8 chars - - uniq = (headers[href] > 0) ? "-#{headers[href]}" : '' - headers[href] += 1 - - href + uniq -} - -ARGF.each_line do |line| - if line =~ /^(#+) (.+?)#*$/ - level = $1.size - next if level < start_at_level - title = $2.strip - href = anchor.call title - - puts "%s* [%s](#%s)" % [ - ' ' * (level - start_at_level), - title, - href - ] - end -end From 41cfa5f3d03260edb6515b7e00d21c224ff8a4ab Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Fri, 4 Jan 2013 09:19:18 -0600 Subject: [PATCH 263/384] Link to the binstubs wiki page --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2e9de59d..39cb91b5 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ bulletproof deployments. **Rock-solid in production.** Your application's executables are its interface with ops. With rbenv and [Bundler - binstubs](http://yehudakatz.com/2011/05/30/gem-versioning-and-bundler-doing-it-right/) + binstubs](https://github.com/sstephenson/rbenv/wiki/Understanding-binstubs) you'll never again need to `cd` in a cron job or Chef recipe to ensure you've selected the right runtime. The Ruby version dependency lives in one place—your app—so upgrades and rollbacks are From 7f975a37f9ae9f148509e4e6aef7714d7f2a9f64 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Fri, 4 Jan 2013 10:12:29 -0600 Subject: [PATCH 264/384] Deprecate ruby-local-exec --- bin/ruby-local-exec | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/bin/ruby-local-exec b/bin/ruby-local-exec index a2064370..97d0a3df 100755 --- a/bin/ruby-local-exec +++ b/bin/ruby-local-exec @@ -13,4 +13,11 @@ set -e export RBENV_DIR="${1%/*}" + +[ -n "$RBENV_SILENCE_WARNINGS" ] || { + echo "rbenv: \`ruby-local-exec' is deprecated and will be removed in the next release." + echo " To upgrade: https://github.com/sstephenson/rbenv/wiki/ruby-local-exec" + echo +} >&2 + exec ruby "$@" From c6855e01a9fe66b3ad0a53bb4fc0918798460d23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohnic=CC=81?= Date: Fri, 4 Jan 2013 17:58:38 +0100 Subject: [PATCH 265/384] zshenv -> zshrc. update Ubuntu/zsh installation notices --- README.md | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 39cb91b5..2390c7c0 100644 --- a/README.md +++ b/README.md @@ -163,13 +163,9 @@ easy to fork and contribute any changes back upstream. $ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile ~~~ - **Zsh note**: Modify your `~/.zshenv` file instead of `~/.bash_profile`. + **Ubuntu note**: Modify your `~/.profile` instead of `~/.bash_profile`. - **Ubuntu note**: Ubuntu uses `~/.profile` for enabling certain path - changes. This file won't be read if you create a `~/.bash_profile`. - Therefore, it's recommended that you add this line and the one in - point 3 below to your `~/.profile`. This has the added advantage - of working under both bash and zsh. + **Zsh note**: Modify your `~/.zshrc` file instead of `~/.bash_profile`. 3. Add `rbenv init` to your shell to enable shims and autocompletion. @@ -177,9 +173,7 @@ easy to fork and contribute any changes back upstream. $ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile ~~~ - **Zsh note**: Modify your `~/.zshenv` file instead of `~/.bash_profile`. - - **Ubuntu note**: Same as Ubuntu note for point 2 above. + _Same as in previous step, use `~/.profile` on Ubuntu, `~/.zshrc` for zsh._ 4. Restart your shell as a login shell so the path changes take effect. You can now begin using rbenv. From b66eeaf2f7e18efe23b0d2badfb47d87e943537e Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Fri, 4 Jan 2013 12:23:41 -0600 Subject: [PATCH 266/384] Link up the "Why choose rbenv?" wiki page --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 2390c7c0..12666f38 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,9 @@ bulletproof deployments. See more [plugins on the wiki](https://github.com/sstephenson/rbenv/wiki/Plugins). +[**Why choose rbenv over +RVM?**](https://github.com/sstephenson/rbenv/wiki/Why-rbenv%3F) + ## Table of Contents * [How It Works](#how-it-works) From 9375e99f921f428849f19efe2a2e500b3295d1a7 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Fri, 4 Jan 2013 12:27:26 -0600 Subject: [PATCH 267/384] rbenv 0.4.0 --- README.md | 50 +++++++++++++++++++++++++++++++++++++++++ libexec/rbenv---version | 2 +- 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 12666f38..8da425a3 100644 --- a/README.md +++ b/README.md @@ -403,6 +403,56 @@ tracker](https://github.com/sstephenson/rbenv/issues). ### Version History +**0.4.0** (January 4, 2013) + +* rbenv now prefers `.ruby-version` files to `.rbenv-version` files + for specifying local application-specific versions. The + `.ruby-version` file has the same format as `.rbenv-version` but is + [compatible with other Ruby version + managers](https://gist.github.com/1912050). +* Deprecated `ruby-local-exec` and moved its functionality into the + standard `ruby` shim. See the [ruby-local-exec wiki + page](https://github.com/sstephenson/wiki/ruby-local-exec) for + upgrade instructions. +* Modified shims to include the full path to rbenv so that they can be + invoked without having rbenv's bin directory in the `$PATH`. +* Sped up `rbenv init` by avoiding rbenv reinintialization and by + using a simpler indexing approach. (Users of + [chef-rbenv](https://github.com/fnichol/chef-rbenv) should upgrade + to the latest version to fix a [compatibility + issue](https://github.com/fnichol/chef-rbenv/pull/26).) +* Reworked `rbenv help` so that usage and documentation is stored as a + comment in each subcommand, enabling plugin commands to hook into + the help system. +* Added support for full completion of the command line, not just the + first argument. +* Updated installation instructions for Zsh and Ubuntu users. +* Fixed `rbenv which` and `rbenv prefix` with system Ruby versions. +* Changed `rbenv exec` to avoid prepending the system Ruby location to + `$PATH` to fix issues running system Ruby commands that invoke other + commands. +* Changed `rbenv rehash` to ensure it exits with a 0 status code under + normal operation, and to ensure outdated shims are removed first + when rehashing. +* Modified `rbenv rehash` to run `hash -r` afterwards, when shell + integration is enabled, to ensure the shell's command cache is + cleared. +* Removed use of the `+=` operator to support older versions of Bash. +* Adjusted non-bare `rbenv versions` output to include `system`, if + present. +* Improved documentation for installing and uninstalling Ruby + versions. +* Fixed `rbenv versions` not to display a warning if the currently + specified version doesn't exist. +* Fixed an instance of local variable leakage in the `rbenv` shell + function wrapper. +* Changed `rbenv shell` to ensure it exits with a non-zero status on + failure. +* Added `rbenv --version` for printing the current version of rbenv. +* Added `/usr/lib/rbenv/hooks` to the plugin hook search path. +* Fixed `rbenv which` to account for path entries with spaces. +* Changed `rbenv init` to accept option arguments in any order. + **0.3.0** (December 25, 2011) * Added an `rbenv root` command which prints the value of diff --git a/libexec/rbenv---version b/libexec/rbenv---version index 222ad004..ba5c562f 100755 --- a/libexec/rbenv---version +++ b/libexec/rbenv---version @@ -12,7 +12,7 @@ set -e [ -n "$RBENV_DEBUG" ] && set -x -version=0.3.0 +version="0.4.0" cd "$RBENV_ROOT" git_revision="$(git describe --tags HEAD 2>/dev/null || true)" From c56f72794ed8388af17a5d1ff3dedf9f00695454 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Fri, 4 Jan 2013 12:40:20 -0600 Subject: [PATCH 268/384] Fix ruby-local-exec wiki page link in the changelog --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8da425a3..fdf0801a 100644 --- a/README.md +++ b/README.md @@ -412,7 +412,7 @@ tracker](https://github.com/sstephenson/rbenv/issues). managers](https://gist.github.com/1912050). * Deprecated `ruby-local-exec` and moved its functionality into the standard `ruby` shim. See the [ruby-local-exec wiki - page](https://github.com/sstephenson/wiki/ruby-local-exec) for + page](https://github.com/sstephenson/rbenv/wiki/ruby-local-exec) for upgrade instructions. * Modified shims to include the full path to rbenv so that they can be invoked without having rbenv's bin directory in the `$PATH`. From 093809eac6697287884f6aa061e71c6e4c2ce484 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohnic=CC=81?= Date: Fri, 4 Jan 2013 23:17:52 +0100 Subject: [PATCH 269/384] spellcheck --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index fdf0801a..3b0c7cb6 100644 --- a/README.md +++ b/README.md @@ -176,7 +176,7 @@ easy to fork and contribute any changes back upstream. $ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile ~~~ - _Same as in previous step, use `~/.profile` on Ubuntu, `~/.zshrc` for zsh._ + _Same as in previous step, use `~/.profile` on Ubuntu, `~/.zshrc` for Zsh._ 4. Restart your shell as a login shell so the path changes take effect. You can now begin using rbenv. @@ -246,7 +246,7 @@ Skip this section unless you must know what every line in your shell profile is doing. `rbenv init` is the only command that crosses the line of loading -extra commands into your shell. Coming from rvm, some of you might be +extra commands into your shell. Coming from RVM, some of you might be opposed to this idea. Here's what `rbenv init` actually does: 1. Sets up your shims path. This is the only requirement for rbenv to @@ -259,7 +259,7 @@ opposed to this idea. Here's what `rbenv init` actually does: users. 3. Rehashes shims. From time to time you'll need to rebuild your - shim files. Doing this on init makes sure everything is up to + shim files. Doing this automatically makes sure everything is up to date. You can always run `rbenv rehash` manually. 4. Installs the sh dispatcher. This bit is also optional, but allows @@ -279,7 +279,7 @@ As time goes on, Ruby versions you install will accumulate in your To remove old Ruby versions, simply `rm -rf` the directory of the version you want to remove. You can find the directory of a particular -Ruby verison with the `rbenv prefix` command, e.g. `rbenv prefix +Ruby version with the `rbenv prefix` command, e.g. `rbenv prefix 1.8.7-p357`. The [ruby-build](https://github.com/sstephenson/ruby-build) plugin @@ -416,7 +416,7 @@ tracker](https://github.com/sstephenson/rbenv/issues). upgrade instructions. * Modified shims to include the full path to rbenv so that they can be invoked without having rbenv's bin directory in the `$PATH`. -* Sped up `rbenv init` by avoiding rbenv reinintialization and by +* Sped up `rbenv init` by avoiding rbenv reinitialization and by using a simpler indexing approach. (Users of [chef-rbenv](https://github.com/fnichol/chef-rbenv) should upgrade to the latest version to fix a [compatibility @@ -457,7 +457,7 @@ tracker](https://github.com/sstephenson/rbenv/issues). * Added an `rbenv root` command which prints the value of `$RBENV_ROOT`, or the default root directory if it's unset. -* Clarified Zsh installation instructions in the readme. +* Clarified Zsh installation instructions in the Readme. * Removed some redundant code in `rbenv rehash`. * Fixed an issue with calling `readlink` for paths with spaces. * Changed Zsh initialization code to install completion hooks only for From cd940bd797ea8230f58629527608337dca4c9a2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohnic=CC=81?= Date: Fri, 4 Jan 2013 23:26:01 +0100 Subject: [PATCH 270/384] typo in docs --- libexec/rbenv-rehash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libexec/rbenv-rehash b/libexec/rbenv-rehash index 8f74b529..b05a4c76 100755 --- a/libexec/rbenv-rehash +++ b/libexec/rbenv-rehash @@ -92,7 +92,7 @@ registered_shims=() registered_shims_index="" # We will keep track of shims registered for installation with the -# global `reigstered_shims` array and with a global search index +# global `registered_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. From 14ff078b8556504b71a9d35e1acbc187aead94d0 Mon Sep 17 00:00:00 2001 From: Carlos Rodriguez Date: Fri, 4 Jan 2013 15:14:36 -0800 Subject: [PATCH 271/384] Removed double 'at' from README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3b0c7cb6..d3e1cf86 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ RVM?**](https://github.com/sstephenson/rbenv/wiki/Why-rbenv%3F) ## How It Works -At at high level, rbenv intercepts Ruby commands using shim +At a high level, rbenv intercepts Ruby commands using shim executables injected into your `PATH`, determines which Ruby version has been specified by your application, and passes your commands along to the correct Ruby installation. From 1d687ac734a42cf179d41fb850705f8db9932c3c Mon Sep 17 00:00:00 2001 From: Leo Cassarani Date: Sat, 5 Jan 2013 16:52:57 +0000 Subject: [PATCH 272/384] Fix incorrect formatting of rbenv-help output under MAWK In systems that use the MAWK interpreter (the default AWK installed with Ubuntu), the output of `rbenv help ` would have no line breaks. The issue is fixed by changing `gsub` to `sub` in the snippet of awk commands that are used to extract documentation comments. I suspect the bug is something to do with the way the '^' and '$' characters are interpreted by different AWK interpreters (per-line vs per-string anchors). If I understand correctly, the purpose of trim() is to remove all line breaks from the start and end of each sections of a command's documentation, in which case `sub` should serve the same purpose. --- libexec/rbenv-help | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libexec/rbenv-help b/libexec/rbenv-help index 6dd6fd6e..f15e83fd 100755 --- a/libexec/rbenv-help +++ b/libexec/rbenv-help @@ -64,8 +64,8 @@ collect_documentation() { } function trim(str) { - gsub(/^\n*/, "", str) - gsub(/\n*$/, "", str) + sub(/^\n*/, "", str) + sub(/\n*$/, "", str) return str } From 1d4261a9979851f3878511fc9137387c18b7ccc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacky=20Alcin=C3=A9?= Date: Wed, 9 Jan 2013 16:45:08 -0500 Subject: [PATCH 273/384] Added 'sources' to the Git ignores. --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 7e2eb978..a615996c 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ /shims /version /versions +/sources From 892aea138e84c43126ee26cba817c6aaf5a9f084 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Wed, 23 Jan 2013 19:05:26 -0600 Subject: [PATCH 274/384] Export PS4 when RBENV_DEBUG is set for more informative debug output --- libexec/rbenv | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libexec/rbenv b/libexec/rbenv index 76928647..93089fe9 100755 --- a/libexec/rbenv +++ b/libexec/rbenv @@ -1,7 +1,11 @@ #!/usr/bin/env bash set -e -[ -n "$RBENV_DEBUG" ] && set -x + +if [ -n "$RBENV_DEBUG" ]; then + export PS4='+ [${BASH_SOURCE##*/}:${LINENO}] ' + set -x +fi resolve_link() { $(type -p greadlink readlink | head -1) "$1" } From 3cb95b4d2da9901e1f1988dd31aa531817a43768 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Wed, 23 Jan 2013 19:06:08 -0600 Subject: [PATCH 275/384] Add `rbenv --debug ` as a shortcut for setting RBENV_DEBUG=1 --- libexec/rbenv | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libexec/rbenv b/libexec/rbenv index 93089fe9..05302e85 100755 --- a/libexec/rbenv +++ b/libexec/rbenv @@ -1,11 +1,16 @@ #!/usr/bin/env bash set -e +if [ "$1" = "--debug" ]; then + export RBENV_DEBUG=1 + shift +fi if [ -n "$RBENV_DEBUG" ]; then export PS4='+ [${BASH_SOURCE##*/}:${LINENO}] ' set -x fi + resolve_link() { $(type -p greadlink readlink | head -1) "$1" } From 98f45695dbe092261f9600d7cd0863fa0b1da556 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Fri, 25 Jan 2013 11:50:37 -0600 Subject: [PATCH 276/384] Suppress shell warnings when hashing is disabled by `set +h` --- libexec/rbenv-sh-rehash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libexec/rbenv-sh-rehash b/libexec/rbenv-sh-rehash index 9cc75265..7548861b 100755 --- a/libexec/rbenv-sh-rehash +++ b/libexec/rbenv-sh-rehash @@ -10,4 +10,4 @@ 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" +echo "hash -r 2>/dev/null || true" From e3f72ebae20768079ca4b4425a364900f3f16fc6 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Fri, 25 Jan 2013 12:02:11 -0600 Subject: [PATCH 277/384] Guard against exported `CDPATH` (fixes #316) --- libexec/rbenv | 1 + 1 file changed, 1 insertion(+) diff --git a/libexec/rbenv b/libexec/rbenv index 05302e85..0e70361d 100755 --- a/libexec/rbenv +++ b/libexec/rbenv @@ -1,5 +1,6 @@ #!/usr/bin/env bash set -e +export -n CDPATH if [ "$1" = "--debug" ]; then export RBENV_DEBUG=1 From 13f36e04160031f874b589ab8189761e1d8543ae Mon Sep 17 00:00:00 2001 From: YanhaoYang Date: Fri, 22 Feb 2013 21:41:57 +0800 Subject: [PATCH 278/384] rbenv(): preserve multiline output of `sh-*` commands --- libexec/rbenv-init | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libexec/rbenv-init b/libexec/rbenv-init index 0ae9cf47..d8de64a0 100755 --- a/libexec/rbenv-init +++ b/libexec/rbenv-init @@ -97,7 +97,7 @@ rbenv() { case "\$command" in ${commands[*]}) - eval \`rbenv "sh-\$command" "\$@"\`;; + eval "\`rbenv "sh-\$command" "\$@"\`";; *) command rbenv "\$command" "\$@";; esac From 0d1f1d09f029e818d966359e49a77505c84ff46d Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Sat, 23 Feb 2013 16:55:21 -0500 Subject: [PATCH 279/384] Fix multiple argument completion with zsh This changes the zsh completion to omit the final, incomplete command line argument when invoking rbenv completions, making it consistent with the bash completion. Since no built-in completion cares about the argument list, this inconsistency only affected plugins. --- completions/rbenv.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/completions/rbenv.zsh b/completions/rbenv.zsh index c439c5aa..5b23d42f 100644 --- a/completions/rbenv.zsh +++ b/completions/rbenv.zsh @@ -11,7 +11,7 @@ _rbenv() { if [ "${#words}" -eq 2 ]; then completions="$(rbenv commands)" else - completions="$(rbenv completions ${words[2,-1]})" + completions="$(rbenv completions ${words[2,-2]})" fi reply=("${(ps:\n:)completions}") From 1fe59e41ea28511b0260bcdd7638484c737ae1e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohnic=CC=81?= Date: Thu, 7 Mar 2013 00:13:50 -0500 Subject: [PATCH 280/384] error message when rehash fails on non-writable directory Fixes #238 --- libexec/rbenv-rehash | 6 +++++- test/rehash.bats | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100755 test/rehash.bats diff --git a/libexec/rbenv-rehash b/libexec/rbenv-rehash index b05a4c76..8a6d66d6 100755 --- a/libexec/rbenv-rehash +++ b/libexec/rbenv-rehash @@ -17,7 +17,11 @@ mkdir -p "$SHIM_PATH" set -o noclobber { echo > "$PROTOTYPE_SHIM_PATH" } 2>/dev/null || -{ echo "rbenv: cannot rehash: $PROTOTYPE_SHIM_PATH exists" +{ if [ -w "$SHIM_PATH" ]; then + echo "rbenv: cannot rehash: $PROTOTYPE_SHIM_PATH exists" + else + echo "rbenv: cannot rehash: $SHIM_PATH isn't writable" + fi exit 1 } >&2 set +o noclobber diff --git a/test/rehash.bats b/test/rehash.bats new file mode 100755 index 00000000..22f26d07 --- /dev/null +++ b/test/rehash.bats @@ -0,0 +1,33 @@ +#!/usr/bin/env bats + +export PATH="${BATS_TEST_DIRNAME}/../libexec:$PATH" + +RBENV_TEST_ROOT="${BATS_TMPDIR}/rbenv" +export RBENV_ROOT="$RBENV_TEST_ROOT" + +teardown() { + rm -rf "$RBENV_TEST_ROOT" +} + +@test "empty rehash" { + run rbenv-rehash + [ "$status" -eq 0 ] + [ -d "${RBENV_TEST_ROOT}/shims" ] + rmdir "${RBENV_TEST_ROOT}/shims" +} + +@test "shims directory not writable" { + mkdir -p "${RBENV_TEST_ROOT}/shims" + chmod -w "${RBENV_TEST_ROOT}/shims" + run rbenv-rehash + [ "$status" -eq 1 ] + [ "$output" = "rbenv: cannot rehash: ${RBENV_TEST_ROOT}/shims isn't writable" ] +} + +@test "rehash in progress" { + mkdir -p "${RBENV_TEST_ROOT}/shims" + touch "${RBENV_TEST_ROOT}/shims/.rbenv-shim" + run rbenv-rehash + [ "$status" -eq 1 ] + [ "$output" = "rbenv: cannot rehash: ${RBENV_TEST_ROOT}/shims/.rbenv-shim exists" ] +} From bb6bccb782bf3ff8a338463f0893f73781078e58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohnic=CC=81?= Date: Thu, 7 Mar 2013 15:05:49 -0500 Subject: [PATCH 281/384] tests galore --- README.md | 5 ++++ libexec/rbenv---version | 7 +++-- libexec/rbenv-shims | 2 ++ test/commands.bats | 27 ++++++++++++++++++ test/global.bats | 31 +++++++++++++++++++++ test/libexec/rbenv-echo | 2 ++ test/local.bats | 53 +++++++++++++++++++++++++++++++++++ test/prefix.bats | 25 +++++++++++++++++ test/rbenv.bats | 47 +++++++++++++++++++++++++++++++ test/rehash.bats | 34 ++++++++++------------ test/shell.bats | 35 +++++++++++++++++++++++ test/shims.bats | 29 +++++++++++++++++++ test/test_helper.bash | 62 +++++++++++++++++++++++++++++++++++++++++ 13 files changed, 336 insertions(+), 23 deletions(-) create mode 100644 test/commands.bats create mode 100644 test/global.bats create mode 100755 test/libexec/rbenv-echo create mode 100644 test/local.bats create mode 100644 test/prefix.bats create mode 100644 test/rbenv.bats create mode 100644 test/shell.bats create mode 100644 test/shims.bats create mode 100644 test/test_helper.bash diff --git a/README.md b/README.md index d3e1cf86..ff7fe446 100644 --- a/README.md +++ b/README.md @@ -398,6 +398,11 @@ The rbenv source code is [hosted on GitHub](https://github.com/sstephenson/rbenv). It's clean, modular, and easy to understand, even if you're not a shell hacker. +Tests are executed using [Bats](https://github.com/sstephenson/bats): + + $ bats test + $ bats test/.bats + Please feel free to submit pull requests and file bugs on the [issue tracker](https://github.com/sstephenson/rbenv/issues). diff --git a/libexec/rbenv---version b/libexec/rbenv---version index ba5c562f..79cb64d8 100755 --- a/libexec/rbenv---version +++ b/libexec/rbenv---version @@ -14,8 +14,9 @@ set -e version="0.4.0" -cd "$RBENV_ROOT" -git_revision="$(git describe --tags HEAD 2>/dev/null || true)" -git_revision="${git_revision#v}" +if cd "$RBENV_ROOT" 2>/dev/null; then + git_revision="$(git describe --tags HEAD 2>/dev/null || true)" + git_revision="${git_revision#v}" +fi echo "rbenv ${git_revision:-$version}" diff --git a/libexec/rbenv-shims b/libexec/rbenv-shims index 713ca5ab..9a1b0553 100755 --- a/libexec/rbenv-shims +++ b/libexec/rbenv-shims @@ -11,6 +11,8 @@ if [ "$1" = "--complete" ]; then exit fi +shopt -s nullglob + for command in "${RBENV_ROOT}/shims/"*; do if [ "$1" = "--short" ]; then echo "${command##*/}" diff --git a/test/commands.bats b/test/commands.bats new file mode 100644 index 00000000..2cac3940 --- /dev/null +++ b/test/commands.bats @@ -0,0 +1,27 @@ +#!/usr/bin/env bats + +load test_helper + +@test "commands" { + run rbenv-commands + assert_success + assert_line "init" + assert_line "rehash" + assert_line "shell" + refute_line "sh-shell" + assert_line "echo" +} + +@test "commands --sh" { + run rbenv-commands --sh + assert_success + refute_line "init" + assert_line "shell" +} + +@test "commands --no-sh" { + run rbenv-commands --no-sh + assert_success + assert_line "init" + refute_line "shell" +} diff --git a/test/global.bats b/test/global.bats new file mode 100644 index 00000000..f6dcc3e1 --- /dev/null +++ b/test/global.bats @@ -0,0 +1,31 @@ +#!/usr/bin/env bats + +load test_helper + +@test "default" { + run rbenv global + assert_success + assert_output "system" +} + +@test "read RBENV_ROOT/version" { + mkdir -p "$RBENV_ROOT" + echo "1.2.3" > "$RBENV_ROOT/version" + run rbenv-global + assert_success + assert_output "1.2.3" +} + +@test "set RBENV_ROOT/version" { + mkdir -p "$RBENV_ROOT/versions/1.2.3" + run rbenv-global "1.2.3" + assert_success + run rbenv global + assert_success "1.2.3" +} + +@test "fail setting invalid RBENV_ROOT/version" { + mkdir -p "$RBENV_ROOT" + run rbenv-global "1.2.3" + assert_failure "rbenv: version \`1.2.3' not installed" +} diff --git a/test/libexec/rbenv-echo b/test/libexec/rbenv-echo new file mode 100755 index 00000000..0a802df4 --- /dev/null +++ b/test/libexec/rbenv-echo @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +eval "echo \$$1" diff --git a/test/local.bats b/test/local.bats new file mode 100644 index 00000000..5ccdb2b5 --- /dev/null +++ b/test/local.bats @@ -0,0 +1,53 @@ +#!/usr/bin/env bats + +load test_helper + +setup() { + mkdir -p "${RBENV_TEST_DIR}/myproject" + cd "${RBENV_TEST_DIR}/myproject" +} + +@test "no version" { + assert [ ! -e "${PWD}/.ruby-version" ] + run rbenv-local + assert_failure "rbenv: no local version configured for this directory" +} + +@test "local version" { + echo "1.2.3" > .ruby-version + run rbenv-local + assert_success "1.2.3" +} + +@test "ignores version in parent directory" { + echo "1.2.3" > .ruby-version + mkdir -p "subdir" && cd "subdir" + run rbenv-local + assert_failure +} + +@test "ignores RBENV_DIR" { + echo "1.2.3" > .ruby-version + mkdir -p "$HOME" + echo "2.0-home" > "${HOME}/.ruby-version" + RBENV_DIR="$HOME" run rbenv-local + assert_success "1.2.3" +} + +@test "sets local version" { + mkdir -p "${RBENV_ROOT}/versions/1.2.3" + run rbenv-local 1.2.3 + assert_success "" + assert [ "$(cat .ruby-version)" = "1.2.3" ] +} + +@test "changes local version" { + echo "1.0-pre" > .ruby-version + mkdir -p "${RBENV_ROOT}/versions/1.2.3" + run rbenv-local + assert_success "1.0-pre" + run rbenv-local 1.2.3 + assert_success "" + run rbenv-local + assert_success "1.2.3" +} diff --git a/test/prefix.bats b/test/prefix.bats new file mode 100644 index 00000000..b7afa87e --- /dev/null +++ b/test/prefix.bats @@ -0,0 +1,25 @@ +#!/usr/bin/env bats + +load test_helper + +@test "prefix" { + mkdir -p "${RBENV_TEST_DIR}/myproject" + cd "${RBENV_TEST_DIR}/myproject" + echo "1.2.3" > .ruby-version + mkdir -p "${RBENV_ROOT}/versions/1.2.3" + run rbenv-prefix + assert_success "${RBENV_ROOT}/versions/1.2.3" +} + +@test "prefix for invalid version" { + RBENV_VERSION="1.2.3" run rbenv-prefix + assert_failure "rbenv: version \`1.2.3' not installed" +} + +@test "prefix for system" { + mkdir -p "${RBENV_TEST_DIR}/bin" + touch "${RBENV_TEST_DIR}/bin/ruby" + chmod +x "${RBENV_TEST_DIR}/bin/ruby" + RBENV_VERSION="system" run rbenv-prefix + assert_success "$RBENV_TEST_DIR" +} diff --git a/test/rbenv.bats b/test/rbenv.bats new file mode 100644 index 00000000..e8a939af --- /dev/null +++ b/test/rbenv.bats @@ -0,0 +1,47 @@ +#!/usr/bin/env bats + +load test_helper + +@test "blank invocation" { + run rbenv + assert_success + assert [ "${lines[0]}" = "rbenv 0.4.0" ] +} + +@test "invalid command" { + run rbenv does-not-exist + assert_failure + assert_output "rbenv: no such command \`does-not-exist'" +} + +@test "default RBENV_ROOT" { + RBENV_ROOT="" HOME=/home/mislav run rbenv root + assert_success + assert_output "/home/mislav/.rbenv" +} + +@test "inherited RBENV_ROOT" { + RBENV_ROOT=/opt/rbenv run rbenv root + assert_success + assert_output "/opt/rbenv" +} + +@test "default RBENV_DIR" { + run rbenv echo RBENV_DIR + assert_output "$(pwd)" +} + +@test "inherited RBENV_DIR" { + dir="${BATS_TMPDIR}/myproject" + mkdir -p "$dir" + RBENV_DIR="$dir" run rbenv echo RBENV_DIR + assert_output "$dir" +} + +@test "invalid RBENV_DIR" { + dir="${BATS_TMPDIR}/does-not-exist" + assert [ ! -d "$dir" ] + RBENV_DIR="$dir" run rbenv echo RBENV_DIR + assert_failure + assert_output "rbenv: cannot change working directory to \`$dir'" +} diff --git a/test/rehash.bats b/test/rehash.bats index 22f26d07..6e9e8907 100755 --- a/test/rehash.bats +++ b/test/rehash.bats @@ -1,33 +1,27 @@ #!/usr/bin/env bats -export PATH="${BATS_TEST_DIRNAME}/../libexec:$PATH" - -RBENV_TEST_ROOT="${BATS_TMPDIR}/rbenv" -export RBENV_ROOT="$RBENV_TEST_ROOT" - -teardown() { - rm -rf "$RBENV_TEST_ROOT" -} +load test_helper @test "empty rehash" { + assert [ ! -d "${RBENV_ROOT}/shims" ] run rbenv-rehash - [ "$status" -eq 0 ] - [ -d "${RBENV_TEST_ROOT}/shims" ] - rmdir "${RBENV_TEST_ROOT}/shims" + assert_success + assert [ -d "${RBENV_ROOT}/shims" ] + rmdir "${RBENV_ROOT}/shims" } -@test "shims directory not writable" { - mkdir -p "${RBENV_TEST_ROOT}/shims" - chmod -w "${RBENV_TEST_ROOT}/shims" +@test "non-writable shims directory" { + mkdir -p "${RBENV_ROOT}/shims" + chmod -w "${RBENV_ROOT}/shims" run rbenv-rehash - [ "$status" -eq 1 ] - [ "$output" = "rbenv: cannot rehash: ${RBENV_TEST_ROOT}/shims isn't writable" ] + assert_failure + assert_output "rbenv: cannot rehash: ${RBENV_ROOT}/shims isn't writable" } @test "rehash in progress" { - mkdir -p "${RBENV_TEST_ROOT}/shims" - touch "${RBENV_TEST_ROOT}/shims/.rbenv-shim" + mkdir -p "${RBENV_ROOT}/shims" + touch "${RBENV_ROOT}/shims/.rbenv-shim" run rbenv-rehash - [ "$status" -eq 1 ] - [ "$output" = "rbenv: cannot rehash: ${RBENV_TEST_ROOT}/shims/.rbenv-shim exists" ] + assert_failure + assert_output "rbenv: cannot rehash: ${RBENV_ROOT}/shims/.rbenv-shim exists" } diff --git a/test/shell.bats b/test/shell.bats new file mode 100644 index 00000000..94778985 --- /dev/null +++ b/test/shell.bats @@ -0,0 +1,35 @@ +#!/usr/bin/env bats + +load test_helper + +@test "no shell version" { + mkdir -p "${RBENV_TEST_DIR}/myproject" + cd "${RBENV_TEST_DIR}/myproject" + echo "1.2.3" > .ruby-version + RBENV_VERSION="" run rbenv-sh-shell + assert_failure "rbenv: no shell-specific version configured" +} + +@test "shell version" { + RBENV_VERSION="1.2.3" run rbenv-sh-shell + assert_success 'echo "$RBENV_VERSION"' +} + +@test "shell unset" { + run rbenv-sh-shell --unset + assert_success "unset RBENV_VERSION" +} + +@test "shell change invalid version" { + run rbenv-sh-shell 1.2.3 + assert_failure + assert_line "rbenv: version \`1.2.3' not installed" + assert_line "return 1" +} + +@test "shell change version" { + mkdir -p "${RBENV_ROOT}/versions/1.2.3" + run rbenv-sh-shell 1.2.3 + assert_success 'export RBENV_VERSION="1.2.3"' + refute_line "return 1" +} diff --git a/test/shims.bats b/test/shims.bats new file mode 100644 index 00000000..194554af --- /dev/null +++ b/test/shims.bats @@ -0,0 +1,29 @@ +#!/usr/bin/env bats + +load test_helper + +@test "no shims" { + run rbenv-shims + assert_success + assert [ -z "$output" ] +} + +@test "shims" { + mkdir -p "${RBENV_ROOT}/shims" + touch "${RBENV_ROOT}/shims/ruby" + touch "${RBENV_ROOT}/shims/irb" + run rbenv-shims + assert_success + assert_line "${RBENV_ROOT}/shims/ruby" + assert_line "${RBENV_ROOT}/shims/irb" +} + +@test "shims --short" { + mkdir -p "${RBENV_ROOT}/shims" + touch "${RBENV_ROOT}/shims/ruby" + touch "${RBENV_ROOT}/shims/irb" + run rbenv-shims --short + assert_success + assert_line "irb" + assert_line "ruby" +} diff --git a/test/test_helper.bash b/test/test_helper.bash new file mode 100644 index 00000000..7d52e442 --- /dev/null +++ b/test/test_helper.bash @@ -0,0 +1,62 @@ +RBENV_TEST_DIR="${BATS_TMPDIR}/rbenv" +export RBENV_ROOT="${RBENV_TEST_DIR}/root" +export HOME="${RBENV_TEST_DIR}/home" + +unset RBENV_VERSION +unset RBENV_DIR + +export PATH="${RBENV_TEST_DIR}/bin:$PATH" +export PATH="${BATS_TEST_DIRNAME}/../libexec:$PATH" +export PATH="${BATS_TEST_DIRNAME}/libexec:$PATH" +export PATH="${RBENV_ROOT}/shims:$PATH" + +teardown() { + rm -rf "$RBENV_TEST_DIR" +} + +flunk() { + echo "$@" | sed "s:${RBENV_ROOT}:\$RBENV_ROOT:" >&2 + return 1 +} + +assert_success() { + if [ "$status" -ne 0 ]; then + flunk "command failed with exit status $status" + elif [ "$#" -gt 0 ]; then + assert_output "$1" + fi +} + +assert_failure() { + if [ "$status" -eq 0 ]; then + flunk "expected failed exit status" + elif [ "$#" -gt 0 ]; then + assert_output "$1" + fi +} + +assert_output() { + if [ "$output" != "$1" ]; then + flunk "expected: $1" || true + flunk "got: $output" + fi +} + +assert_line() { + for line in "${lines[@]}"; do + if [ "$line" = "$1" ]; then return 0; fi + done + flunk "expected line \`$1'" +} + +refute_line() { + for line in "${lines[@]}"; do + if [ "$line" = "$1" ]; then flunk "expected to not find line \`$line'"; fi + done +} + +assert() { + if ! "$@"; then + flunk "failed: $@" + fi +} From bc369fb1ab5d48636922c38b075100e69af4946b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohnic=CC=81?= Date: Thu, 7 Mar 2013 16:05:34 -0500 Subject: [PATCH 282/384] configure Travis --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..dbd6c551 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,2 @@ +install: git clone https://github.com/sstephenson/bats.git +script: bats/bin/bats test From 5e5e3e0588992a66e879e5e077175f614e387ec0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohnic=CC=81?= Date: Thu, 7 Mar 2013 16:09:02 -0500 Subject: [PATCH 283/384] skip Ruby stuff on Travis --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index dbd6c551..445df624 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,2 +1,4 @@ install: git clone https://github.com/sstephenson/bats.git script: bats/bin/bats test +# skips unnecessary Ruby-specific setup +language: node_js From a7da06998e3f48da0dfd4e40264a861d0a5d4ddc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohnic=CC=81?= Date: Thu, 7 Mar 2013 16:14:25 -0500 Subject: [PATCH 284/384] use C on Travis for even less overhead --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 445df624..4498f8e5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,4 @@ install: git clone https://github.com/sstephenson/bats.git script: bats/bin/bats test # skips unnecessary Ruby-specific setup -language: node_js +language: c From a81ace2ccb5b5c87c6a1012be8a2cd021443a8f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohnic=CC=81?= Date: Thu, 7 Mar 2013 23:55:02 -0500 Subject: [PATCH 285/384] add hook lookup tests --- test/hooks.bats | 38 ++++++++++++++++++++++++++++++++++++++ test/test_helper.bash | 30 +++++++++++++++++++++--------- 2 files changed, 59 insertions(+), 9 deletions(-) create mode 100644 test/hooks.bats diff --git a/test/hooks.bats b/test/hooks.bats new file mode 100644 index 00000000..738c55ed --- /dev/null +++ b/test/hooks.bats @@ -0,0 +1,38 @@ +#!/usr/bin/env bats + +load test_helper + +create_hook() { + mkdir -p "$1/$2" + touch "$1/$2/$3" +} + +@test "prints usage help given no argument" { + run rbenv-hooks + assert_failure "Usage: rbenv hooks " +} + +@test "prints list of hooks" { + path1="${RBENV_TEST_DIR}/rbenv.d" + path2="${RBENV_TEST_DIR}/etc/rbenv_hooks" + create_hook "$path1" exec "hello.bash" + create_hook "$path1" exec "ahoy.bash" + create_hook "$path1" exec "invalid.sh" + create_hook "$path1" which "boom.bash" + create_hook "$path2" exec "bueno.bash" + + RBENV_HOOK_PATH="$path1:$path2" run rbenv-hooks exec + assert_success + assert_line 0 "${RBENV_TEST_DIR}/rbenv.d/exec/ahoy.bash" + assert_line 1 "${RBENV_TEST_DIR}/rbenv.d/exec/hello.bash" + assert_line 2 "${RBENV_TEST_DIR}/etc/rbenv_hooks/exec/bueno.bash" +} + +@test "resolves relative paths" { + path="${RBENV_TEST_DIR}/rbenv.d" + create_hook "$path" exec "hello.bash" + mkdir -p "$HOME" + + RBENV_HOOK_PATH="${HOME}/../rbenv.d" run rbenv-hooks exec + assert_success "${RBENV_TEST_DIR}/rbenv.d/exec/hello.bash" +} diff --git a/test/test_helper.bash b/test/test_helper.bash index 7d52e442..85e8853b 100644 --- a/test/test_helper.bash +++ b/test/test_helper.bash @@ -15,7 +15,10 @@ teardown() { } flunk() { - echo "$@" | sed "s:${RBENV_ROOT}:\$RBENV_ROOT:" >&2 + { if [ "$#" -eq 0 ]; then cat - + else echo "$@" + fi + } | sed "s:${RBENV_TEST_DIR}:TEST_DIR:" >&2 return 1 } @@ -35,18 +38,27 @@ assert_failure() { fi } -assert_output() { - if [ "$output" != "$1" ]; then - flunk "expected: $1" || true - flunk "got: $output" +assert_equal() { + if [ "$1" != "$2" ]; then + { echo "expected: $1" + echo "actual: $2" + } | flunk fi } +assert_output() { + assert_equal "$1" "$output" +} + assert_line() { - for line in "${lines[@]}"; do - if [ "$line" = "$1" ]; then return 0; fi - done - flunk "expected line \`$1'" + if [ "$1" -ge 0 ] 2>/dev/null; then + assert_equal "$2" "${lines[$1]}" + else + for line in "${lines[@]}"; do + if [ "$line" = "$1" ]; then return 0; fi + done + flunk "expected line \`$1'" + fi } refute_line() { From ea3203dbab78da7fd29b5490889e60a7dcc8766c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohnic=CC=81?= Date: Fri, 8 Mar 2013 14:35:46 -0500 Subject: [PATCH 286/384] fix resolving symlinks in rbenv-hooks --- libexec/rbenv-hooks | 3 +-- test/hooks.bats | 11 +++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/libexec/rbenv-hooks b/libexec/rbenv-hooks index 794b9437..25551782 100755 --- a/libexec/rbenv-hooks +++ b/libexec/rbenv-hooks @@ -25,7 +25,6 @@ resolve_link() { realpath() { local cwd="$(pwd)" - local base="$(basename $1)" local path="$1" while [ -n "$path" ]; do @@ -34,7 +33,7 @@ realpath() { path="$(resolve_link "$name" || true)" done - echo "$(pwd)/$base" + echo "$(pwd)/$name" cd "$cwd" } diff --git a/test/hooks.bats b/test/hooks.bats index 738c55ed..bc1b5f17 100644 --- a/test/hooks.bats +++ b/test/hooks.bats @@ -36,3 +36,14 @@ create_hook() { RBENV_HOOK_PATH="${HOME}/../rbenv.d" run rbenv-hooks exec assert_success "${RBENV_TEST_DIR}/rbenv.d/exec/hello.bash" } + +@test "resolves symlinks" { + path="${RBENV_TEST_DIR}/rbenv.d" + mkdir -p "${path}/exec" + mkdir -p "$HOME" + touch "${HOME}/hola.bash" + ln -s "../../home/hola.bash" "${path}/exec/hello.bash" + + RBENV_HOOK_PATH="$path" run rbenv-hooks exec + assert_success "${HOME}/hola.bash" +} From 03fa148e814d50aba8012dc94b866213a00ea8a9 Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Sun, 24 Feb 2013 16:34:05 -0500 Subject: [PATCH 287/384] Don't duplicate shims in PATH --- libexec/rbenv-init | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libexec/rbenv-init b/libexec/rbenv-init index d8de64a0..9701a42d 100755 --- a/libexec/rbenv-init +++ b/libexec/rbenv-init @@ -73,7 +73,9 @@ fi mkdir -p "${RBENV_ROOT}/"{shims,versions} -echo 'export PATH="'${RBENV_ROOT}'/shims:${PATH}"' +if [[ ":${PATH}:" != *:"${RBENV_ROOT}/shims":* ]]; then + echo 'export PATH="'${RBENV_ROOT}'/shims:${PATH}"' +fi case "$shell" in bash | zsh ) From 6a6ae8ae4667dd8c95cae359f92819b6d1d1320b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohnic=CC=81?= Date: Wed, 20 Mar 2013 13:43:57 +0100 Subject: [PATCH 288/384] tests for rbenv-init --- test/init.bats | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 test/init.bats diff --git a/test/init.bats b/test/init.bats new file mode 100644 index 00000000..95781e33 --- /dev/null +++ b/test/init.bats @@ -0,0 +1,46 @@ +#!/usr/bin/env bats + +load test_helper + +@test "creates shims and versions directories" { + assert [ ! -d "${RBENV_ROOT}/shims" ] + assert [ ! -d "${RBENV_ROOT}/versions" ] + run rbenv-init - + assert_success + assert [ -d "${RBENV_ROOT}/shims" ] + assert [ -d "${RBENV_ROOT}/versions" ] +} + +@test "auto rehash" { + run rbenv-init - + assert_success + assert_line "rbenv rehash 2>/dev/null" +} + +@test "setup shell completions" { + export SHELL=/bin/bash + root="$(cd $BATS_TEST_DIRNAME/.. && pwd)" + run rbenv-init - + assert_success + assert_line 'source "'${root}'/libexec/../completions/rbenv.bash"' +} + +@test "option to skip rehash" { + run rbenv-init - --no-rehash + assert_success + refute_line "rbenv rehash 2>/dev/null" +} + +@test "adds shims to PATH" { + export PATH="${BATS_TEST_DIRNAME}/../libexec:/usr/bin:/bin" + run rbenv-init - + assert_success + assert_line 0 'export PATH="'${RBENV_ROOT}'/shims:${PATH}"' +} + +@test "doesn't add shims to PATH more than once" { + export PATH="${RBENV_ROOT}/shims:$PATH" + run rbenv-init - + assert_success + refute_line 'export PATH="'${RBENV_ROOT}'/shims:${PATH}"' +} From 2bbf49b2f552086b324122bffae16f37043f0c4d Mon Sep 17 00:00:00 2001 From: Shohei Yamasaki Date: Sat, 23 Mar 2013 22:36:11 +0900 Subject: [PATCH 289/384] replace tab with spaces --- libexec/rbenv-init | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libexec/rbenv-init b/libexec/rbenv-init index 9701a42d..8cbe7df0 100755 --- a/libexec/rbenv-init +++ b/libexec/rbenv-init @@ -11,7 +11,7 @@ for args in "$@" do if [ "$args" = "-" ]; then print=1 - shift + shift fi if [ "$args" = "--no-rehash" ]; then From baf7656d2f1570a3b2d5a7e70d5bfcc52fe0428a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohnic=CC=81?= Date: Sun, 24 Feb 2013 14:52:50 +0100 Subject: [PATCH 290/384] fix iterating through paths that have spaces in them Fixes #344, #196 --- libexec/rbenv-commands | 4 +++- libexec/rbenv-exec | 3 ++- libexec/rbenv-hooks | 6 ++++-- libexec/rbenv-rehash | 3 ++- libexec/rbenv-which | 3 ++- test/commands.bats | 12 ++++++++++++ test/exec.bats | 14 ++++++++++++++ test/hooks.bats | 12 ++++++++++++ 8 files changed, 51 insertions(+), 6 deletions(-) create mode 100644 test/exec.bats diff --git a/libexec/rbenv-commands b/libexec/rbenv-commands index 58aab012..daeedd78 100755 --- a/libexec/rbenv-commands +++ b/libexec/rbenv-commands @@ -20,9 +20,11 @@ elif [ "$1" = "--no-sh" ]; then shift fi +IFS=: paths=($PATH) + shopt -s nullglob -{ for path in ${PATH//:/$'\n'}; do +{ for path in "${paths[@]}"; do for command in "${path}/rbenv-"*; do command="${command##*rbenv-}" if [ -n "$sh" ]; then diff --git a/libexec/rbenv-exec b/libexec/rbenv-exec index 45dbbf80..4ccc610c 100755 --- a/libexec/rbenv-exec +++ b/libexec/rbenv-exec @@ -32,7 +32,8 @@ fi RBENV_COMMAND_PATH="$(rbenv-which "$RBENV_COMMAND")" RBENV_BIN_PATH="${RBENV_COMMAND_PATH%/*}" -for script in $(rbenv-hooks exec); do +IFS=$'\n' scripts=(`rbenv-hooks exec`) +for script in "${scripts[@]}"; do source "$script" done diff --git a/libexec/rbenv-hooks b/libexec/rbenv-hooks index 25551782..f81e9af4 100755 --- a/libexec/rbenv-hooks +++ b/libexec/rbenv-hooks @@ -37,9 +37,11 @@ realpath() { cd "$cwd" } +IFS=: hook_paths=($RBENV_HOOK_PATH) + shopt -s nullglob -for path in ${RBENV_HOOK_PATH//:/$'\n'}; do - for script in $path/"$RBENV_COMMAND"/*.bash; do +for path in "${hook_paths[@]}"; do + for script in "$path/$RBENV_COMMAND"/*.bash; do echo $(realpath $script) done done diff --git a/libexec/rbenv-rehash b/libexec/rbenv-rehash index 8a6d66d6..fd987ace 100755 --- a/libexec/rbenv-rehash +++ b/libexec/rbenv-rehash @@ -144,7 +144,8 @@ make_shims ../versions/*/bin/* cd "$OLDPWD" # Allow plugins to register shims. -for script in $(rbenv-hooks rehash); do +IFS=$'\n' scripts=(`rbenv-hooks rehash`) +for script in "${scripts[@]}"; do source "$script" done diff --git a/libexec/rbenv-which b/libexec/rbenv-which index 1301b2ef..393a06e8 100755 --- a/libexec/rbenv-which +++ b/libexec/rbenv-which @@ -63,7 +63,8 @@ else RBENV_COMMAND_PATH="${RBENV_ROOT}/versions/${RBENV_VERSION}/bin/${RBENV_COMMAND}" fi -for script in $(rbenv-hooks which); do +IFS=$'\n' scripts=(`rbenv-hooks which`) +for script in "${scripts[@]}"; do source "$script" done diff --git a/test/commands.bats b/test/commands.bats index 2cac3940..81d38609 100644 --- a/test/commands.bats +++ b/test/commands.bats @@ -19,6 +19,18 @@ load test_helper assert_line "shell" } +@test "commands in path with spaces" { + path="${RBENV_TEST_DIR}/my commands" + cmd="${path}/rbenv-sh-hello" + mkdir -p "$path" + touch "$cmd" + chmod +x "$cmd" + + PATH="${path}:$PATH" run rbenv-commands --sh + assert_success + assert_line "hello" +} + @test "commands --no-sh" { run rbenv-commands --no-sh assert_success diff --git a/test/exec.bats b/test/exec.bats new file mode 100644 index 00000000..0e4852f2 --- /dev/null +++ b/test/exec.bats @@ -0,0 +1,14 @@ +#!/usr/bin/env bats + +load test_helper + +@test "supports hook path with spaces" { + hook_path="${RBENV_TEST_DIR}/custom stuff/rbenv hooks" + mkdir -p "${hook_path}/exec" + echo "export HELLO='from hook'" > "${hook_path}/exec/hello.bash" + + export RBENV_VERSION=system + RBENV_HOOK_PATH="$hook_path" run rbenv-exec env + assert_success + assert_line "HELLO=from hook" +} diff --git a/test/hooks.bats b/test/hooks.bats index bc1b5f17..da450b6a 100644 --- a/test/hooks.bats +++ b/test/hooks.bats @@ -28,6 +28,18 @@ create_hook() { assert_line 2 "${RBENV_TEST_DIR}/etc/rbenv_hooks/exec/bueno.bash" } +@test "supports hook paths with spaces" { + path1="${RBENV_TEST_DIR}/my hooks/rbenv.d" + path2="${RBENV_TEST_DIR}/etc/rbenv hooks" + create_hook "$path1" exec "hello.bash" + create_hook "$path2" exec "ahoy.bash" + + RBENV_HOOK_PATH="$path1:$path2" run rbenv-hooks exec + assert_success + assert_line 0 "${RBENV_TEST_DIR}/my hooks/rbenv.d/exec/hello.bash" + assert_line 1 "${RBENV_TEST_DIR}/etc/rbenv hooks/exec/ahoy.bash" +} + @test "resolves relative paths" { path="${RBENV_TEST_DIR}/rbenv.d" create_hook "$path" exec "hello.bash" From 4b6ab0389b5b5401ca530f3edbef024972b943fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohnic=CC=81?= Date: Mon, 1 Apr 2013 02:58:58 +0200 Subject: [PATCH 291/384] add tests for exec --- test/exec.bats | 45 +++++++++++++++++++++++++++++++++++++++++++ test/test_helper.bash | 15 ++++++++++++--- 2 files changed, 57 insertions(+), 3 deletions(-) diff --git a/test/exec.bats b/test/exec.bats index 0e4852f2..ecff7c70 100644 --- a/test/exec.bats +++ b/test/exec.bats @@ -2,6 +2,13 @@ load test_helper +create_executable() { + bin="${RBENV_ROOT}/versions/${RBENV_VERSION}/bin" + mkdir -p "$bin" + echo "$2" > "${bin}/$1" + chmod +x "${bin}/$1" +} + @test "supports hook path with spaces" { hook_path="${RBENV_TEST_DIR}/custom stuff/rbenv hooks" mkdir -p "${hook_path}/exec" @@ -12,3 +19,41 @@ load test_helper assert_success assert_line "HELLO=from hook" } + +@test "forwards all arguments" { + export RBENV_VERSION="2.0" + create_executable "ruby" "#!$BASH + echo \$0 + while [[ \$# -gt 0 ]]; do + # hack to avoid bash builtin echo which can't output '-e' + \$(which echo) \$1 + shift 1 + done + " + + run rbenv-exec ruby -w -e "puts 'hello world'" -- extra args + assert_line 0 "${RBENV_ROOT}/versions/2.0/bin/ruby" + assert_line 1 "-w" + assert_line 2 "-e" + assert_line 3 "puts 'hello world'" + assert_line 4 "--" + assert_line 5 "extra" + assert_line 6 "args" + refute_line 7 +} + +@test "supports ruby -S " { + export RBENV_VERSION="2.0" + create_executable "ruby" "#!$BASH + if [[ \$1 = '-S' ]]; then + head -1 \$(which \$2) | grep ruby >/dev/null + exit \$? + else + echo 'ruby 2.0 (rbenv test)' + fi" + create_executable "rake" "#!/usr/bin/env ruby" + + rbenv-rehash + run ruby -S rake + assert_success +} diff --git a/test/test_helper.bash b/test/test_helper.bash index 85e8853b..5fb24def 100644 --- a/test/test_helper.bash +++ b/test/test_helper.bash @@ -62,9 +62,18 @@ assert_line() { } refute_line() { - for line in "${lines[@]}"; do - if [ "$line" = "$1" ]; then flunk "expected to not find line \`$line'"; fi - done + if [ "$1" -ge 0 ] 2>/dev/null; then + num_lines="${#lines[@]}" + if [ "$1" -lt "$num_lines" ]; then + flunk "output has $num_lines lines" + fi + else + for line in "${lines[@]}"; do + if [ "$line" = "$1" ]; then + flunk "expected to not find line \`$line'" + fi + done + fi } assert() { From 400fe3106199d241ab6844c8fb47d2a372c556e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohnic=CC=81?= Date: Mon, 1 Apr 2013 03:01:37 +0200 Subject: [PATCH 292/384] fix exec fails for invalid version --- libexec/rbenv-exec | 3 ++- test/exec.bats | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/libexec/rbenv-exec b/libexec/rbenv-exec index 4ccc610c..eb16dc70 100755 --- a/libexec/rbenv-exec +++ b/libexec/rbenv-exec @@ -21,7 +21,7 @@ if [ "$1" = "--complete" ]; then exec rbenv shims --short fi -export RBENV_VERSION="$(rbenv-version-name)" +RBENV_VERSION="$(rbenv-version-name)" RBENV_COMMAND="$1" if [ -z "$RBENV_COMMAND" ]; then @@ -29,6 +29,7 @@ if [ -z "$RBENV_COMMAND" ]; then exit 1 fi +export RBENV_VERSION RBENV_COMMAND_PATH="$(rbenv-which "$RBENV_COMMAND")" RBENV_BIN_PATH="${RBENV_COMMAND_PATH%/*}" diff --git a/test/exec.bats b/test/exec.bats index ecff7c70..1eaef7d7 100644 --- a/test/exec.bats +++ b/test/exec.bats @@ -9,6 +9,12 @@ create_executable() { chmod +x "${bin}/$1" } +@test "fails with invalid version" { + export RBENV_VERSION="2.0" + run rbenv-exec ruby -v + assert_failure "rbenv: version \`2.0' is not installed" +} + @test "supports hook path with spaces" { hook_path="${RBENV_TEST_DIR}/custom stuff/rbenv hooks" mkdir -p "${hook_path}/exec" From 45f651ab0045e2ae03be91fd156e627b2f999a11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohnic=CC=81?= Date: Mon, 1 Apr 2013 03:11:46 +0200 Subject: [PATCH 293/384] hack around the hack around bash `echo` --- test/exec.bats | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/exec.bats b/test/exec.bats index 1eaef7d7..97a11565 100644 --- a/test/exec.bats +++ b/test/exec.bats @@ -32,7 +32,7 @@ create_executable() { echo \$0 while [[ \$# -gt 0 ]]; do # hack to avoid bash builtin echo which can't output '-e' - \$(which echo) \$1 + cat <<<\"\$1\" shift 1 done " From 9b58b6642e178b1697c6046bd8a07c06d46529a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohnic=CC=81?= Date: Mon, 1 Apr 2013 03:44:19 +0200 Subject: [PATCH 294/384] test completions for exec --- test/exec.bats | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/exec.bats b/test/exec.bats index 97a11565..92338aea 100644 --- a/test/exec.bats +++ b/test/exec.bats @@ -15,6 +15,19 @@ create_executable() { assert_failure "rbenv: version \`2.0' is not installed" } +@test "completes with names of executables" { + export RBENV_VERSION="2.0" + create_executable "ruby" + create_executable "rake" + + rbenv-rehash + run rbenv-completions exec + assert_success + assert_line 0 "rake" + assert_line 1 "ruby" + refute_line 2 +} + @test "supports hook path with spaces" { hook_path="${RBENV_TEST_DIR}/custom stuff/rbenv hooks" mkdir -p "${hook_path}/exec" From 4d96d0a6c6721f440ee7e6a28d9743d781b83455 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohnic=CC=81?= Date: Mon, 1 Apr 2013 16:19:21 +0200 Subject: [PATCH 295/384] add tests for completions --- test/completions.bats | 48 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 test/completions.bats diff --git a/test/completions.bats b/test/completions.bats new file mode 100644 index 00000000..8bfb88d5 --- /dev/null +++ b/test/completions.bats @@ -0,0 +1,48 @@ +#!/usr/bin/env bats + +load test_helper + +create_command() { + bin="${RBENV_TEST_DIR}/bin" + mkdir -p "$bin" + echo "$2" > "${bin}/$1" + chmod +x "${bin}/$1" +} + +@test "command with no completion support" { + create_command "rbenv-hello" "#!$BASH + echo hello" + run rbenv-completions hello + assert_success "" +} + +@test "command with completion support" { + create_command "rbenv-hello" "#!$BASH +# provide rbenv completions +if [[ \$1 = --complete ]]; then + echo hello +else + exit 1 +fi" + run rbenv-completions hello + assert_success "hello" +} + +@test "forwards extra arguments" { + create_command "rbenv-hello" "#!$BASH +# provide rbenv completions +if [[ \$1 = --complete ]]; then + shift 1 + while [[ \$# -gt 0 ]]; do + echo \$1 + shift 1 + done +else + exit 1 +fi" + run rbenv-completions hello happy world + assert_success + assert_line 0 "happy" + assert_line 1 "world" + refute_line 2 +} From 497911d6c093341cc1420f1f3f6f1fae5f64d0f5 Mon Sep 17 00:00:00 2001 From: Alisdair Sullivan Date: Sun, 31 Mar 2013 21:01:07 -0700 Subject: [PATCH 296/384] improve detection of completion support for commands Enable JavasCript, Lua and Erlang scripts to provide completions --- libexec/rbenv-completions | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libexec/rbenv-completions b/libexec/rbenv-completions index 2cc14e67..6de09ed2 100755 --- a/libexec/rbenv-completions +++ b/libexec/rbenv-completions @@ -11,7 +11,7 @@ if [ -z "$COMMAND" ]; then fi COMMAND_PATH="$(command -v "rbenv-$COMMAND" || command -v "rbenv-sh-$COMMAND")" -if grep -i "^# provide rbenv completions" "$COMMAND_PATH" >/dev/null; then +if grep -i "^\([#%]\|--\|//\) provide rbenv completions" "$COMMAND_PATH" >/dev/null; then shift exec "$COMMAND_PATH" --complete "$@" fi From b8504ed2a99c6553c5ecefeea93e70e4b9f7ef60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohnic=CC=81?= Date: Tue, 2 Apr 2013 00:27:27 +0200 Subject: [PATCH 297/384] saner assertions for multiline output --- test/completions.bats | 7 +++---- test/exec.bats | 28 +++++++++++++--------------- test/hooks.bats | 14 +++++++------- test/test_helper.bash | 22 +++++++++++++++++++--- 4 files changed, 42 insertions(+), 29 deletions(-) diff --git a/test/completions.bats b/test/completions.bats index 8bfb88d5..4b05357a 100644 --- a/test/completions.bats +++ b/test/completions.bats @@ -41,8 +41,7 @@ else exit 1 fi" run rbenv-completions hello happy world - assert_success - assert_line 0 "happy" - assert_line 1 "world" - refute_line 2 + assert_success "\ + happy + world" } diff --git a/test/exec.bats b/test/exec.bats index 92338aea..7d80bcd0 100644 --- a/test/exec.bats +++ b/test/exec.bats @@ -22,10 +22,9 @@ create_executable() { rbenv-rehash run rbenv-completions exec - assert_success - assert_line 0 "rake" - assert_line 1 "ruby" - refute_line 2 + assert_success "\ + rake + ruby" } @test "supports hook path with spaces" { @@ -45,20 +44,19 @@ create_executable() { echo \$0 while [[ \$# -gt 0 ]]; do # hack to avoid bash builtin echo which can't output '-e' - cat <<<\"\$1\" + printf \"%s\\n\" \"\$1\" shift 1 - done - " + done" run rbenv-exec ruby -w -e "puts 'hello world'" -- extra args - assert_line 0 "${RBENV_ROOT}/versions/2.0/bin/ruby" - assert_line 1 "-w" - assert_line 2 "-e" - assert_line 3 "puts 'hello world'" - assert_line 4 "--" - assert_line 5 "extra" - assert_line 6 "args" - refute_line 7 + assert_success "\ + ${RBENV_ROOT}/versions/2.0/bin/ruby + -w + -e + puts 'hello world' + -- + extra + args" } @test "supports ruby -S " { diff --git a/test/hooks.bats b/test/hooks.bats index da450b6a..7d3b253f 100644 --- a/test/hooks.bats +++ b/test/hooks.bats @@ -22,10 +22,10 @@ create_hook() { create_hook "$path2" exec "bueno.bash" RBENV_HOOK_PATH="$path1:$path2" run rbenv-hooks exec - assert_success - assert_line 0 "${RBENV_TEST_DIR}/rbenv.d/exec/ahoy.bash" - assert_line 1 "${RBENV_TEST_DIR}/rbenv.d/exec/hello.bash" - assert_line 2 "${RBENV_TEST_DIR}/etc/rbenv_hooks/exec/bueno.bash" + assert_success "\ + ${RBENV_TEST_DIR}/rbenv.d/exec/ahoy.bash + ${RBENV_TEST_DIR}/rbenv.d/exec/hello.bash + ${RBENV_TEST_DIR}/etc/rbenv_hooks/exec/bueno.bash" } @test "supports hook paths with spaces" { @@ -35,9 +35,9 @@ create_hook() { create_hook "$path2" exec "ahoy.bash" RBENV_HOOK_PATH="$path1:$path2" run rbenv-hooks exec - assert_success - assert_line 0 "${RBENV_TEST_DIR}/my hooks/rbenv.d/exec/hello.bash" - assert_line 1 "${RBENV_TEST_DIR}/etc/rbenv hooks/exec/ahoy.bash" + assert_success "\ + ${RBENV_TEST_DIR}/my hooks/rbenv.d/exec/hello.bash + ${RBENV_TEST_DIR}/etc/rbenv hooks/exec/ahoy.bash" } @test "resolves relative paths" { diff --git a/test/test_helper.bash b/test/test_helper.bash index 5fb24def..1d49ab2a 100644 --- a/test/test_helper.bash +++ b/test/test_helper.bash @@ -26,7 +26,7 @@ assert_success() { if [ "$status" -ne 0 ]; then flunk "command failed with exit status $status" elif [ "$#" -gt 0 ]; then - assert_output "$1" + assert_output_lines "$1" fi } @@ -34,7 +34,7 @@ assert_failure() { if [ "$status" -eq 0 ]; then flunk "expected failed exit status" elif [ "$#" -gt 0 ]; then - assert_output "$1" + assert_output_lines "$1" fi } @@ -50,10 +50,25 @@ assert_output() { assert_equal "$1" "$output" } +# compares lines with leading whitespace trimmed +assert_output_lines() { + local -a expected + IFS=$'\n' expected=($1) + for (( i=0; i < ${#expected[@]}; i++ )); do + local wants="${expected[$i]}" + local got="${lines[$i]}" + assert_equal \ + "${wants#"${wants%%[![:space:]]*}"}" \ + "${got#"${got%%[![:space:]]*}"}" + done + assert_equal "${expected[$i]}" "${lines[$i]}" +} + assert_line() { if [ "$1" -ge 0 ] 2>/dev/null; then assert_equal "$2" "${lines[$1]}" else + local line for line in "${lines[@]}"; do if [ "$line" = "$1" ]; then return 0; fi done @@ -63,11 +78,12 @@ assert_line() { refute_line() { if [ "$1" -ge 0 ] 2>/dev/null; then - num_lines="${#lines[@]}" + local num_lines="${#lines[@]}" if [ "$1" -lt "$num_lines" ]; then flunk "output has $num_lines lines" fi else + local line for line in "${lines[@]}"; do if [ "$line" = "$1" ]; then flunk "expected to not find line \`$line'" From 97290b2442ac8de54ce7738671dc8f1509173446 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohnic=CC=81?= Date: Tue, 2 Apr 2013 01:35:58 +0200 Subject: [PATCH 298/384] simplify iterating through arglist --- test/completions.bats | 5 +---- test/exec.bats | 5 ++--- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/test/completions.bats b/test/completions.bats index 4b05357a..0f79654d 100644 --- a/test/completions.bats +++ b/test/completions.bats @@ -33,10 +33,7 @@ fi" # provide rbenv completions if [[ \$1 = --complete ]]; then shift 1 - while [[ \$# -gt 0 ]]; do - echo \$1 - shift 1 - done + for arg; do echo \$arg; done else exit 1 fi" diff --git a/test/exec.bats b/test/exec.bats index 7d80bcd0..f97ddfce 100644 --- a/test/exec.bats +++ b/test/exec.bats @@ -42,10 +42,9 @@ create_executable() { export RBENV_VERSION="2.0" create_executable "ruby" "#!$BASH echo \$0 - while [[ \$# -gt 0 ]]; do + for arg; do # hack to avoid bash builtin echo which can't output '-e' - printf \"%s\\n\" \"\$1\" - shift 1 + printf \"%s\\n\" \"\$arg\" done" run rbenv-exec ruby -w -e "puts 'hello world'" -- extra args From f6db678b20b52ef455151d6cbc1365f2d266ef8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohnic=CC=81?= Date: Tue, 2 Apr 2013 02:48:04 +0200 Subject: [PATCH 299/384] un-indent shebang for test executables --- test/exec.bats | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/test/exec.bats b/test/exec.bats index f97ddfce..9b163689 100644 --- a/test/exec.bats +++ b/test/exec.bats @@ -3,10 +3,15 @@ load test_helper create_executable() { + name="${1?}" + shift 1 bin="${RBENV_ROOT}/versions/${RBENV_VERSION}/bin" mkdir -p "$bin" - echo "$2" > "${bin}/$1" - chmod +x "${bin}/$1" + { if [ $# -eq 0 ]; then cat - + else echo "$@" + fi + } | sed -Ee '1s/^ +//' > "${bin}/$name" + chmod +x "${bin}/$name" } @test "fails with invalid version" { @@ -17,8 +22,8 @@ create_executable() { @test "completes with names of executables" { export RBENV_VERSION="2.0" - create_executable "ruby" - create_executable "rake" + create_executable "ruby" "#!/bin/sh" + create_executable "rake" "#!/bin/sh" rbenv-rehash run rbenv-completions exec @@ -40,12 +45,14 @@ create_executable() { @test "forwards all arguments" { export RBENV_VERSION="2.0" - create_executable "ruby" "#!$BASH - echo \$0 - for arg; do - # hack to avoid bash builtin echo which can't output '-e' - printf \"%s\\n\" \"\$arg\" - done" + create_executable "ruby" < Date: Tue, 2 Apr 2013 02:48:27 +0200 Subject: [PATCH 300/384] better emulate `ruby -S` behavior in testing Per https://github.com/ruby/ruby/blob/7d3db3c/ruby.c#L1383-1391 --- test/exec.bats | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/test/exec.bats b/test/exec.bats index 9b163689..45e7f731 100644 --- a/test/exec.bats +++ b/test/exec.bats @@ -67,16 +67,29 @@ SH @test "supports ruby -S " { export RBENV_VERSION="2.0" - create_executable "ruby" "#!$BASH - if [[ \$1 = '-S' ]]; then - head -1 \$(which \$2) | grep ruby >/dev/null - exit \$? - else - echo 'ruby 2.0 (rbenv test)' - fi" - create_executable "rake" "#!/usr/bin/env ruby" + + # emulate `ruby -S' behavior + create_executable "ruby" </dev/null; then + \$BASH "\$found" + else + echo "ruby: no Ruby script found in input (LoadError)" >&2 + exit 1 + fi +else + echo 'ruby 2.0 (rbenv test)' +fi +SH + + create_executable "rake" "\ + #!/usr/bin/env ruby + echo hello rake" rbenv-rehash run ruby -S rake - assert_success + assert_success "hello rake" } From 969af1567af0617a3f08adbbe2c63e3296f59a08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohnic=CC=81?= Date: Sat, 6 Apr 2013 12:30:21 +0200 Subject: [PATCH 301/384] add tests for rehash, whence, which --- test/rehash.bats | 35 ++++++++++++++++++++++++----- test/shell.bats | 7 +++--- test/whence.bats | 28 ++++++++++++++++++++++++ test/which.bats | 57 ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 118 insertions(+), 9 deletions(-) create mode 100644 test/whence.bats create mode 100644 test/which.bats diff --git a/test/rehash.bats b/test/rehash.bats index 6e9e8907..1e4d6d51 100755 --- a/test/rehash.bats +++ b/test/rehash.bats @@ -2,10 +2,17 @@ load test_helper +create_executable() { + local bin="${RBENV_ROOT}/versions/${1}/bin" + mkdir -p "$bin" + touch "${bin}/$2" + chmod +x "${bin}/$2" +} + @test "empty rehash" { assert [ ! -d "${RBENV_ROOT}/shims" ] run rbenv-rehash - assert_success + assert_success "" assert [ -d "${RBENV_ROOT}/shims" ] rmdir "${RBENV_ROOT}/shims" } @@ -14,14 +21,32 @@ load test_helper mkdir -p "${RBENV_ROOT}/shims" chmod -w "${RBENV_ROOT}/shims" run rbenv-rehash - assert_failure - assert_output "rbenv: cannot rehash: ${RBENV_ROOT}/shims isn't writable" + assert_failure "rbenv: cannot rehash: ${RBENV_ROOT}/shims isn't writable" } @test "rehash in progress" { mkdir -p "${RBENV_ROOT}/shims" touch "${RBENV_ROOT}/shims/.rbenv-shim" run rbenv-rehash - assert_failure - assert_output "rbenv: cannot rehash: ${RBENV_ROOT}/shims/.rbenv-shim exists" + assert_failure "rbenv: cannot rehash: ${RBENV_ROOT}/shims/.rbenv-shim exists" +} + +@test "creates shims" { + create_executable "1.8" "ruby" + create_executable "1.8" "rake" + create_executable "2.0" "ruby" + create_executable "2.0" "rspec" + + assert [ ! -e "${RBENV_ROOT}/shims/ruby" ] + assert [ ! -e "${RBENV_ROOT}/shims/rake" ] + assert [ ! -e "${RBENV_ROOT}/shims/rspec" ] + + run rbenv-rehash + assert_success "" + + run ls "${RBENV_ROOT}/shims" + assert_success "\ + rake + rspec + ruby" } diff --git a/test/shell.bats b/test/shell.bats index 94778985..1a5af662 100644 --- a/test/shell.bats +++ b/test/shell.bats @@ -22,14 +22,13 @@ load test_helper @test "shell change invalid version" { run rbenv-sh-shell 1.2.3 - assert_failure - assert_line "rbenv: version \`1.2.3' not installed" - assert_line "return 1" + assert_failure "\ + rbenv: version \`1.2.3' not installed + return 1" } @test "shell change version" { mkdir -p "${RBENV_ROOT}/versions/1.2.3" run rbenv-sh-shell 1.2.3 assert_success 'export RBENV_VERSION="1.2.3"' - refute_line "return 1" } diff --git a/test/whence.bats b/test/whence.bats new file mode 100644 index 00000000..583a2ca6 --- /dev/null +++ b/test/whence.bats @@ -0,0 +1,28 @@ +#!/usr/bin/env bats + +load test_helper + +create_executable() { + local bin="${RBENV_ROOT}/versions/${1}/bin" + mkdir -p "$bin" + touch "${bin}/$2" + chmod +x "${bin}/$2" +} + +@test "finds versions where present" { + create_executable "1.8" "ruby" + create_executable "1.8" "rake" + create_executable "2.0" "ruby" + create_executable "2.0" "rspec" + + run rbenv-whence ruby + assert_success "\ + 1.8 + 2.0" + + run rbenv-whence rake + assert_success "1.8" + + run rbenv-whence rspec + assert_success "2.0" +} diff --git a/test/which.bats b/test/which.bats new file mode 100644 index 00000000..530c1f4b --- /dev/null +++ b/test/which.bats @@ -0,0 +1,57 @@ +#!/usr/bin/env bats + +load test_helper + +create_executable() { + local bin + if [[ $1 == */* ]]; then bin="$1" + else bin="${RBENV_ROOT}/versions/${1}/bin" + fi + mkdir -p "$bin" + touch "${bin}/$2" + chmod +x "${bin}/$2" +} + +@test "outputs path to executable" { + create_executable "1.8" "ruby" + create_executable "2.0" "rspec" + + RBENV_VERSION=1.8 run rbenv-which ruby + assert_success "${RBENV_ROOT}/versions/1.8/bin/ruby" + + RBENV_VERSION=2.0 run rbenv-which rspec + assert_success "${RBENV_ROOT}/versions/2.0/bin/rspec" +} + +@test "searches PATH for system version" { + create_executable "${RBENV_TEST_DIR}/bin" "kill-all-humans" + create_executable "${RBENV_ROOT}/shims" "kill-all-humans" + + RBENV_VERSION=system run rbenv-which kill-all-humans + assert_success "${RBENV_TEST_DIR}/bin/kill-all-humans" +} + +@test "version not installed" { + create_executable "2.0" "rspec" + RBENV_VERSION=1.9 run rbenv-which rspec + assert_failure "rbenv: version \`1.9' is not installed" +} + +@test "no executable found" { + create_executable "1.8" "rspec" + RBENV_VERSION=1.8 run rbenv-which rake + assert_failure "rbenv: rake: command not found" +} + +@test "executable found in other versions" { + create_executable "1.8" "ruby" + create_executable "1.9" "rspec" + create_executable "2.0" "rspec" + + RBENV_VERSION=1.8 run rbenv-which rspec + assert_failure "\ + rbenv: rspec: command not found + The \`rspec' command exists in these Ruby versions: + 1.9 + 2.0" +} From 7fc5f46bbb843c6be95c3f87d19ba21fef25c5b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohnic=CC=81?= Date: Sat, 6 Apr 2013 14:10:44 +0200 Subject: [PATCH 302/384] undo `assert_output_lines` in tests It was a dumb idea and it wasn't even implemented perfectly. --- test/completions.bats | 8 +++++--- test/exec.bats | 36 ++++++++++++++++++++---------------- test/hooks.bats | 18 +++++++++++------- test/rehash.bats | 10 ++++++---- test/shell.bats | 8 +++++--- test/test_helper.bash | 24 +++++++----------------- test/whence.bats | 8 +++++--- test/which.bats | 13 ++++++++----- 8 files changed, 67 insertions(+), 58 deletions(-) diff --git a/test/completions.bats b/test/completions.bats index 0f79654d..0feccfa9 100644 --- a/test/completions.bats +++ b/test/completions.bats @@ -38,7 +38,9 @@ else exit 1 fi" run rbenv-completions hello happy world - assert_success "\ - happy - world" + assert_success + assert_output <" { @@ -85,9 +88,10 @@ else fi SH - create_executable "rake" "\ - #!/usr/bin/env ruby - echo hello rake" + create_executable "rake" < Date: Mon, 8 Apr 2013 21:35:22 +0200 Subject: [PATCH 303/384] add tests for version commands --- libexec/rbenv-local | 5 +- test/local.bats | 54 ++++++++++++++++++- test/version-file-read.bats | 39 ++++++++++++++ test/version-file-write.bats | 30 +++++++++++ test/version-file.bats | 99 ++++++++++++++++++++++++++++++++++ test/version-name.bats | 65 +++++++++++++++++++++++ test/version-origin.bats | 38 +++++++++++++ test/version.bats | 38 +++++++++++++ test/versions.bats | 100 +++++++++++++++++++++++++++++++++++ 9 files changed, 464 insertions(+), 4 deletions(-) create mode 100644 test/version-file-read.bats create mode 100644 test/version-file-write.bats create mode 100644 test/version-file.bats create mode 100644 test/version-name.bats create mode 100644 test/version-origin.bats create mode 100644 test/version.bats create mode 100644 test/versions.bats diff --git a/libexec/rbenv-local b/libexec/rbenv-local index 34464410..9169943e 100755 --- a/libexec/rbenv-local +++ b/libexec/rbenv-local @@ -38,13 +38,14 @@ RBENV_VERSION="$1" if [ "$RBENV_VERSION" = "--unset" ]; then rm -f .ruby-version .rbenv-version elif [ -n "$RBENV_VERSION" ]; then - if [ "$(RBENV_VERSION= rbenv-version-origin)" -ef .rbenv-version ]; then + previous_file="$(RBENV_VERSION= rbenv-version-origin || true)" + rbenv-version-file-write .ruby-version "$RBENV_VERSION" + if [ "$previous_file" -ef .rbenv-version ]; then rm -f .rbenv-version { echo "rbenv: removed existing \`.rbenv-version' file and migrated" echo " local version specification to \`.ruby-version' file" } >&2 fi - rbenv-version-file-write .ruby-version "$RBENV_VERSION" else rbenv-version-file-read .ruby-version || rbenv-version-file-read .rbenv-version || diff --git a/test/local.bats b/test/local.bats index 5ccdb2b5..3e93ca7f 100644 --- a/test/local.bats +++ b/test/local.bats @@ -19,6 +19,19 @@ setup() { assert_success "1.2.3" } +@test "supports legacy .rbenv-version file" { + echo "1.2.3" > .rbenv-version + run rbenv-local + assert_success "1.2.3" +} + +@test "local .ruby-version has precedence over .rbenv-version" { + echo "1.8" > .rbenv-version + echo "2.0" > .ruby-version + run rbenv-local + assert_success "2.0" +} + @test "ignores version in parent directory" { echo "1.2.3" > .ruby-version mkdir -p "subdir" && cd "subdir" @@ -48,6 +61,43 @@ setup() { assert_success "1.0-pre" run rbenv-local 1.2.3 assert_success "" - run rbenv-local - assert_success "1.2.3" + assert [ "$(cat .ruby-version)" = "1.2.3" ] +} + +@test "renames .rbenv-version to .ruby-version" { + echo "1.8.7" > .rbenv-version + mkdir -p "${RBENV_ROOT}/versions/1.9.3" + run rbenv-local + assert_success "1.8.7" + run rbenv-local "1.9.3" + assert_success + assert_output < .rbenv-version + assert [ ! -e "${RBENV_ROOT}/versions/1.9.3" ] + run rbenv-local "1.9.3" + assert_failure "rbenv: version \`1.9.3' not installed" + assert [ ! -e .ruby-version ] + assert [ "$(cat .rbenv-version)" = "1.8.7" ] +} + +@test "unsets local version" { + touch .ruby-version + run rbenv-local --unset + assert_success "" + assert [ ! -e .rbenv-version ] +} + +@test "unsets alternate version file" { + touch .rbenv-version + run rbenv-local --unset + assert_success "" + assert [ ! -e .rbenv-version ] } diff --git a/test/version-file-read.bats b/test/version-file-read.bats new file mode 100644 index 00000000..8002388d --- /dev/null +++ b/test/version-file-read.bats @@ -0,0 +1,39 @@ +#!/usr/bin/env bats + +load test_helper + +setup() { + mkdir -p "${RBENV_TEST_DIR}/myproject" + cd "${RBENV_TEST_DIR}/myproject" +} + +@test "fails without arguments" { + run rbenv-version-file-read + assert_failure "" +} + +@test "fails for invalid file" { + run rbenv-version-file-read "non-existent" + assert_failure "" +} + +@test "reads simple version file" { + cat > my-version <<<"1.9.3" + run rbenv-version-file-read my-version + assert_success "1.9.3" +} + +@test "reads only the first word from file" { + cat > my-version <<<"1.9.3-p194@tag 1.8.7 hi" + run rbenv-version-file-read my-version + assert_success "1.9.3-p194@tag" +} + +@test "loads only the first line in file" { + cat > my-version < " + run rbenv-version-file-write "one" "" + assert_failure +} + +@test "setting nonexistent version fails" { + assert [ ! -e ".ruby-version" ] + run rbenv-version-file-write ".ruby-version" "1.8.7" + assert_failure "rbenv: version \`1.8.7' not installed" + assert [ ! -e ".ruby-version" ] +} + +@test "writes value to arbitrary file" { + mkdir -p "${RBENV_ROOT}/versions/1.8.7" + assert [ ! -e "my-version" ] + run rbenv-version-file-write "${PWD}/my-version" "1.8.7" + assert_success "" + assert [ "$(cat my-version)" = "1.8.7" ] +} diff --git a/test/version-file.bats b/test/version-file.bats new file mode 100644 index 00000000..ed84c484 --- /dev/null +++ b/test/version-file.bats @@ -0,0 +1,99 @@ +#!/usr/bin/env bats + +load test_helper + +setup() { + mkdir -p "$RBENV_TEST_DIR" + cd "$RBENV_TEST_DIR" +} + +create_file() { + mkdir -p "$(dirname "$1")" + touch "$1" +} + +@test "prints global file if no version files exist" { + assert [ ! -e "${RBENV_ROOT}/version" ] + assert [ ! -e ".ruby-version" ] + run rbenv-version-file + assert_success "${RBENV_ROOT}/version" +} + +@test "detects 'global' file" { + create_file "${RBENV_ROOT}/global" + run rbenv-version-file + assert_success "${RBENV_ROOT}/global" +} + +@test "detects 'default' file" { + create_file "${RBENV_ROOT}/default" + run rbenv-version-file + assert_success "${RBENV_ROOT}/default" +} + +@test "'version' has precedence over 'global' and 'default'" { + create_file "${RBENV_ROOT}/version" + create_file "${RBENV_ROOT}/global" + create_file "${RBENV_ROOT}/default" + run rbenv-version-file + assert_success "${RBENV_ROOT}/version" +} + +@test "in current directory" { + create_file ".ruby-version" + run rbenv-version-file + assert_success "${RBENV_TEST_DIR}/.ruby-version" +} + +@test "legacy file in current directory" { + create_file ".rbenv-version" + run rbenv-version-file + assert_success "${RBENV_TEST_DIR}/.rbenv-version" +} + +@test ".ruby-version has precedence over legacy file" { + create_file ".ruby-version" + create_file ".rbenv-version" + run rbenv-version-file + assert_success "${RBENV_TEST_DIR}/.ruby-version" +} + +@test "in parent directory" { + create_file ".ruby-version" + mkdir -p project + cd project + run rbenv-version-file + assert_success "${RBENV_TEST_DIR}/.ruby-version" +} + +@test "topmost file has precedence" { + create_file ".ruby-version" + create_file "project/.ruby-version" + cd project + run rbenv-version-file + assert_success "${RBENV_TEST_DIR}/project/.ruby-version" +} + +@test "legacy file has precedence if higher" { + create_file ".ruby-version" + create_file "project/.rbenv-version" + cd project + run rbenv-version-file + assert_success "${RBENV_TEST_DIR}/project/.rbenv-version" +} + +@test "RBENV_DIR has precedence over PWD" { + create_file "widget/.ruby-version" + create_file "project/.ruby-version" + cd project + RBENV_DIR="${RBENV_TEST_DIR}/widget" run rbenv-version-file + assert_success "${RBENV_TEST_DIR}/widget/.ruby-version" +} + +@test "PWD is searched if RBENV_DIR yields no results" { + mkdir -p "widget/blank" + create_file "project/.ruby-version" + cd project + RBENV_DIR="${RBENV_TEST_DIR}/widget/blank" run rbenv-version-file + assert_success "${RBENV_TEST_DIR}/project/.ruby-version" +} diff --git a/test/version-name.bats b/test/version-name.bats new file mode 100644 index 00000000..3f4d9b36 --- /dev/null +++ b/test/version-name.bats @@ -0,0 +1,65 @@ +#!/usr/bin/env bats + +load test_helper + +create_version() { + mkdir -p "${RBENV_ROOT}/versions/$1" +} + +setup() { + mkdir -p "$RBENV_TEST_DIR" + cd "$RBENV_TEST_DIR" +} + +@test "no version selected" { + assert [ ! -d "${RBENV_ROOT}/versions" ] + run rbenv-version-name + assert_success "system" +} + +@test "system version is not checked for existance" { + RBENV_VERSION=system run rbenv-version-name + assert_success "system" +} + +@test "RBENV_VERSION has precedence over local" { + create_version "1.8.7" + create_version "1.9.3" + + cat > ".ruby-version" <<<"1.8.7" + run rbenv-version-name + assert_success "1.8.7" + + RBENV_VERSION=1.9.3 run rbenv-version-name + assert_success "1.9.3" +} + +@test "local file has precedence over global" { + create_version "1.8.7" + create_version "1.9.3" + + cat > "${RBENV_ROOT}/version" <<<"1.8.7" + run rbenv-version-name + assert_success "1.8.7" + + cat > ".ruby-version" <<<"1.9.3" + run rbenv-version-name + assert_success "1.9.3" +} + +@test "missing version" { + RBENV_VERSION=1.2 run rbenv-version-name + assert_failure "rbenv: version \`1.2' is not installed" +} + +@test "version with prefix in name" { + create_version "1.8.7" + cat > ".ruby-version" <<<"ruby-1.8.7" + run rbenv-version-name + assert_success + assert_output < ".ruby-version" <<<"1.9.3" + run rbenv-version + assert_success "1.9.3 (set by ${PWD}/.ruby-version)" +} + +@test "set by global file" { + create_version "1.9.3" + cat > "${RBENV_ROOT}/version" <<<"1.9.3" + run rbenv-version + assert_success "1.9.3 (set by ${RBENV_ROOT}/version)" +} diff --git a/test/versions.bats b/test/versions.bats new file mode 100644 index 00000000..cdec7a8a --- /dev/null +++ b/test/versions.bats @@ -0,0 +1,100 @@ +#!/usr/bin/env bats + +load test_helper + +create_version() { + mkdir -p "${RBENV_ROOT}/versions/$1" +} + +@test "no versions installed" { + assert [ ! -d "${RBENV_ROOT}/versions" ] + run rbenv-versions + assert_success "* system (set by ${RBENV_ROOT}/version)" +} + +@test "bare output no versions installed" { + assert [ ! -d "${RBENV_ROOT}/versions" ] + run rbenv-versions --bare + assert_success "" +} + +@test "single version installed" { + create_version "1.9" + run rbenv-versions + assert_success + assert_output < "${RBENV_ROOT}/version" <<<"1.9.3" + run rbenv-versions + assert_success + assert_output < ".ruby-version" <<<"1.9.3" + run rbenv-versions + assert_success + assert_output < Date: Mon, 8 Apr 2013 23:00:15 +0200 Subject: [PATCH 304/384] add tests for `help` and `rbenv --version` --- test/--version.bats | 46 ++++++++++++++++++ test/help.bats | 115 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 161 insertions(+) create mode 100644 test/--version.bats create mode 100644 test/help.bats diff --git a/test/--version.bats b/test/--version.bats new file mode 100644 index 00000000..e99a3a95 --- /dev/null +++ b/test/--version.bats @@ -0,0 +1,46 @@ +#!/usr/bin/env bats + +load test_helper + +setup() { + mkdir -p "$HOME" + git config --global user.name "Tester" + git config --global user.email "tester@test.local" +} + +git_commit() { + git commit --quiet --allow-empty -m "" --allow-empty-message +} + +@test "default version" { + assert [ ! -e "$RBENV_ROOT" ] + run rbenv---version + assert_success + [[ $output == "rbenv 0."* ]] +} + +@test "reads version from git repo" { + mkdir -p "$RBENV_ROOT" + cd "$RBENV_ROOT" + git init + git_commit + git tag v0.4.1 + git_commit + git_commit + + cd "$RBENV_TEST_DIR" + run rbenv---version + assert_success + [[ $output == "rbenv 0.4.1-2-g"* ]] +} + +@test "prints default version if no tags in git repo" { + mkdir -p "$RBENV_ROOT" + cd "$RBENV_ROOT" + git init + git_commit + + cd "$RBENV_TEST_DIR" + run rbenv---version + [[ $output == "rbenv 0."* ]] +} diff --git a/test/help.bats b/test/help.bats new file mode 100644 index 00000000..9862d630 --- /dev/null +++ b/test/help.bats @@ -0,0 +1,115 @@ +#!/usr/bin/env bats + +load test_helper + +@test "without args shows summary of common commands" { + run rbenv-help + assert_success + assert_line "Usage: rbenv []" + assert_line "Some useful rbenv commands are:" +} + +@test "invalid command" { + run rbenv-help hello + assert_failure "rbenv: no such command \`hello'" +} + +@test "shows help for a specific command" { + mkdir -p "${RBENV_TEST_DIR}/bin" + cat > "${RBENV_TEST_DIR}/bin/rbenv-hello" < +# Summary: Says "hello" to you, from rbenv +# This command is useful for saying hello. +echo hello +SH + + run rbenv-help hello + assert_success + assert_output < + +This command is useful for saying hello. +SH +} + +@test "replaces missing extended help with summary text" { + mkdir -p "${RBENV_TEST_DIR}/bin" + cat > "${RBENV_TEST_DIR}/bin/rbenv-hello" < +# Summary: Says "hello" to you, from rbenv +echo hello +SH + + run rbenv-help hello + assert_success + assert_output < + +Says "hello" to you, from rbenv +SH +} + +@test "extracts only usage" { + mkdir -p "${RBENV_TEST_DIR}/bin" + cat > "${RBENV_TEST_DIR}/bin/rbenv-hello" < +# Summary: Says "hello" to you, from rbenv +# This extended help won't be shown. +echo hello +SH + + run rbenv-help --usage hello + assert_success "Usage: rbenv hello " +} + +@test "multiline usage section" { + mkdir -p "${RBENV_TEST_DIR}/bin" + cat > "${RBENV_TEST_DIR}/bin/rbenv-hello" < +# rbenv hi [everybody] +# rbenv hola --translate +# Summary: Says "hello" to you, from rbenv +# Help text. +echo hello +SH + + run rbenv-help hello + assert_success + assert_output < + rbenv hi [everybody] + rbenv hola --translate + +Help text. +SH +} + +@test "multiline extended help section" { + mkdir -p "${RBENV_TEST_DIR}/bin" + cat > "${RBENV_TEST_DIR}/bin/rbenv-hello" < +# Summary: Says "hello" to you, from rbenv +# This is extended help text. +# It can contain multiple lines. +# +# And paragraphs. + +echo hello +SH + + run rbenv-help hello + assert_success + assert_output < + +This is extended help text. +It can contain multiple lines. + +And paragraphs. +SH +} From bc1049f5aec5590d198e6995ccdce9dd49e4fa3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohnic=CC=81?= Date: Tue, 16 Apr 2013 12:52:42 +0200 Subject: [PATCH 305/384] improve `versions` tests by cd'ing into a clean slate --- test/versions.bats | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/test/versions.bats b/test/versions.bats index cdec7a8a..11acdfc8 100644 --- a/test/versions.bats +++ b/test/versions.bats @@ -6,6 +6,11 @@ create_version() { mkdir -p "${RBENV_ROOT}/versions/$1" } +setup() { + mkdir -p "$RBENV_TEST_DIR" + cd "$RBENV_TEST_DIR" +} + @test "no versions installed" { assert [ ! -d "${RBENV_ROOT}/versions" ] run rbenv-versions @@ -87,8 +92,6 @@ OUT @test "per-project version" { create_version "1.9.3" create_version "2.0.0" - mkdir -p "$RBENV_TEST_DIR" - cd "$RBENV_TEST_DIR" cat > ".ruby-version" <<<"1.9.3" run rbenv-versions assert_success From 6ca591ab757cd9162bd7fecde225bd696c77077a Mon Sep 17 00:00:00 2001 From: Ian Yang Date: Tue, 16 Apr 2013 00:10:56 +0800 Subject: [PATCH 306/384] restore original IFS for hooks --- libexec/rbenv-exec | 2 ++ libexec/rbenv-rehash | 3 +++ libexec/rbenv-which | 2 ++ 3 files changed, 7 insertions(+) diff --git a/libexec/rbenv-exec b/libexec/rbenv-exec index eb16dc70..a9309d0e 100755 --- a/libexec/rbenv-exec +++ b/libexec/rbenv-exec @@ -33,7 +33,9 @@ export RBENV_VERSION RBENV_COMMAND_PATH="$(rbenv-which "$RBENV_COMMAND")" RBENV_BIN_PATH="${RBENV_COMMAND_PATH%/*}" +OLDIFS="$IFS" IFS=$'\n' scripts=(`rbenv-hooks exec`) +IFS="$OLDIFS" for script in "${scripts[@]}"; do source "$script" done diff --git a/libexec/rbenv-rehash b/libexec/rbenv-rehash index fd987ace..b220329a 100755 --- a/libexec/rbenv-rehash +++ b/libexec/rbenv-rehash @@ -144,7 +144,10 @@ make_shims ../versions/*/bin/* cd "$OLDPWD" # Allow plugins to register shims. +OLDIFS="$IFS" IFS=$'\n' scripts=(`rbenv-hooks rehash`) +IFS="$OLDIFS" + for script in "${scripts[@]}"; do source "$script" done diff --git a/libexec/rbenv-which b/libexec/rbenv-which index 393a06e8..5d73673c 100755 --- a/libexec/rbenv-which +++ b/libexec/rbenv-which @@ -63,7 +63,9 @@ else RBENV_COMMAND_PATH="${RBENV_ROOT}/versions/${RBENV_VERSION}/bin/${RBENV_COMMAND}" fi +OLDIFS="$IFS" IFS=$'\n' scripts=(`rbenv-hooks which`) +IFS="$OLDIFS" for script in "${scripts[@]}"; do source "$script" done From 060f141b2174f9ab53b7c2c248ad8f426ec5c125 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohnic=CC=81?= Date: Tue, 16 Apr 2013 14:01:04 +0200 Subject: [PATCH 307/384] test that IFS in hooks is correct closes #379 --- test/exec.bats | 14 ++++++++++++++ test/rehash.bats | 14 ++++++++++++++ test/which.bats | 14 ++++++++++++++ 3 files changed, 42 insertions(+) diff --git a/test/exec.bats b/test/exec.bats index bf57c597..889eb897 100644 --- a/test/exec.bats +++ b/test/exec.bats @@ -45,6 +45,20 @@ OUT assert_line "HELLO=from hook" } +@test "carries original IFS within hooks" { + hook_path="${RBENV_TEST_DIR}/rbenv.d" + mkdir -p "${hook_path}/exec" + cat > "${hook_path}/exec/hello.bash" < "${hook_path}/rehash/hello.bash" < "${hook_path}/which/hello.bash" < Date: Fri, 7 Jun 2013 19:10:40 +0200 Subject: [PATCH 308/384] work around bug in git 1.8.2.1 in tests Making empty commits in tests blocked by opening the default text editor, waiting for a message which we specified to be empty. http://thread.gmane.org/gmane.comp.version-control.git/225529 --- test/--version.bats | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/--version.bats b/test/--version.bats index e99a3a95..4e0e452d 100644 --- a/test/--version.bats +++ b/test/--version.bats @@ -9,7 +9,7 @@ setup() { } git_commit() { - git commit --quiet --allow-empty -m "" --allow-empty-message + git commit --quiet --allow-empty -m "empty" } @test "default version" { From 81bb14e181c556e599e20ca6fdc86fdb690b8995 Mon Sep 17 00:00:00 2001 From: James FitzGibbon Date: Fri, 10 May 2013 14:20:16 -0700 Subject: [PATCH 309/384] bail out early if readlink is not available readlink comes from GNU coreutils. On systems without it, rbenv used to spin out of control when it didn't have readlink or greadlink available because it would re-exec the frontend script over and over instead of the worker script in libexec. Fixes #389 --- libexec/rbenv | 8 +++++++- libexec/rbenv-hooks | 8 +++++++- libexec/rbenv-init | 8 +++++++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/libexec/rbenv b/libexec/rbenv index 0e70361d..2d475857 100755 --- a/libexec/rbenv +++ b/libexec/rbenv @@ -12,8 +12,14 @@ if [ -n "$RBENV_DEBUG" ]; then set -x 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() { - $(type -p greadlink readlink | head -1) "$1" + $READLINK "$1" } abs_dirname() { diff --git a/libexec/rbenv-hooks b/libexec/rbenv-hooks index f81e9af4..86386719 100755 --- a/libexec/rbenv-hooks +++ b/libexec/rbenv-hooks @@ -19,8 +19,14 @@ if [ -z "$RBENV_COMMAND" ]; then 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() { - $(type -p greadlink readlink | head -1) $1 + $READLINK "$1" } realpath() { diff --git a/libexec/rbenv-init b/libexec/rbenv-init index 8cbe7df0..7fb7b737 100755 --- a/libexec/rbenv-init +++ b/libexec/rbenv-init @@ -25,8 +25,14 @@ if [ -z "$shell" ]; then shell="$(basename "$SHELL")" 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() { - $(type -p greadlink readlink | head -1) $1 + $READLINK "$1" } abs_dirname() { From 5130b41f5b7d6b5002a4bb2f45ebb857f72f3dcc Mon Sep 17 00:00:00 2001 From: Marc Huffnagle Date: Fri, 29 Mar 2013 11:06:26 -0400 Subject: [PATCH 310/384] suggest cloning rbenv via https instead of git:// --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ff7fe446..7712a06d 100644 --- a/README.md +++ b/README.md @@ -156,7 +156,7 @@ easy to fork and contribute any changes back upstream. 1. Check out rbenv into `~/.rbenv`. ~~~ sh - $ git clone git://github.com/sstephenson/rbenv.git ~/.rbenv + $ git clone https://github.com/sstephenson/rbenv.git ~/.rbenv ~~~ 2. Add `~/.rbenv/bin` to your `$PATH` for access to the `rbenv` From 8b043038b81c55427d4de8595efe57624f9deffa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Thu, 20 Jun 2013 20:38:07 +0200 Subject: [PATCH 311/384] ensure cleaner PATH in test environment --- test/test_helper.bash | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/test/test_helper.bash b/test/test_helper.bash index 75912f14..01d9fb99 100644 --- a/test/test_helper.bash +++ b/test/test_helper.bash @@ -1,14 +1,20 @@ -RBENV_TEST_DIR="${BATS_TMPDIR}/rbenv" -export RBENV_ROOT="${RBENV_TEST_DIR}/root" -export HOME="${RBENV_TEST_DIR}/home" - unset RBENV_VERSION unset RBENV_DIR -export PATH="${RBENV_TEST_DIR}/bin:$PATH" -export PATH="${BATS_TEST_DIRNAME}/../libexec:$PATH" -export PATH="${BATS_TEST_DIRNAME}/libexec:$PATH" -export PATH="${RBENV_ROOT}/shims:$PATH" +RBENV_TEST_DIR="${BATS_TMPDIR}/rbenv" + +# guard against executing this block twice due to bats internals +if [ "$RBENV_ROOT" != "${RBENV_TEST_DIR}/root" ]; then + export RBENV_ROOT="${RBENV_TEST_DIR}/root" + export HOME="${RBENV_TEST_DIR}/home" + + PATH=/usr/bin:/bin:/usr/sbin:/sbin + PATH="${RBENV_TEST_DIR}/bin:$PATH" + PATH="${BATS_TEST_DIRNAME}/../libexec:$PATH" + PATH="${BATS_TEST_DIRNAME}/libexec:$PATH" + PATH="${RBENV_ROOT}/shims:$PATH" + export PATH +fi teardown() { rm -rf "$RBENV_TEST_DIR" @@ -18,7 +24,7 @@ flunk() { { if [ "$#" -eq 0 ]; then cat - else echo "$@" fi - } | sed "s:${RBENV_TEST_DIR}:TEST_DIR:" >&2 + } | sed "s:${RBENV_TEST_DIR}:TEST_DIR:g" >&2 return 1 } From db143bb654fe447a462b0d91ba931e0524f234f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Thu, 20 Jun 2013 17:22:15 +0200 Subject: [PATCH 312/384] rbenv exec: avoid mutating PATH Enables shelling out from a ruby process started with rbenv to a ruby process with a different RBENV_VERSION. Fixes #121 This removes the workaround created for #15 and solves `ruby -S` support by setting RUBYPATH. PATH is never changed. To illustrate how RUBYPATH changes in various configurations: PATH=~/bin:~/.rbenv/shims:/usr/bin:/bin RBENV_VERSION=1.8 ruby -S rake #=> executes ~/.rbenv/versions/1.8/bin/rake #=> RUBYPATH=~/bin:~/.rbenv/versions/1.8/bin:/usr/bin:/bin RBENV_VERSION=2.0 ruby -S rake #=> executes ~/.rbenv/versions/2.0/bin/rake #=> RUBYPATH=~/bin:~/.rbenv/versions/2.0/bin:/usr/bin:/bin RBENV_VERSION=system ruby -S rake #=> executes /usr/bin/rake #=> RUBYPATH=~/bin:/rbenv_shims_were_here:/usr/bin:/bin RBENV_VERSION=1.8 ruby -S rake #=> executes ~/.rbenv/versions/1.8/bin/rake #=> RUBYPATH=~/bin:~/.rbenv/versions/1.8/bin:/usr/bin:/bin --- libexec/rbenv-exec | 64 +++++++++--- libexec/rbenv-rehash | 4 +- test/exec.bats | 244 +++++++++++++++++++++++++++++++++++++++---- 3 files changed, 275 insertions(+), 37 deletions(-) diff --git a/libexec/rbenv-exec b/libexec/rbenv-exec index a9309d0e..f3908f8d 100755 --- a/libexec/rbenv-exec +++ b/libexec/rbenv-exec @@ -2,24 +2,59 @@ # # Summary: Run an executable with the selected Ruby version # -# Usage: rbenv exec [arg1 arg2...] +# Usage: rbenv exec [args...] # -# Runs an executable by first preparing PATH so that the selected Ruby -# version's `bin' directory is at the front. +# Runs an executable contained by the currently selected Ruby's bin +# directory. Rough equivalent of: # -# For example, if the currently selected Ruby version is 1.9.3-p327: -# rbenv exec bundle install -# -# is equivalent to: -# PATH="$RBENV_ROOT/versions/1.9.3-p327/bin:$PATH" bundle install +# exec "$(rbenv prefix)/bin/$command" args... set -e [ -n "$RBENV_DEBUG" ] && set -x +rubypath="" # Provide rbenv completions -if [ "$1" = "--complete" ]; then - exec rbenv shims --short -fi +while true; do + case "$1" in + "--complete" ) + exec rbenv shims --short + ;; + "--rubypath" ) + rubypath=1 + shift 1 + ;; + * ) + break + ;; + esac +done + +# Replace any "RBENV_ROOT/shims" or "RBENV_ROOT/versions/*/bin" paths in the +# list with the given path. If no replacements were made, prepend the path onto +# the list. +replace_shims_path() { + local path="$1" + local dir="$2" + # fake directory that serves as a placeholder for shims location in RUBYPATH: + local placeholder="/rbenv_shims_were_here" + local found="" + local result="" + local -a paths + IFS=: paths=($path) + + for path in "${paths[@]}"; do + if [[ $path = "${RBENV_ROOT}/shims" || $path == "${RBENV_ROOT}/versions/"*/bin || $path = $placeholder ]]; then + found=1 + result="${result}${dir:-$placeholder}:" + else + result="${result}${path}:" + fi + done + + # if no rbenv paths were replaced, simply prepend the path + [ -n "$found" -o -z "$dir" ] || result="${dir}:${path}" + echo "${result%:}" +} RBENV_VERSION="$(rbenv-version-name)" RBENV_COMMAND="$1" @@ -31,7 +66,6 @@ fi export RBENV_VERSION RBENV_COMMAND_PATH="$(rbenv-which "$RBENV_COMMAND")" -RBENV_BIN_PATH="${RBENV_COMMAND_PATH%/*}" OLDIFS="$IFS" IFS=$'\n' scripts=(`rbenv-hooks exec`) @@ -41,7 +75,9 @@ for script in "${scripts[@]}"; do done shift 1 -if [ "$RBENV_VERSION" != "system" ]; then - export PATH="${RBENV_BIN_PATH}:${PATH}" +if [ -n "$rubypath" ]; then + bindir="" + [ "$RBENV_VERSION" != "system" ] && bindir="${RBENV_COMMAND_PATH%/*}" + export RUBYPATH="$(replace_shims_path "${RUBYPATH:-$PATH}" "$bindir")" fi exec -a "$RBENV_COMMAND" "$RBENV_COMMAND_PATH" "$@" diff --git a/libexec/rbenv-rehash b/libexec/rbenv-rehash index b220329a..d8154279 100755 --- a/libexec/rbenv-rehash +++ b/libexec/rbenv-rehash @@ -45,10 +45,12 @@ create_prototype_shim() { set -e [ -n "\$RBENV_DEBUG" ] && set -x +opt="" program="\${0##*/}" if [ "\$program" = "ruby" ]; then for arg; do case "\$arg" in + -S* ) opt=--rubypath ;; -e* | -- ) break ;; */* ) if [ -f "\$arg" ]; then @@ -61,7 +63,7 @@ if [ "\$program" = "ruby" ]; then fi export RBENV_ROOT="$RBENV_ROOT" -exec "$(command -v rbenv)" exec "\$program" "\$@" +exec "$(command -v rbenv)" exec \$opt "\$program" "\$@" SH chmod +x "$PROTOTYPE_SHIM_PATH" } diff --git a/test/exec.bats b/test/exec.bats index 889eb897..f82a42ef 100644 --- a/test/exec.bats +++ b/test/exec.bats @@ -3,15 +3,37 @@ load test_helper create_executable() { - name="${1?}" + local file="${1?}" + [[ $file == */* ]] || file="${RBENV_ROOT}/versions/${RBENV_VERSION}/bin/$file" shift 1 - bin="${RBENV_ROOT}/versions/${RBENV_VERSION}/bin" - mkdir -p "$bin" + mkdir -p "${file%/*}" { if [ $# -eq 0 ]; then cat - else echo "$@" fi - } | sed -Ee '1s/^ +//' > "${bin}/$name" - chmod +x "${bin}/$name" + } | sed -Ee '1s/^[[:space:]]+//' > "$file" + chmod +x "$file" +} + +# Fake ruby executable that emulates `ruby -S ' behavior by running the +# first `cmd' found in RUBYPATH/PATH as bash script. +create_ruby_executable() { + create_executable "${1:-ruby}" </dev/null; then + \$BASH "\$found" + else + echo "ruby: no Ruby script found in input (LoadError)" >&2 + exit 1 + fi +else + echo 'ruby (rbenv test)' +fi +SH } @test "fails with invalid version" { @@ -82,26 +104,56 @@ ${RBENV_ROOT}/versions/2.0/bin/ruby OUT } +@test "doesn't mutate PATH" { + export RBENV_VERSION="2.0" + create_executable "ruby" <" { export RBENV_VERSION="2.0" - # emulate `ruby -S' behavior - create_executable "ruby" </dev/null; then - \$BASH "\$found" - else - echo "ruby: no Ruby script found in input (LoadError)" >&2 - exit 1 - fi -else - echo 'ruby 2.0 (rbenv test)' -fi -SH - + create_ruby_executable create_executable "rake" < Date: Thu, 25 Jul 2013 00:02:05 +0300 Subject: [PATCH 313/384] Homebrew homepage location changed --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7712a06d..e67185c0 100644 --- a/README.md +++ b/README.md @@ -225,7 +225,7 @@ $ git checkout v0.3.0 ### Homebrew on Mac OS X You can also install rbenv using the -[Homebrew](http://mxcl.github.com/homebrew/) package manager on Mac OS +[Homebrew](http://brew.sh) package manager on Mac OS X. ~~~ From 1cc75362d6e5ffcff3e610def863049717734292 Mon Sep 17 00:00:00 2001 From: Aaron Stone Date: Tue, 6 Aug 2013 13:40:39 -0700 Subject: [PATCH 314/384] Clarify the search precedence for .ruby-version files. Closes #432 [ci skip] --- README.md | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index e67185c0..c9159e92 100644 --- a/README.md +++ b/README.md @@ -108,13 +108,14 @@ reading it from the following sources, in this order: the [`rbenv shell`](#rbenv-shell) command to set this environment variable in your current shell session. -2. The application-specific `.ruby-version` file in the current - directory, if present. You can modify the current directory's - `.ruby-version` file with the [`rbenv local`](#rbenv-local) - command. +2. The first `.ruby-version` file found by searching the directory of the + script you are executing and each of its parent directories until reaching + the root of your filesystem. -3. The first `.ruby-version` file found by searching each parent - directory until reaching the root of your filesystem, if any. +3. The first `.ruby-version` file found by searching the current working + directory and each of its parent directories until reaching the root of your + filesystem. You can modify the `.ruby-version` file in the current working + directory with the [`rbenv local`](#rbenv-local) command. 4. The global `~/.rbenv/version` file. You can modify this file using the [`rbenv global`](#rbenv-global) command. If the global version From 749f21e48221c57b3e3b29676e3df7c515c44425 Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Mon, 9 Sep 2013 10:41:04 +1000 Subject: [PATCH 315/384] Install a more recent version of Ruby in README instructions --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c9159e92..39267560 100644 --- a/README.md +++ b/README.md @@ -191,7 +191,7 @@ easy to fork and contribute any changes back upstream. process of installing new Ruby versions. ~~~ - $ rbenv install 1.9.3-p327 + $ rbenv install 2.0.0-p247 ~~~ As an alternative, you can download and compile Ruby yourself into From bdcc2e179008e6060a95412c67a9e3abdc7f24f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Mon, 9 Sep 2013 09:53:29 +0200 Subject: [PATCH 316/384] check if completion script is readable fixes #444 --- libexec/rbenv-init | 7 ++----- test/init.bats | 2 +- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/libexec/rbenv-init b/libexec/rbenv-init index 7fb7b737..2dbd67d1 100755 --- a/libexec/rbenv-init +++ b/libexec/rbenv-init @@ -83,11 +83,8 @@ if [[ ":${PATH}:" != *:"${RBENV_ROOT}/shims":* ]]; then echo 'export PATH="'${RBENV_ROOT}'/shims:${PATH}"' fi -case "$shell" in -bash | zsh ) - echo "source \"$root/completions/rbenv.${shell}\"" - ;; -esac +completion="${root}/completions/rbenv.${shell}" +[ -r "$completion" ] && echo "source '$completion'" if [ -z "$no_rehash" ]; then echo 'rbenv rehash 2>/dev/null' diff --git a/test/init.bats b/test/init.bats index 95781e33..dc9fe302 100644 --- a/test/init.bats +++ b/test/init.bats @@ -22,7 +22,7 @@ load test_helper root="$(cd $BATS_TEST_DIRNAME/.. && pwd)" run rbenv-init - assert_success - assert_line 'source "'${root}'/libexec/../completions/rbenv.bash"' + assert_line "source '${root}/libexec/../completions/rbenv.bash'" } @test "option to skip rehash" { From caa4a8e228808b7e3dc1fdaf11c3d2ebac30296a Mon Sep 17 00:00:00 2001 From: Jeffrey 'jf' Lim Date: Mon, 23 Sep 2013 14:16:15 +0800 Subject: [PATCH 317/384] fix rehash when paths have spaces in them fixes #450 --- libexec/rbenv-rehash | 4 ++-- test/rehash.bats | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/libexec/rbenv-rehash b/libexec/rbenv-rehash index b220329a..5ec195ec 100755 --- a/libexec/rbenv-rehash +++ b/libexec/rbenv-rehash @@ -82,9 +82,9 @@ remove_outdated_shims() { # 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() { - local shims="$@" + local shims=("$@") - for file in $shims; do + for file in "${shims[@]}"; do local shim="${file##*/}" register_shim "$shim" done diff --git a/test/rehash.bats b/test/rehash.bats index afcc11cd..97414410 100755 --- a/test/rehash.bats +++ b/test/rehash.bats @@ -53,6 +53,38 @@ ruby OUT } +@test "removes stale shims" { + mkdir -p "${RBENV_ROOT}/shims" + touch "${RBENV_ROOT}/shims/oldshim1" + chmod +x "${RBENV_ROOT}/shims/oldshim1" + + create_executable "2.0" "rake" + create_executable "2.0" "ruby" + + run rbenv-rehash + assert_success "" + + assert [ ! -e "${RBENV_ROOT}/shims/oldshim1" ] +} + +@test "binary install locations containing spaces" { + create_executable "dirname1 p247" "ruby" + create_executable "dirname2 preview1" "rspec" + + assert [ ! -e "${RBENV_ROOT}/shims/ruby" ] + assert [ ! -e "${RBENV_ROOT}/shims/rspec" ] + + run rbenv-rehash + assert_success "" + + run ls "${RBENV_ROOT}/shims" + assert_success + assert_output < Date: Thu, 15 Aug 2013 23:01:13 +0900 Subject: [PATCH 318/384] add fish shell support --- completions/rbenv.fish | 22 ++++++++++++++++++++++ libexec/rbenv-init | 37 ++++++++++++++++++++++++++++++++++--- libexec/rbenv-sh-rehash | 12 +++++++++++- libexec/rbenv-sh-shell | 21 ++++++++++++++++++--- test/init.bats | 28 ++++++++++++++++++++++++---- test/shell.bats | 24 ++++++++++++++++++++---- 6 files changed, 129 insertions(+), 15 deletions(-) create mode 100644 completions/rbenv.fish diff --git a/completions/rbenv.fish b/completions/rbenv.fish new file mode 100644 index 00000000..3ca8e945 --- /dev/null +++ b/completions/rbenv.fish @@ -0,0 +1,22 @@ +function __fish_rbenv_needs_command + set cmd (commandline -opc) + if [ (count $cmd) -eq 1 -a $cmd[1] = 'rbenv' ] + return 0 + end + return 1 +end + +function __fish_rbenv_using_command + set cmd (commandline -opc) + if [ (count $cmd) -gt 1 ] + if [ $argv[1] = $cmd[2] ] + return 0 + end + end + return 1 +end + +complete -f -c rbenv -n '__fish_rbenv_needs_command' -a '(rbenv commands)' +for cmd in (rbenv commands) + complete -f -c rbenv -n "__fish_rbenv_using_command $cmd" -a "(rbenv completions $cmd)" +end diff --git a/libexec/rbenv-init b/libexec/rbenv-init index 2dbd67d1..c3a3bb02 100755 --- a/libexec/rbenv-init +++ b/libexec/rbenv-init @@ -62,6 +62,9 @@ if [ -z "$print" ]; then ksh ) profile='~/.profile' ;; + fish ) + profile='~/.config/fish/config.fish' + ;; * ) profile='your profile' ;; @@ -80,7 +83,14 @@ fi mkdir -p "${RBENV_ROOT}/"{shims,versions} if [[ ":${PATH}:" != *:"${RBENV_ROOT}/shims":* ]]; then - echo 'export PATH="'${RBENV_ROOT}'/shims:${PATH}"' + case "$shell" in + fish ) + echo 'setenv PATH "'${RBENV_ROOT}'/shims"' '$PATH' ';' + ;; + * ) + echo 'export PATH="'${RBENV_ROOT}'/shims:${PATH}"' + ;; + esac fi completion="${root}/completions/rbenv.${shell}" @@ -91,8 +101,27 @@ if [ -z "$no_rehash" ]; then fi commands=(`rbenv-commands --sh`) -IFS="|" -cat </dev/null || true" + +case "$shell" in +fish ) + # nothing to do + ;; +* ) + echo "hash -r 2>/dev/null || true" + ;; +esac diff --git a/libexec/rbenv-sh-shell b/libexec/rbenv-sh-shell index 4b89c6c0..d0ffe1b0 100755 --- a/libexec/rbenv-sh-shell +++ b/libexec/rbenv-sh-shell @@ -24,6 +24,7 @@ if [ "$1" = "--complete" ]; then fi version="$1" +shell="$(basename "$SHELL")" if [ -z "$version" ]; then if [ -z "$RBENV_VERSION" ]; then @@ -36,14 +37,28 @@ if [ -z "$version" ]; then fi if [ "$version" = "--unset" ]; then - echo "unset RBENV_VERSION" + case "$shell" in + fish ) + echo "set -e RBENV_VERSION" + ;; + * ) + echo "unset RBENV_VERSION" + ;; + esac exit fi # Make sure the specified version is installed. if rbenv-prefix "$version" >/dev/null; then - echo "export RBENV_VERSION=\"${version}\"" + case "$shell" in + fish ) + echo "setenv RBENV_VERSION \"${version}\"" + ;; + * ) + echo "export RBENV_VERSION=\"${version}\"" + ;; + esac else - echo "return 1" + echo "false" exit 1 fi diff --git a/test/init.bats b/test/init.bats index dc9fe302..a4c63199 100644 --- a/test/init.bats +++ b/test/init.bats @@ -18,13 +18,19 @@ load test_helper } @test "setup shell completions" { - export SHELL=/bin/bash root="$(cd $BATS_TEST_DIRNAME/.. && pwd)" - run rbenv-init - + SHELL=/bin/bash run rbenv-init - assert_success assert_line "source '${root}/libexec/../completions/rbenv.bash'" } +@test "setup shell completions (fish)" { + root="$(cd $BATS_TEST_DIRNAME/.. && pwd)" + SHELL=/usr/bin/fish run rbenv-init - + assert_success + assert_line '. "'${root}'/libexec/../completions/rbenv.fish";' +} + @test "option to skip rehash" { run rbenv-init - --no-rehash assert_success @@ -33,14 +39,28 @@ load test_helper @test "adds shims to PATH" { export PATH="${BATS_TEST_DIRNAME}/../libexec:/usr/bin:/bin" - run rbenv-init - + SHELL=/bin/bash run rbenv-init - assert_success assert_line 0 'export PATH="'${RBENV_ROOT}'/shims:${PATH}"' } +@test "adds shims to PATH (fish)" { + export PATH="${BATS_TEST_DIRNAME}/../libexec:/usr/bin:/bin" + SHELL=/usr/bin/fish run rbenv-init - + assert_success + assert_line 0 'setenv PATH "'${RBENV_ROOT}'/shims" $PATH ;' +} + @test "doesn't add shims to PATH more than once" { export PATH="${RBENV_ROOT}/shims:$PATH" - run rbenv-init - + SHELL=/bin/bash run rbenv-init - assert_success refute_line 'export PATH="'${RBENV_ROOT}'/shims:${PATH}"' } + +@test "doesn't add shims to PATH more than once (fish)" { + export PATH="${RBENV_ROOT}/shims:$PATH" + SHELL=/usr/bin/fish run rbenv-init - + assert_success + refute_line 'setenv PATH "'${RBENV_ROOT}'/shims" $PATH ;' +} diff --git a/test/shell.bats b/test/shell.bats index 579d31ae..b14d1cfb 100644 --- a/test/shell.bats +++ b/test/shell.bats @@ -11,26 +11,42 @@ load test_helper } @test "shell version" { - RBENV_VERSION="1.2.3" run rbenv-sh-shell + SHELL=/bin/bash RBENV_VERSION="1.2.3" run rbenv-sh-shell + assert_success 'echo "$RBENV_VERSION"' +} + +@test "shell version (fish)" { + SHELL=/usr/bin/fish RBENV_VERSION="1.2.3" run rbenv-sh-shell assert_success 'echo "$RBENV_VERSION"' } @test "shell unset" { - run rbenv-sh-shell --unset + SHELL=/bin/bash run rbenv-sh-shell --unset assert_success "unset RBENV_VERSION" } +@test "shell unset (fish)" { + SHELL=/usr/bin/fish run rbenv-sh-shell --unset + assert_success "set -e RBENV_VERSION" +} + @test "shell change invalid version" { run rbenv-sh-shell 1.2.3 assert_failure assert_output < Date: Sat, 28 Sep 2013 15:04:24 +0200 Subject: [PATCH 319/384] cleanup in fish Use process subtitution syntax: . (rbenv init -|psub) instead of: eval (rbenv init -) because the latter doesn't work well with newlines. --- libexec/rbenv-init | 17 +++++++++++------ libexec/rbenv-sh-rehash | 6 ++++-- test/init.bats | 6 +++--- test/rehash.bats | 14 ++++++++++++++ 4 files changed, 32 insertions(+), 11 deletions(-) diff --git a/libexec/rbenv-init b/libexec/rbenv-init index c3a3bb02..c240460d 100755 --- a/libexec/rbenv-init +++ b/libexec/rbenv-init @@ -73,7 +73,14 @@ if [ -z "$print" ]; then { echo "# Load rbenv automatically by adding" echo "# the following to ${profile}:" echo - echo 'eval "$(rbenv init -)"' + case "$shell" in + fish ) + echo '. (rbenv init -|psub)' + ;; + * ) + echo 'eval "$(rbenv init -)"' + ;; + esac echo } >&2 @@ -85,7 +92,7 @@ mkdir -p "${RBENV_ROOT}/"{shims,versions} if [[ ":${PATH}:" != *:"${RBENV_ROOT}/shims":* ]]; then case "$shell" in fish ) - echo 'setenv PATH "'${RBENV_ROOT}'/shims"' '$PATH' ';' + echo "setenv PATH '${RBENV_ROOT}/shims' \$PATH" ;; * ) echo 'export PATH="'${RBENV_ROOT}'/shims:${PATH}"' @@ -94,7 +101,7 @@ if [[ ":${PATH}:" != *:"${RBENV_ROOT}/shims":* ]]; then fi completion="${root}/completions/rbenv.${shell}" -[ -r "$completion" ] && echo "source '$completion'" +[ -r "$completion" ] && echo ". '$completion'" if [ -z "$no_rehash" ]; then echo 'rbenv rehash 2>/dev/null' @@ -106,9 +113,7 @@ fish ) cat </dev/null || true" + or='||' ;; esac + +echo "hash -r 2>/dev/null $or true" diff --git a/test/init.bats b/test/init.bats index a4c63199..d0795eef 100644 --- a/test/init.bats +++ b/test/init.bats @@ -21,14 +21,14 @@ load test_helper root="$(cd $BATS_TEST_DIRNAME/.. && pwd)" SHELL=/bin/bash run rbenv-init - assert_success - assert_line "source '${root}/libexec/../completions/rbenv.bash'" + assert_line ". '${root}/libexec/../completions/rbenv.bash'" } @test "setup shell completions (fish)" { root="$(cd $BATS_TEST_DIRNAME/.. && pwd)" SHELL=/usr/bin/fish run rbenv-init - assert_success - assert_line '. "'${root}'/libexec/../completions/rbenv.fish";' + assert_line ". '${root}/libexec/../completions/rbenv.fish'" } @test "option to skip rehash" { @@ -48,7 +48,7 @@ load test_helper export PATH="${BATS_TEST_DIRNAME}/../libexec:/usr/bin:/bin" SHELL=/usr/bin/fish run rbenv-init - assert_success - assert_line 0 'setenv PATH "'${RBENV_ROOT}'/shims" $PATH ;' + assert_line 0 "setenv PATH '${RBENV_ROOT}/shims' \$PATH" } @test "doesn't add shims to PATH more than once" { diff --git a/test/rehash.bats b/test/rehash.bats index 97414410..97f6cd43 100755 --- a/test/rehash.bats +++ b/test/rehash.bats @@ -98,3 +98,17 @@ SH assert_success assert_output "HELLO=:hello:ugly:world:again" } + +@test "sh-rehash in bash" { + create_executable "2.0" "ruby" + SHELL=/bin/bash run rbenv-sh-rehash + assert_success "hash -r 2>/dev/null || true" + assert [ -x "${RBENV_ROOT}/shims/ruby" ] +} + +@test "sh-rehash in fish" { + create_executable "2.0" "ruby" + SHELL=/usr/bin/fish run rbenv-sh-rehash + assert_success "hash -r 2>/dev/null ; or true" + assert [ -x "${RBENV_ROOT}/shims/ruby" ] +} From 5ae2cac088d12fea01054e1f3abbf304b92920b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Sat, 28 Sep 2013 15:58:13 +0200 Subject: [PATCH 320/384] fix `rbenv()` function in ksh and dash ksh syntax becomes: function rbenv { typeset command `typeset` only declares a local variable if there's an explicit `function` declaration; otherwise the variable leaks. Other shells use this syntax: rbenv() { local command This is for dash compatibility, which supports neither `function` nor `typeset`. references #205, fixes #408 --- libexec/rbenv-init | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/libexec/rbenv-init b/libexec/rbenv-init index c240460d..1a2762c7 100755 --- a/libexec/rbenv-init +++ b/libexec/rbenv-init @@ -122,13 +122,25 @@ function rbenv command rbenv "\$command" \$argv end end +EOS + exit 0 + ;; +ksh ) + cat < Date: Thu, 3 Oct 2013 16:12:24 +0200 Subject: [PATCH 321/384] Ubuntu fix: don't use `.` in place of `source` If `rbenv init -` outputs `.` in place of `source` and that gets eval'd by the desktop manager via `~/.profile`, it chokes and prevents the user from logging in. Fixes #457 --- libexec/rbenv-init | 7 ++++++- test/init.bats | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/libexec/rbenv-init b/libexec/rbenv-init index 1a2762c7..22d509bc 100755 --- a/libexec/rbenv-init +++ b/libexec/rbenv-init @@ -101,7 +101,12 @@ if [[ ":${PATH}:" != *:"${RBENV_ROOT}/shims":* ]]; then fi completion="${root}/completions/rbenv.${shell}" -[ -r "$completion" ] && echo ". '$completion'" +if [ -r "$completion" ]; then + case "$shell" in + fish ) echo ". '$completion'" ;; + * ) echo "source '$completion'" ;; + esac +fi if [ -z "$no_rehash" ]; then echo 'rbenv rehash 2>/dev/null' diff --git a/test/init.bats b/test/init.bats index d0795eef..38771ef9 100644 --- a/test/init.bats +++ b/test/init.bats @@ -21,7 +21,7 @@ load test_helper root="$(cd $BATS_TEST_DIRNAME/.. && pwd)" SHELL=/bin/bash run rbenv-init - assert_success - assert_line ". '${root}/libexec/../completions/rbenv.bash'" + assert_line "source '${root}/libexec/../completions/rbenv.bash'" } @test "setup shell completions (fish)" { From a1fb5b1153368e3cd4d47d50965b301f81ca3ff0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Thu, 3 Oct 2013 20:07:22 +0200 Subject: [PATCH 322/384] better Ubuntu Desktop installation instructions Don't suggest that they add to their `.profile` anymore because: 1. They would have to restart the desktop session for their change to be reflected, or source the file manually; 2. An error in `.profile` may prevent logging in; 3. The `rbenv()` shell function and shell completions won't be available in Terminal since it doesn't start bash in login mode by default. Therefore, suggest that they use `.bashrc` instead. This will be immediately reflected in a new Terminal tab. If bash is started in login mode somehow, the default `.profile` is set up to source `.bashrc` anyway. Also, don't suggest restarting the shell environment with `exec $SHELL -l`, since we don't know what was the original mode that their shell was started in. (OS X Terminal.app will be login mode, Ubuntu Terminal has non-login mode by default.) Mode can be checked with: * bash: `shopt -q login_shell` * zsh: `[[ $options[login] = "on" ]]` But since this is gnarly, let's just avoid it altogether and go the easy route. Closes #305, fixes #373, reverts #286 --- README.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 39267560..656cf49b 100644 --- a/README.md +++ b/README.md @@ -167,7 +167,7 @@ easy to fork and contribute any changes back upstream. $ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile ~~~ - **Ubuntu note**: Modify your `~/.profile` instead of `~/.bash_profile`. + **Ubuntu Desktop note**: Modify your `~/.bashrc` instead of `~/.bash_profile`. **Zsh note**: Modify your `~/.zshrc` file instead of `~/.bash_profile`. @@ -177,13 +177,14 @@ easy to fork and contribute any changes back upstream. $ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile ~~~ - _Same as in previous step, use `~/.profile` on Ubuntu, `~/.zshrc` for Zsh._ + _Same as in previous step, use `~/.bashrc` on Ubuntu, or `~/.zshrc` for Zsh._ -4. Restart your shell as a login shell so the path changes take effect. - You can now begin using rbenv. +4. Restart your shell so that PATH changes take effect. (Opening a new + terminal tab will usually do it.) Now check if rbenv was set up: ~~~ sh - $ exec $SHELL -l + $ type rbenv + #=> "rbenv is a function" ~~~ 5. Install [ruby-build](https://github.com/sstephenson/ruby-build), From 0d216c2d82bbdcc393351b7ce415cc6183f9bdd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Thu, 3 Oct 2013 20:17:10 +0200 Subject: [PATCH 323/384] remove `rbenv install` example; clarify manual compile It can be confusing if people mistake the example as instructions to install ruby-build with. --- README.md | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 656cf49b..23f46ebe 100644 --- a/README.md +++ b/README.md @@ -191,12 +191,8 @@ easy to fork and contribute any changes back upstream. which provides an `rbenv install` command that simplifies the process of installing new Ruby versions. - ~~~ - $ rbenv install 2.0.0-p247 - ~~~ - - As an alternative, you can download and compile Ruby yourself into - `~/.rbenv/versions/`. + If you don't want to do this, you can download and compile Ruby + manually as subdirectories of `~/.rbenv/versions/`. 6. Rebuild the shim executables. You should do this any time you install a new Ruby executable (for example, when installing a new From 16c3e0ddac551d6681a8313fd75afc1fda5e66d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Thu, 3 Oct 2013 20:52:13 +0200 Subject: [PATCH 324/384] tweak installation instructions Provide an `rbenv install` example and explanation lower down, so that both folk that are following git install and Homebrew install will finish at the same section and learn how to use ruby-build. Also remove step 6 of manual install process: `rbenv rehash`. It's unnecessary at that point, even if they already did `rbenv install` (which rehashes automatically). Fixes #455, closes #456 --- README.md | 68 +++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 43 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 23f46ebe..94f1c979 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ bulletproof deployments. **One thing well.** rbenv is concerned solely with switching Ruby versions. It's simple and predictable. A rich plugin ecosystem lets you tailor it to suit your needs. Compile your own Ruby versions, or - use the [ruby-build](https://github.com/sstephenson/ruby-build) + use the [ruby-build][] plugin to automate the process. Specify per-application environment variables with [rbenv-vars](https://github.com/sstephenson/rbenv-vars). See more [plugins on the @@ -43,6 +43,7 @@ RVM?**](https://github.com/sstephenson/rbenv/wiki/Why-rbenv%3F) * [Upgrading](#upgrading) * [Homebrew on Mac OS X](#homebrew-on-mac-os-x) * [Neckbeard Configuration](#neckbeard-configuration) + * [Installing Ruby Versions](#installing-ruby-versions) * [Uninstalling Ruby Versions](#uninstalling-ruby-versions) * [Command Reference](#command-reference) * [rbenv local](#rbenv-local) @@ -187,20 +188,9 @@ easy to fork and contribute any changes back upstream. #=> "rbenv is a function" ~~~ -5. Install [ruby-build](https://github.com/sstephenson/ruby-build), - which provides an `rbenv install` command that simplifies the - process of installing new Ruby versions. - - If you don't want to do this, you can download and compile Ruby - manually as subdirectories of `~/.rbenv/versions/`. - -6. Rebuild the shim executables. You should do this any time you - install a new Ruby executable (for example, when installing a new - Ruby version, or when installing a gem that provides a command). - - ~~~ - $ rbenv rehash - ~~~ +5. _(Optional)_ Install [ruby-build][], which provides the + `rbenv install` command that simplifies the process of + [installing new Ruby versions](#installing-ruby-versions). #### Upgrading @@ -220,20 +210,25 @@ $ git fetch $ git checkout v0.3.0 ~~~ +If you've [installed via Homebrew](#homebrew-on-mac-os-x), then upgrade +via its `brew` command: + +~~~ sh +$ brew update +$ brew upgrade rbenv ruby-build +~~~ + ### Homebrew on Mac OS X -You can also install rbenv using the -[Homebrew](http://brew.sh) package manager on Mac OS -X. +As an alternative to installation via GitHub checkout, you can install +rbenv and [ruby-build][] using the [Homebrew](http://brew.sh) package +manager on Mac OS X: ~~~ $ brew update -$ brew install rbenv -$ brew install ruby-build +$ brew install rbenv ruby-build ~~~ -To later update these installs, use `upgrade` instead of `install`. - Afterwards you'll still need to add `eval "$(rbenv init -)"` to your profile as stated in the caveats. You'll only ever have to do this once. @@ -270,6 +265,27 @@ opposed to this idea. Here's what `rbenv init` actually does: Run `rbenv init -` for yourself to see exactly what happens under the hood. +### Installing Ruby Versions + +The `rbenv install` command doesn't ship with rbenv out of the box, but +is provided by the [ruby-build][] project. If you installed it either +as part of GitHub checkout process outlined above or via Homebrew, you +should be able to: + +~~~ sh +# list all available versions: +$ rbenv install -l + +# install a Ruby version: +$ rbenv install v2.0.0-p247 +~~~ + +Alternatively to the `install` command, you can download and compile +Ruby manually as a subdirectory of `~/.rbenv/versions/`. An entry in +that directory can also be a symlink to a Ruby version installed +elsewhere on the filesystem. rbenv doesn't care; it will simply treat +any entry in the `versions/` directory as a separate Ruby version. + ### Uninstalling Ruby Versions As time goes on, Ruby versions you install will accumulate in your @@ -280,9 +296,8 @@ version you want to remove. You can find the directory of a particular Ruby version with the `rbenv prefix` command, e.g. `rbenv prefix 1.8.7-p357`. -The [ruby-build](https://github.com/sstephenson/ruby-build) plugin -provides an `rbenv uninstall` command to automate the removal -process. +The [ruby-build][] plugin provides an `rbenv uninstall` command to +automate the removal process. ## Command Reference @@ -554,3 +569,6 @@ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + + [ruby-build]: https://github.com/sstephenson/ruby-build#readme From f4fade3d268bf73b5260ffb50175c7beca2f16ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Thu, 3 Oct 2013 21:42:52 +0200 Subject: [PATCH 325/384] better error message for `rbenv prefix system` Have `rbenv prefix` handle the case where system Ruby is not installed, i.e. `rbenv which ruby` doesn't find ruby in PATH. Fixes #362 --- libexec/rbenv-prefix | 12 ++++++++---- test/prefix.bats | 14 ++++++++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/libexec/rbenv-prefix b/libexec/rbenv-prefix index a0aebab2..5376cf5d 100755 --- a/libexec/rbenv-prefix +++ b/libexec/rbenv-prefix @@ -22,10 +22,14 @@ elif [ -z "$RBENV_VERSION" ]; then fi if [ "$RBENV_VERSION" = "system" ]; then - RUBY_PATH="$(rbenv-which ruby)" - RUBY_PATH="${RUBY_PATH%/*}" - echo "${RUBY_PATH%/bin}" - exit + if RUBY_PATH="$(rbenv-which ruby 2>/dev/null)"; then + RUBY_PATH="${RUBY_PATH%/*}" + echo "${RUBY_PATH%/bin}" + exit + else + echo "rbenv: system version not found in PATH" >&2 + exit 1 + fi fi RBENV_PREFIX_PATH="${RBENV_ROOT}/versions/${RBENV_VERSION}" diff --git a/test/prefix.bats b/test/prefix.bats index b7afa87e..0d6cdba6 100644 --- a/test/prefix.bats +++ b/test/prefix.bats @@ -23,3 +23,17 @@ load test_helper RBENV_VERSION="system" run rbenv-prefix assert_success "$RBENV_TEST_DIR" } + +@test "prefix for invalid system" { + USRBIN_ALT="${RBENV_TEST_DIR}/usr-bin-alt" + mkdir -p "$USRBIN_ALT" + for util in head readlink greadlink; do + if [ -x "/usr/bin/$util" ]; then + ln -s "/usr/bin/$util" "${USRBIN_ALT}/$util" + fi + done + PATH_WITHOUT_RUBY="${PATH/\/usr\/bin:/$USRBIN_ALT:}" + + PATH="$PATH_WITHOUT_RUBY" run rbenv-prefix system + assert_failure "rbenv: system version not found in PATH" +} From ff23666d5693b75b637109bdf01497f063ac724a Mon Sep 17 00:00:00 2001 From: Gunes Date: Thu, 3 Oct 2013 23:10:44 +0300 Subject: [PATCH 326/384] typo: remove "v" (version prefix) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 94f1c979..900eb453 100644 --- a/README.md +++ b/README.md @@ -277,7 +277,7 @@ should be able to: $ rbenv install -l # install a Ruby version: -$ rbenv install v2.0.0-p247 +$ rbenv install 2.0.0-p247 ~~~ Alternatively to the `install` command, you can download and compile From 878bd873285706856dfad1e9eafdab58274df876 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Sat, 28 Sep 2013 18:43:39 +0200 Subject: [PATCH 327/384] reliably detect parent shell in `rbenv init` `$SHELL` variable is a terrible way of detecting the current shell because it's not even supposed to reflect the current shell; it's meant for keeping the value of the default shell for programs to start. If an explicit `` argument wasn't passed to `rbenv init`, it tries to detect the shell by getting the name of its parent process. If this fails, it falls back on the value of `$SHELL` as before. Furthermore, `rbenv init` will set the RBENV_SHELL variable in the current shell to the value of the detected shell so that `sh-shell` and `sh-rehash` commands don't have to repeat the detection. --- libexec/rbenv-init | 12 +++++++++++- libexec/rbenv-sh-rehash | 2 +- libexec/rbenv-sh-shell | 2 +- test/init.bats | 19 +++++++++++++------ test/rehash.bats | 4 ++-- test/shell.bats | 12 ++++++------ 6 files changed, 34 insertions(+), 17 deletions(-) diff --git a/libexec/rbenv-init b/libexec/rbenv-init index 22d509bc..29f7512a 100755 --- a/libexec/rbenv-init +++ b/libexec/rbenv-init @@ -22,7 +22,8 @@ done shell="$1" if [ -z "$shell" ]; then - shell="$(basename "$SHELL")" + shell="$(ps c -p $(ps -p $$ -o 'ppid=' 2>/dev/null) -o 'comm=' 2>/dev/null || true)" + shell="$(basename "${shell:-$SHELL}")" fi READLINK=$(type -p greadlink readlink | head -1) @@ -100,6 +101,15 @@ if [[ ":${PATH}:" != *:"${RBENV_ROOT}/shims":* ]]; then esac fi +case "$shell" in +fish ) + echo "setenv RBENV_SHELL $shell" +;; +* ) + echo "export RBENV_SHELL=$shell" +;; +esac + completion="${root}/completions/rbenv.${shell}" if [ -r "$completion" ]; then case "$shell" in diff --git a/libexec/rbenv-sh-rehash b/libexec/rbenv-sh-rehash index 0e1cade1..2fcd3e44 100755 --- a/libexec/rbenv-sh-rehash +++ b/libexec/rbenv-sh-rehash @@ -7,7 +7,7 @@ if [ "$1" = "--complete" ]; then exec rbenv-rehash --complete fi -shell="$(basename "$SHELL")" +shell="$(basename "${RBENV_SHELL:-$SHELL}")" # When rbenv shell integration is enabled, delegate to rbenv-rehash, # then tell the shell to empty its command lookup cache. diff --git a/libexec/rbenv-sh-shell b/libexec/rbenv-sh-shell index d0ffe1b0..f4e0098f 100755 --- a/libexec/rbenv-sh-shell +++ b/libexec/rbenv-sh-shell @@ -24,7 +24,7 @@ if [ "$1" = "--complete" ]; then fi version="$1" -shell="$(basename "$SHELL")" +shell="$(basename "${RBENV_SHELL:-$SHELL}")" if [ -z "$version" ]; then if [ -z "$RBENV_VERSION" ]; then diff --git a/test/init.bats b/test/init.bats index 38771ef9..54086e5f 100644 --- a/test/init.bats +++ b/test/init.bats @@ -19,14 +19,21 @@ load test_helper @test "setup shell completions" { root="$(cd $BATS_TEST_DIRNAME/.. && pwd)" - SHELL=/bin/bash run rbenv-init - + run rbenv-init - bash assert_success assert_line "source '${root}/libexec/../completions/rbenv.bash'" } +@test "detect parent shell" { + root="$(cd $BATS_TEST_DIRNAME/.. && pwd)" + SHELL=/bin/false run rbenv-init - + assert_success + assert_line "export RBENV_SHELL=bash" +} + @test "setup shell completions (fish)" { root="$(cd $BATS_TEST_DIRNAME/.. && pwd)" - SHELL=/usr/bin/fish run rbenv-init - + run rbenv-init - fish assert_success assert_line ". '${root}/libexec/../completions/rbenv.fish'" } @@ -39,28 +46,28 @@ load test_helper @test "adds shims to PATH" { export PATH="${BATS_TEST_DIRNAME}/../libexec:/usr/bin:/bin" - SHELL=/bin/bash run rbenv-init - + run rbenv-init - bash assert_success assert_line 0 'export PATH="'${RBENV_ROOT}'/shims:${PATH}"' } @test "adds shims to PATH (fish)" { export PATH="${BATS_TEST_DIRNAME}/../libexec:/usr/bin:/bin" - SHELL=/usr/bin/fish run rbenv-init - + run rbenv-init - fish assert_success assert_line 0 "setenv PATH '${RBENV_ROOT}/shims' \$PATH" } @test "doesn't add shims to PATH more than once" { export PATH="${RBENV_ROOT}/shims:$PATH" - SHELL=/bin/bash run rbenv-init - + run rbenv-init - bash assert_success refute_line 'export PATH="'${RBENV_ROOT}'/shims:${PATH}"' } @test "doesn't add shims to PATH more than once (fish)" { export PATH="${RBENV_ROOT}/shims:$PATH" - SHELL=/usr/bin/fish run rbenv-init - + run rbenv-init - fish assert_success refute_line 'setenv PATH "'${RBENV_ROOT}'/shims" $PATH ;' } diff --git a/test/rehash.bats b/test/rehash.bats index 97f6cd43..54f0f4a6 100755 --- a/test/rehash.bats +++ b/test/rehash.bats @@ -101,14 +101,14 @@ SH @test "sh-rehash in bash" { create_executable "2.0" "ruby" - SHELL=/bin/bash run rbenv-sh-rehash + RBENV_SHELL=bash run rbenv-sh-rehash assert_success "hash -r 2>/dev/null || true" assert [ -x "${RBENV_ROOT}/shims/ruby" ] } @test "sh-rehash in fish" { create_executable "2.0" "ruby" - SHELL=/usr/bin/fish run rbenv-sh-rehash + RBENV_SHELL=fish run rbenv-sh-rehash assert_success "hash -r 2>/dev/null ; or true" assert [ -x "${RBENV_ROOT}/shims/ruby" ] } diff --git a/test/shell.bats b/test/shell.bats index b14d1cfb..0f776745 100644 --- a/test/shell.bats +++ b/test/shell.bats @@ -11,22 +11,22 @@ load test_helper } @test "shell version" { - SHELL=/bin/bash RBENV_VERSION="1.2.3" run rbenv-sh-shell + RBENV_SHELL=bash RBENV_VERSION="1.2.3" run rbenv-sh-shell assert_success 'echo "$RBENV_VERSION"' } @test "shell version (fish)" { - SHELL=/usr/bin/fish RBENV_VERSION="1.2.3" run rbenv-sh-shell + RBENV_SHELL=fish RBENV_VERSION="1.2.3" run rbenv-sh-shell assert_success 'echo "$RBENV_VERSION"' } @test "shell unset" { - SHELL=/bin/bash run rbenv-sh-shell --unset + RBENV_SHELL=bash run rbenv-sh-shell --unset assert_success "unset RBENV_VERSION" } @test "shell unset (fish)" { - SHELL=/usr/bin/fish run rbenv-sh-shell --unset + RBENV_SHELL=fish run rbenv-sh-shell --unset assert_success "set -e RBENV_VERSION" } @@ -41,12 +41,12 @@ SH @test "shell change version" { mkdir -p "${RBENV_ROOT}/versions/1.2.3" - SHELL=/bin/bash run rbenv-sh-shell 1.2.3 + RBENV_SHELL=bash run rbenv-sh-shell 1.2.3 assert_success 'export RBENV_VERSION="1.2.3"' } @test "shell change version (fish)" { mkdir -p "${RBENV_ROOT}/versions/1.2.3" - SHELL=/usr/bin/fish run rbenv-sh-shell 1.2.3 + RBENV_SHELL=fish run rbenv-sh-shell 1.2.3 assert_success 'setenv RBENV_VERSION "1.2.3"' } From 3300587c6bef99f6504f4bacb147e5d9ab315e98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Mon, 7 Oct 2013 14:18:36 +0200 Subject: [PATCH 328/384] strip initial `-` from the name of shell process Avoids the case where shell detection would result in `basename "-bash"` invocation, triggering the error: basename: illegal option -- b fixes #462 --- libexec/rbenv-init | 1 + 1 file changed, 1 insertion(+) diff --git a/libexec/rbenv-init b/libexec/rbenv-init index 29f7512a..dcb1bd5a 100755 --- a/libexec/rbenv-init +++ b/libexec/rbenv-init @@ -23,6 +23,7 @@ done shell="$1" if [ -z "$shell" ]; then shell="$(ps c -p $(ps -p $$ -o 'ppid=' 2>/dev/null) -o 'comm=' 2>/dev/null || true)" + shell="${shell##-}" shell="$(basename "${shell:-$SHELL}")" fi From d2eace00c9bd28134d3a3c2239b0d17b62e13e23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Wed, 30 Oct 2013 02:33:23 +0100 Subject: [PATCH 329/384] Add more tests for version-file-read --- test/version-file-read.bats | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/test/version-file-read.bats b/test/version-file-read.bats index 8002388d..66bd46fa 100644 --- a/test/version-file-read.bats +++ b/test/version-file-read.bats @@ -17,12 +17,24 @@ setup() { assert_failure "" } +@test "fails for blank file" { + echo > my-version + run rbenv-version-file-read my-version + assert_failure "" +} + @test "reads simple version file" { cat > my-version <<<"1.9.3" run rbenv-version-file-read my-version assert_success "1.9.3" } +@test "ignores leading spaces" { + cat > my-version <<<" 1.9.3" + run rbenv-version-file-read my-version + assert_success "1.9.3" +} + @test "reads only the first word from file" { cat > my-version <<<"1.9.3-p194@tag 1.8.7 hi" run rbenv-version-file-read my-version @@ -37,3 +49,18 @@ IN run rbenv-version-file-read my-version assert_success "1.8.7" } + +@test "ignores leading blank lines" { + cat > my-version < my-version + run rbenv-version-file-read my-version + assert_success "1.8.7" +} From 681435e0b4a0d3f9609a11af734902312eabaeaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Wed, 30 Oct 2013 02:33:49 +0100 Subject: [PATCH 330/384] Simplify version-file-read to avoid process substitution Process substitution seems to be causing problems with some versions of bash on specific systems. Fixes #401 --- libexec/rbenv-version-file-read | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/libexec/rbenv-version-file-read b/libexec/rbenv-version-file-read index 69ec78b9..5a1d7a3f 100755 --- a/libexec/rbenv-version-file-read +++ b/libexec/rbenv-version-file-read @@ -8,13 +8,8 @@ VERSION_FILE="$1" if [ -e "$VERSION_FILE" ]; then # Read the first non-whitespace word from the specified version file. # Be careful not to load it whole in case there's something crazy in it. - version="" - while read -a words; do - word="${words[0]}" - if [ -z "$version" ] && [ -n "$word" ]; then - version="$word" - fi - done < <( cat "$VERSION_FILE" && echo ) + words=( $(head -c 1024 "$VERSION_FILE") ) + version="${words[0]}" if [ -n "$version" ]; then echo "$version" From f1fdb9bbc8d25f51cccd039305e5517684463899 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Thu, 31 Oct 2013 20:16:26 +0200 Subject: [PATCH 331/384] Avoid invoking `hash -r` in fish It doesn't exist as a builtin, and it doesn't seem there is a way to detect support for a shell builtin that is portable. So, just detect fish and don't the rehash command at all. Fixes #478 --- libexec/rbenv-sh-rehash | 6 ++---- test/rehash.bats | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/libexec/rbenv-sh-rehash b/libexec/rbenv-sh-rehash index 2fcd3e44..a81dae7f 100755 --- a/libexec/rbenv-sh-rehash +++ b/libexec/rbenv-sh-rehash @@ -15,11 +15,9 @@ rbenv-rehash case "$shell" in fish ) - or='; or' + # no rehash support ;; * ) - or='||' + echo "hash -r 2>/dev/null || true" ;; esac - -echo "hash -r 2>/dev/null $or true" diff --git a/test/rehash.bats b/test/rehash.bats index 54f0f4a6..ba12a245 100755 --- a/test/rehash.bats +++ b/test/rehash.bats @@ -109,6 +109,6 @@ SH @test "sh-rehash in fish" { create_executable "2.0" "ruby" RBENV_SHELL=fish run rbenv-sh-rehash - assert_success "hash -r 2>/dev/null ; or true" + assert_success "" assert [ -x "${RBENV_ROOT}/shims/ruby" ] } From 95a039aaaa3855ea2df4855ad38c06faaba01f9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Sun, 3 Nov 2013 12:18:28 +0200 Subject: [PATCH 332/384] Revert "rbenv exec: avoid mutating PATH" It was supposed to fix shelling out to Ruby but it in fact broke another kind of shelling out to Ruby: invoking the `ruby` binary directly with the `-S` flag. Fixes #480 This reverts commit db143bb654fe447a462b0d91ba931e0524f234f7. --- libexec/rbenv-exec | 64 +++--------- libexec/rbenv-rehash | 4 +- test/exec.bats | 244 ++++--------------------------------------- 3 files changed, 37 insertions(+), 275 deletions(-) diff --git a/libexec/rbenv-exec b/libexec/rbenv-exec index f3908f8d..a9309d0e 100755 --- a/libexec/rbenv-exec +++ b/libexec/rbenv-exec @@ -2,59 +2,24 @@ # # Summary: Run an executable with the selected Ruby version # -# Usage: rbenv exec [args...] +# Usage: rbenv exec [arg1 arg2...] # -# Runs an executable contained by the currently selected Ruby's bin -# directory. Rough equivalent of: +# Runs an executable by first preparing PATH so that the selected Ruby +# version's `bin' directory is at the front. # -# exec "$(rbenv prefix)/bin/$command" args... +# For example, if the currently selected Ruby version is 1.9.3-p327: +# rbenv exec bundle install +# +# is equivalent to: +# PATH="$RBENV_ROOT/versions/1.9.3-p327/bin:$PATH" bundle install set -e [ -n "$RBENV_DEBUG" ] && set -x -rubypath="" # Provide rbenv completions -while true; do - case "$1" in - "--complete" ) - exec rbenv shims --short - ;; - "--rubypath" ) - rubypath=1 - shift 1 - ;; - * ) - break - ;; - esac -done - -# Replace any "RBENV_ROOT/shims" or "RBENV_ROOT/versions/*/bin" paths in the -# list with the given path. If no replacements were made, prepend the path onto -# the list. -replace_shims_path() { - local path="$1" - local dir="$2" - # fake directory that serves as a placeholder for shims location in RUBYPATH: - local placeholder="/rbenv_shims_were_here" - local found="" - local result="" - local -a paths - IFS=: paths=($path) - - for path in "${paths[@]}"; do - if [[ $path = "${RBENV_ROOT}/shims" || $path == "${RBENV_ROOT}/versions/"*/bin || $path = $placeholder ]]; then - found=1 - result="${result}${dir:-$placeholder}:" - else - result="${result}${path}:" - fi - done - - # if no rbenv paths were replaced, simply prepend the path - [ -n "$found" -o -z "$dir" ] || result="${dir}:${path}" - echo "${result%:}" -} +if [ "$1" = "--complete" ]; then + exec rbenv shims --short +fi RBENV_VERSION="$(rbenv-version-name)" RBENV_COMMAND="$1" @@ -66,6 +31,7 @@ fi export RBENV_VERSION RBENV_COMMAND_PATH="$(rbenv-which "$RBENV_COMMAND")" +RBENV_BIN_PATH="${RBENV_COMMAND_PATH%/*}" OLDIFS="$IFS" IFS=$'\n' scripts=(`rbenv-hooks exec`) @@ -75,9 +41,7 @@ for script in "${scripts[@]}"; do done shift 1 -if [ -n "$rubypath" ]; then - bindir="" - [ "$RBENV_VERSION" != "system" ] && bindir="${RBENV_COMMAND_PATH%/*}" - export RUBYPATH="$(replace_shims_path "${RUBYPATH:-$PATH}" "$bindir")" +if [ "$RBENV_VERSION" != "system" ]; then + export PATH="${RBENV_BIN_PATH}:${PATH}" fi exec -a "$RBENV_COMMAND" "$RBENV_COMMAND_PATH" "$@" diff --git a/libexec/rbenv-rehash b/libexec/rbenv-rehash index 4bcc944d..5ec195ec 100755 --- a/libexec/rbenv-rehash +++ b/libexec/rbenv-rehash @@ -45,12 +45,10 @@ create_prototype_shim() { set -e [ -n "\$RBENV_DEBUG" ] && set -x -opt="" program="\${0##*/}" if [ "\$program" = "ruby" ]; then for arg; do case "\$arg" in - -S* ) opt=--rubypath ;; -e* | -- ) break ;; */* ) if [ -f "\$arg" ]; then @@ -63,7 +61,7 @@ if [ "\$program" = "ruby" ]; then fi export RBENV_ROOT="$RBENV_ROOT" -exec "$(command -v rbenv)" exec \$opt "\$program" "\$@" +exec "$(command -v rbenv)" exec "\$program" "\$@" SH chmod +x "$PROTOTYPE_SHIM_PATH" } diff --git a/test/exec.bats b/test/exec.bats index f82a42ef..889eb897 100644 --- a/test/exec.bats +++ b/test/exec.bats @@ -3,37 +3,15 @@ load test_helper create_executable() { - local file="${1?}" - [[ $file == */* ]] || file="${RBENV_ROOT}/versions/${RBENV_VERSION}/bin/$file" + name="${1?}" shift 1 - mkdir -p "${file%/*}" + bin="${RBENV_ROOT}/versions/${RBENV_VERSION}/bin" + mkdir -p "$bin" { if [ $# -eq 0 ]; then cat - else echo "$@" fi - } | sed -Ee '1s/^[[:space:]]+//' > "$file" - chmod +x "$file" -} - -# Fake ruby executable that emulates `ruby -S ' behavior by running the -# first `cmd' found in RUBYPATH/PATH as bash script. -create_ruby_executable() { - create_executable "${1:-ruby}" </dev/null; then - \$BASH "\$found" - else - echo "ruby: no Ruby script found in input (LoadError)" >&2 - exit 1 - fi -else - echo 'ruby (rbenv test)' -fi -SH + } | sed -Ee '1s/^ +//' > "${bin}/$name" + chmod +x "${bin}/$name" } @test "fails with invalid version" { @@ -104,56 +82,26 @@ ${RBENV_ROOT}/versions/2.0/bin/ruby OUT } -@test "doesn't mutate PATH" { - export RBENV_VERSION="2.0" - create_executable "ruby" <" { export RBENV_VERSION="2.0" - create_ruby_executable + # emulate `ruby -S' behavior + create_executable "ruby" </dev/null; then + \$BASH "\$found" + else + echo "ruby: no Ruby script found in input (LoadError)" >&2 + exit 1 + fi +else + echo 'ruby 2.0 (rbenv test)' +fi +SH + create_executable "rake" < Date: Mon, 25 Nov 2013 11:59:23 +0800 Subject: [PATCH 333/384] ignore cache directory used by ruby-build --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index a615996c..cfcaaa17 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ /version /versions /sources +/cache From be5e1a4ded1d0634bb73de6d4ba424da390c7837 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Fri, 6 Dec 2013 16:45:22 +0100 Subject: [PATCH 334/384] Improve `rbenv init` instructions for fish Fish user config file `~/.config/fish/config.fish` loads for every instance of fish shell, not just interactive ones. Since it's unnecessary and dangerous to eval `rbenv init -` output in non-interactive shells, wrap the invocation in a conditional that checks if the current shell is interactive. Fixes #501 --- libexec/rbenv-init | 2 +- test/init.bats | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/libexec/rbenv-init b/libexec/rbenv-init index dcb1bd5a..a3292d66 100755 --- a/libexec/rbenv-init +++ b/libexec/rbenv-init @@ -77,7 +77,7 @@ if [ -z "$print" ]; then echo case "$shell" in fish ) - echo '. (rbenv init -|psub)' + echo 'status --is-interactive; and . (rbenv init -|psub)' ;; * ) echo 'eval "$(rbenv init -)"' diff --git a/test/init.bats b/test/init.bats index 54086e5f..61b30be7 100644 --- a/test/init.bats +++ b/test/init.bats @@ -38,6 +38,12 @@ load test_helper assert_line ". '${root}/libexec/../completions/rbenv.fish'" } +@test "fish instructions" { + run rbenv-init fish + assert [ "$status" -eq 1 ] + assert_line 'status --is-interactive; and . (rbenv init -|psub)' +} + @test "option to skip rehash" { run rbenv-init - --no-rehash assert_success From 590b19a1b170c890d0e2c2934dcde06fe154613d Mon Sep 17 00:00:00 2001 From: Jonathan Dean Date: Fri, 13 Dec 2013 14:06:44 -0500 Subject: [PATCH 335/384] Remove Neckbeard reference in favor of Advanced --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 900eb453..239c1f9b 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ RVM?**](https://github.com/sstephenson/rbenv/wiki/Why-rbenv%3F) * [Basic GitHub Checkout](#basic-github-checkout) * [Upgrading](#upgrading) * [Homebrew on Mac OS X](#homebrew-on-mac-os-x) - * [Neckbeard Configuration](#neckbeard-configuration) + * [Advanced Configuration](#advanced-configuration) * [Installing Ruby Versions](#installing-ruby-versions) * [Uninstalling Ruby Versions](#uninstalling-ruby-versions) * [Command Reference](#command-reference) @@ -233,7 +233,7 @@ Afterwards you'll still need to add `eval "$(rbenv init -)"` to your profile as stated in the caveats. You'll only ever have to do this once. -### Neckbeard Configuration +### Advanced Configuration Skip this section unless you must know what every line in your shell profile is doing. From 09ec276a85ed8afdee910bd9458ad66630646a58 Mon Sep 17 00:00:00 2001 From: Jonathan Dean Date: Sat, 14 Dec 2013 16:38:25 -0500 Subject: [PATCH 336/384] Change 'Advanced Configuration' reference to 'How rbenv hooks into your shell' --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 239c1f9b..7999645f 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ RVM?**](https://github.com/sstephenson/rbenv/wiki/Why-rbenv%3F) * [Basic GitHub Checkout](#basic-github-checkout) * [Upgrading](#upgrading) * [Homebrew on Mac OS X](#homebrew-on-mac-os-x) - * [Advanced Configuration](#advanced-configuration) + * [How rbenv hooks into your shell](#how-rbenv-hooks-into-your-shell) * [Installing Ruby Versions](#installing-ruby-versions) * [Uninstalling Ruby Versions](#uninstalling-ruby-versions) * [Command Reference](#command-reference) @@ -233,7 +233,7 @@ Afterwards you'll still need to add `eval "$(rbenv init -)"` to your profile as stated in the caveats. You'll only ever have to do this once. -### Advanced Configuration +### How rbenv hooks into your shell Skip this section unless you must know what every line in your shell profile is doing. From 4f2f6f8575c75b8feb1a527168431817b9b6a7e4 Mon Sep 17 00:00:00 2001 From: Jeffrey 'jf' Lim Date: Wed, 25 Dec 2013 09:09:49 +0800 Subject: [PATCH 337/384] Fix test suite when no system Ruby exists Some tests assumed that the `ruby` executable will be found in system PATH. Fixes #512, closes #514 --- test/versions.bats | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/versions.bats b/test/versions.bats index 11acdfc8..9554c154 100644 --- a/test/versions.bats +++ b/test/versions.bats @@ -11,7 +11,14 @@ setup() { cd "$RBENV_TEST_DIR" } +stub_system_ruby() { + local stub="${RBENV_TEST_DIR}/bin/ruby" + mkdir -p "$(dirname "$stub")" + touch "$stub" && chmod +x "$stub" +} + @test "no versions installed" { + stub_system_ruby assert [ ! -d "${RBENV_ROOT}/versions" ] run rbenv-versions assert_success "* system (set by ${RBENV_ROOT}/version)" @@ -24,6 +31,7 @@ setup() { } @test "single version installed" { + stub_system_ruby create_version "1.9" run rbenv-versions assert_success @@ -40,6 +48,7 @@ OUT } @test "multiple versions" { + stub_system_ruby create_version "1.8.7" create_version "1.9.3" create_version "2.0.0" @@ -54,6 +63,7 @@ OUT } @test "indicates current version" { + stub_system_ruby create_version "1.9.3" create_version "2.0.0" RBENV_VERSION=1.9.3 run rbenv-versions @@ -77,6 +87,7 @@ OUT } @test "globally selected version" { + stub_system_ruby create_version "1.9.3" create_version "2.0.0" cat > "${RBENV_ROOT}/version" <<<"1.9.3" @@ -90,6 +101,7 @@ OUT } @test "per-project version" { + stub_system_ruby create_version "1.9.3" create_version "2.0.0" cat > ".ruby-version" <<<"1.9.3" From 783618b89cb80b74f1daf03679081dd1233f49eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Wed, 25 Dec 2013 18:10:20 +0100 Subject: [PATCH 338/384] Force TAP output from Bats on CI In Travis CI environment, Bats thinks it's outputting to an interactive terminal, so it switches to "pretty" format and ANSI escape codes which don't look well in the final output. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 4498f8e5..ca1abab7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,4 @@ install: git clone https://github.com/sstephenson/bats.git -script: bats/bin/bats test +script: bats/bin/bats --tap test # skips unnecessary Ruby-specific setup language: c From 2f5d9a6f90d8fc0de9c5b07fc10c4203670126db Mon Sep 17 00:00:00 2001 From: wmoxam Date: Tue, 31 Dec 2013 01:44:36 -0500 Subject: [PATCH 339/384] Fixes rbenv on OpenBSD and any other systems that don't support head -c --- libexec/rbenv-version-file-read | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libexec/rbenv-version-file-read b/libexec/rbenv-version-file-read index 5a1d7a3f..cde0ca75 100755 --- a/libexec/rbenv-version-file-read +++ b/libexec/rbenv-version-file-read @@ -8,7 +8,7 @@ VERSION_FILE="$1" if [ -e "$VERSION_FILE" ]; then # Read the first non-whitespace word from the specified version file. # Be careful not to load it whole in case there's something crazy in it. - words=( $(head -c 1024 "$VERSION_FILE") ) + words=( $(cut -b 1-1024 "$VERSION_FILE") ) version="${words[0]}" if [ -n "$version" ]; then From 3dc0005032f04d40001cf0542d2b3d154dc2dc11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Thu, 2 Jan 2014 22:17:38 +0100 Subject: [PATCH 340/384] Fix test suite running on OpenBSD The error was "bash: no such file or directory" and it was due to bash being located in `/usr/local/bin` on OpenBSD 5.4 instead of `/bin` like on other systems. Fixed by keeping `/usr/local/bin` in PATH during the test run. --- test/init.bats | 4 ++-- test/test_helper.bash | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/init.bats b/test/init.bats index 61b30be7..60a3328c 100644 --- a/test/init.bats +++ b/test/init.bats @@ -51,14 +51,14 @@ load test_helper } @test "adds shims to PATH" { - export PATH="${BATS_TEST_DIRNAME}/../libexec:/usr/bin:/bin" + export PATH="${BATS_TEST_DIRNAME}/../libexec:/usr/bin:/bin:/usr/local/bin" run rbenv-init - bash assert_success assert_line 0 'export PATH="'${RBENV_ROOT}'/shims:${PATH}"' } @test "adds shims to PATH (fish)" { - export PATH="${BATS_TEST_DIRNAME}/../libexec:/usr/bin:/bin" + export PATH="${BATS_TEST_DIRNAME}/../libexec:/usr/bin:/bin:/usr/local/bin" run rbenv-init - fish assert_success assert_line 0 "setenv PATH '${RBENV_ROOT}/shims' \$PATH" diff --git a/test/test_helper.bash b/test/test_helper.bash index 01d9fb99..43b04d3b 100644 --- a/test/test_helper.bash +++ b/test/test_helper.bash @@ -8,7 +8,7 @@ if [ "$RBENV_ROOT" != "${RBENV_TEST_DIR}/root" ]; then export RBENV_ROOT="${RBENV_TEST_DIR}/root" export HOME="${RBENV_TEST_DIR}/home" - PATH=/usr/bin:/bin:/usr/sbin:/sbin + PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin PATH="${RBENV_TEST_DIR}/bin:$PATH" PATH="${BATS_TEST_DIRNAME}/../libexec:$PATH" PATH="${BATS_TEST_DIRNAME}/libexec:$PATH" From 1e1c9cb0dcecf7a4c5126bcd3545967e07429173 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Thu, 2 Jan 2014 22:30:21 +0100 Subject: [PATCH 341/384] Fix emulating the scenario where system Ruby is missing on OpenBSD On other systems, we expected to find system Ruby in `/usr/bin`, but in OpenBSD 5.4 it will be found in `/usr/local/bin`. This replaces the limited USRBIN_ALT hack with a more generic `path_without` function that will ensure that the given executable is not present in the resulting PATH even if it's found in multiple system paths. --- test/prefix.bats | 11 +---------- test/test_helper.bash | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/test/prefix.bats b/test/prefix.bats index 0d6cdba6..3fb94086 100644 --- a/test/prefix.bats +++ b/test/prefix.bats @@ -25,15 +25,6 @@ load test_helper } @test "prefix for invalid system" { - USRBIN_ALT="${RBENV_TEST_DIR}/usr-bin-alt" - mkdir -p "$USRBIN_ALT" - for util in head readlink greadlink; do - if [ -x "/usr/bin/$util" ]; then - ln -s "/usr/bin/$util" "${USRBIN_ALT}/$util" - fi - done - PATH_WITHOUT_RUBY="${PATH/\/usr\/bin:/$USRBIN_ALT:}" - - PATH="$PATH_WITHOUT_RUBY" run rbenv-prefix system + PATH="$(path_without ruby)" run rbenv-prefix system assert_failure "rbenv: system version not found in PATH" } diff --git a/test/test_helper.bash b/test/test_helper.bash index 43b04d3b..53ae8e64 100644 --- a/test/test_helper.bash +++ b/test/test_helper.bash @@ -93,3 +93,25 @@ assert() { flunk "failed: $@" fi } + +# Output a modified PATH that ensures that the given executable is not present, +# but in which system utils necessary for rbenv operation are still available. +path_without() { + local exe="$1" + local path="${PATH}:" + local found alt util + for found in $(which -a "$exe"); do + found="${found%/*}" + if [ "$found" != "${RBENV_ROOT}/shims" ]; then + alt="${RBENV_TEST_DIR}/$(echo "${found#/}" | tr '/' '-')" + mkdir -p "$alt" + for util in bash head cut readlink greadlink; do + if [ -x "${found}/$util" ]; then + ln -s "${found}/$util" "${alt}/$util" + fi + done + path="${path/${found}:/${alt}:}" + fi + done + echo "${path%:}" +} From eda535a9423dfe39cd90197c1c4150bc1da392b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Thu, 2 Jan 2014 22:33:54 +0100 Subject: [PATCH 342/384] Fix detecting completions support on OpenBSD The non-extended regex pattern didn't work on OpenBSD so this switches grep to extended pattern mode that seems to work consistenty on all systems. --- libexec/rbenv-completions | 2 +- test/completions.bats | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libexec/rbenv-completions b/libexec/rbenv-completions index 6de09ed2..196212e4 100755 --- a/libexec/rbenv-completions +++ b/libexec/rbenv-completions @@ -11,7 +11,7 @@ if [ -z "$COMMAND" ]; then fi COMMAND_PATH="$(command -v "rbenv-$COMMAND" || command -v "rbenv-sh-$COMMAND")" -if grep -i "^\([#%]\|--\|//\) provide rbenv completions" "$COMMAND_PATH" >/dev/null; then +if grep -iE "^([#%]|--|//) provide rbenv completions" "$COMMAND_PATH" >/dev/null; then shift exec "$COMMAND_PATH" --complete "$@" fi diff --git a/test/completions.bats b/test/completions.bats index 0feccfa9..9091f082 100644 --- a/test/completions.bats +++ b/test/completions.bats @@ -18,7 +18,7 @@ create_command() { @test "command with completion support" { create_command "rbenv-hello" "#!$BASH -# provide rbenv completions +# Provide rbenv completions if [[ \$1 = --complete ]]; then echo hello else From 1a6bada94cad7605188daafca8106a975c193979 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Thu, 2 Jan 2014 22:36:03 +0100 Subject: [PATCH 343/384] Fix detecting parent shell on OpenBSD and Cygwin It seems that "comm" header can't be relied on cross-platform, but that "ucomm" is more portable. I have no idea whether it's the right value to use here, but it seems to be doing the job. Also strip trailing whitespace because OpenBSD 5.4 `ps` output is padded with spaces for some reason. Fixes #489 --- libexec/rbenv-init | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libexec/rbenv-init b/libexec/rbenv-init index a3292d66..a28b7fc4 100755 --- a/libexec/rbenv-init +++ b/libexec/rbenv-init @@ -22,8 +22,9 @@ done shell="$1" if [ -z "$shell" ]; then - shell="$(ps c -p $(ps -p $$ -o 'ppid=' 2>/dev/null) -o 'comm=' 2>/dev/null || true)" + shell="$(ps c -p "$PPID" -o 'ucomm=' 2>/dev/null || true)" shell="${shell##-}" + shell="${shell%% *}" shell="$(basename "${shell:-$SHELL}")" fi From 2fd3b18d39bc319a5022ca3e62e51d474ff33a4c Mon Sep 17 00:00:00 2001 From: Vincent Robert Date: Thu, 20 Mar 2014 11:30:27 +0100 Subject: [PATCH 344/384] Remove carriage return characters in version file When created on Windows, .rbenv-version or .ruby-version files may have CR characters that will prevent rbenv from correctly parsing the Ruby version. Discard those characters when reading the file. --- libexec/rbenv-version-file-read | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libexec/rbenv-version-file-read b/libexec/rbenv-version-file-read index cde0ca75..9385ab1e 100755 --- a/libexec/rbenv-version-file-read +++ b/libexec/rbenv-version-file-read @@ -9,7 +9,7 @@ if [ -e "$VERSION_FILE" ]; then # Read the first non-whitespace word from the specified version file. # Be careful not to load it whole in case there's something crazy in it. words=( $(cut -b 1-1024 "$VERSION_FILE") ) - version="${words[0]}" + version="${words[0]//[$'\r']}" if [ -n "$version" ]; then echo "$version" From 3be9773c4f8180c9902403af4331e3ef64b94539 Mon Sep 17 00:00:00 2001 From: Vincent Robert Date: Thu, 20 Mar 2014 16:27:13 +0100 Subject: [PATCH 345/384] Add test for carriage return in ruby-version file --- test/version.bats | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/version.bats b/test/version.bats index 886d0efa..1fb97c70 100644 --- a/test/version.bats +++ b/test/version.bats @@ -30,6 +30,13 @@ setup() { assert_success "1.9.3 (set by ${PWD}/.ruby-version)" } +@test "set by local file containing CR" { + create_version "1.9.3" + cat > ".ruby-version" <<< $'1.9.3\r' + run rbenv-version + assert_success "1.9.3 (set by ${PWD}/.ruby-version)" +} + @test "set by global file" { create_version "1.9.3" cat > "${RBENV_ROOT}/version" <<<"1.9.3" From f50cee2ac7cc1adbe6849a72865b99f9cc0a2da3 Mon Sep 17 00:00:00 2001 From: Vincent Robert Date: Thu, 20 Mar 2014 16:52:45 +0100 Subject: [PATCH 346/384] Simplify bash expression --- libexec/rbenv-version-file-read | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libexec/rbenv-version-file-read b/libexec/rbenv-version-file-read index 9385ab1e..521a6cf9 100755 --- a/libexec/rbenv-version-file-read +++ b/libexec/rbenv-version-file-read @@ -9,7 +9,7 @@ if [ -e "$VERSION_FILE" ]; then # Read the first non-whitespace word from the specified version file. # Be careful not to load it whole in case there's something crazy in it. words=( $(cut -b 1-1024 "$VERSION_FILE") ) - version="${words[0]//[$'\r']}" + version="${words[0]//$'\r'}" if [ -n "$version" ]; then echo "$version" From f205ec83592aa5a6f61a720ba5ee5cb950790b97 Mon Sep 17 00:00:00 2001 From: Vincent Robert Date: Fri, 21 Mar 2014 01:32:29 +0100 Subject: [PATCH 347/384] Move carriage return test to version-file-read --- test/version-file-read.bats | 6 ++++++ test/version.bats | 7 ------- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/test/version-file-read.bats b/test/version-file-read.bats index 66bd46fa..bf7bf910 100644 --- a/test/version-file-read.bats +++ b/test/version-file-read.bats @@ -64,3 +64,9 @@ IN run rbenv-version-file-read my-version assert_success "1.8.7" } + +@test "ignores carriage returns" { + cat > my-version <<< $'1.9.3\r' + run rbenv-version-file-read my-version + assert_success "1.9.3" +} diff --git a/test/version.bats b/test/version.bats index 1fb97c70..886d0efa 100644 --- a/test/version.bats +++ b/test/version.bats @@ -30,13 +30,6 @@ setup() { assert_success "1.9.3 (set by ${PWD}/.ruby-version)" } -@test "set by local file containing CR" { - create_version "1.9.3" - cat > ".ruby-version" <<< $'1.9.3\r' - run rbenv-version - assert_success "1.9.3 (set by ${PWD}/.ruby-version)" -} - @test "set by global file" { create_version "1.9.3" cat > "${RBENV_ROOT}/version" <<<"1.9.3" From b025dfcf585abc2528028c0d0c360048eeb13b21 Mon Sep 17 00:00:00 2001 From: Vincent Robert Date: Fri, 21 Mar 2014 01:36:39 +0100 Subject: [PATCH 348/384] Add \r to IFS instead of removing it manually --- libexec/rbenv-version-file-read | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libexec/rbenv-version-file-read b/libexec/rbenv-version-file-read index 521a6cf9..03d2db0c 100755 --- a/libexec/rbenv-version-file-read +++ b/libexec/rbenv-version-file-read @@ -8,8 +8,9 @@ VERSION_FILE="$1" if [ -e "$VERSION_FILE" ]; then # Read the first non-whitespace word from the specified version file. # Be careful not to load it whole in case there's something crazy in it. + IFS="${IFS}"$'\r' words=( $(cut -b 1-1024 "$VERSION_FILE") ) - version="${words[0]//$'\r'}" + version="${words[0]}" if [ -n "$version" ]; then echo "$version" From 808527b5d0c40b83d289773460d1e53c6bc0f52a Mon Sep 17 00:00:00 2001 From: Adam Harvey Date: Fri, 18 Apr 2014 10:39:29 +1000 Subject: [PATCH 349/384] Prefer gawk over awk if both are available. --- libexec/rbenv-help | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libexec/rbenv-help b/libexec/rbenv-help index f15e83fd..9a3049aa 100755 --- a/libexec/rbenv-help +++ b/libexec/rbenv-help @@ -36,7 +36,7 @@ extract_initial_comment_block() { } collect_documentation() { - awk ' + $(type -p gawk awk | head -1) ' /^Summary:/ { summary = substr($0, 10) next From 13a474c4e9c3305179b364723349fc49b3e935e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Tue, 3 Jun 2014 00:36:49 +0700 Subject: [PATCH 350/384] Get rid of explicit exit in fish branch of `rbenv-init` Allows for code to be added to the end of the script which will not mysteriously fail to run for fish shell. --- libexec/rbenv-init | 3 ++- test/init.bats | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/libexec/rbenv-init b/libexec/rbenv-init index a28b7fc4..5f9079a7 100755 --- a/libexec/rbenv-init +++ b/libexec/rbenv-init @@ -140,7 +140,6 @@ function rbenv end end EOS - exit 0 ;; ksh ) cat < Date: Mon, 13 Oct 2014 04:02:04 +0200 Subject: [PATCH 351/384] Have `versions` emit a warning when no Ruby version was found --- libexec/rbenv-versions | 10 ++++++++++ test/versions.bats | 6 ++++++ 2 files changed, 16 insertions(+) diff --git a/libexec/rbenv-versions b/libexec/rbenv-versions index ea28e5cd..b35cef48 100755 --- a/libexec/rbenv-versions +++ b/libexec/rbenv-versions @@ -19,12 +19,15 @@ else include_system="1" fi +num_versions=0 + print_version() { if [ "$1" == "$current_version" ]; then echo "${hit_prefix}$(rbenv-version 2>/dev/null)" else echo "${miss_prefix}$1" fi + num_versions=$((num_versions + 1)) } # Include "system" in the non-bare output, if it exists @@ -32,8 +35,15 @@ if [ -n "$include_system" ] && RBENV_VERSION=system rbenv-which ruby >/dev/null print_version system fi +shopt -s nullglob for path in "${RBENV_ROOT}/versions/"*; do if [ -d "$path" ]; then print_version "${path##*/}" fi done +shopt -u nullglob + +if [ "$num_versions" -eq 0 ] && [ -n "$include_system" ]; then + echo "Warning: no Ruby detected on the system" >&2 + exit 1 +fi diff --git a/test/versions.bats b/test/versions.bats index 9554c154..56a2aa33 100644 --- a/test/versions.bats +++ b/test/versions.bats @@ -24,6 +24,12 @@ stub_system_ruby() { assert_success "* system (set by ${RBENV_ROOT}/version)" } +@test "not even system ruby available" { + PATH="$(path_without ruby)" run rbenv-versions + assert_failure + assert_output "Warning: no Ruby detected on the system" +} + @test "bare output no versions installed" { assert [ ! -d "${RBENV_ROOT}/versions" ] run rbenv-versions --bare From 9bcef4b8759b54edee5413500f24f60be28499b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Mon, 13 Oct 2014 04:02:46 +0200 Subject: [PATCH 352/384] Add tests for non-directory types under `RBENV_ROOT/versions/` --- test/versions.bats | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/test/versions.bats b/test/versions.bats index 56a2aa33..5d79ed5a 100644 --- a/test/versions.bats +++ b/test/versions.bats @@ -119,3 +119,23 @@ OUT 2.0.0 OUT } + +@test "ignores non-directories under versions" { + create_version "1.9" + touch "${RBENV_ROOT}/versions/hello" + + run rbenv-versions --bare + assert_success "1.9" +} + +@test "lists symlinks under versions" { + create_version "1.8.7" + ln -s "1.8.7" "${RBENV_ROOT}/versions/1.8" + + run rbenv-versions --bare + assert_success + assert_output < Date: Fri, 3 Jan 2014 21:25:18 +0100 Subject: [PATCH 353/384] Speed up `realpath()` with dynamically loaded C extension On systems that support both C compiling and dynamic loading, we can speed up `realpath()` (where most time in rbenv is spent) by replacing it with a dynamically loaded bash builtin. When `make -C src` is called in the project's root, `libexec/rbenv-realpath.dylib` will be created. If it exists, rbenv will attempt to load it as a builtin command. If it fails, execution will fall back to the old `realpath()` shell function. --- .gitignore | 2 ++ libexec/rbenv-hooks | 4 +++- src/Makefile | 10 ++++++++++ src/bash.h | 31 +++++++++++++++++++++++++++++++ src/realpath.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 src/Makefile create mode 100644 src/bash.h create mode 100644 src/realpath.c diff --git a/.gitignore b/.gitignore index cfcaaa17..e64b0156 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,5 @@ /versions /sources /cache +/libexec/*.dylib +/src/*.o diff --git a/libexec/rbenv-hooks b/libexec/rbenv-hooks index 86386719..939891d1 100755 --- a/libexec/rbenv-hooks +++ b/libexec/rbenv-hooks @@ -19,6 +19,7 @@ if [ -z "$RBENV_COMMAND" ]; then exit 1 fi +if ! enable -f "${BASH_SOURCE%/*}"/rbenv-realpath.dylib realpath 2>/dev/null; then READLINK=$(type -p greadlink readlink | head -1) if [ -z "$READLINK" ]; then echo "rbenv: cannot find readlink - are you missing GNU coreutils?" >&2 @@ -42,13 +43,14 @@ realpath() { echo "$(pwd)/$name" cd "$cwd" } +fi IFS=: hook_paths=($RBENV_HOOK_PATH) shopt -s nullglob for path in "${hook_paths[@]}"; do for script in "$path/$RBENV_COMMAND"/*.bash; do - echo $(realpath $script) + realpath "$script" done done shopt -u nullglob diff --git a/src/Makefile b/src/Makefile new file mode 100644 index 00000000..3d359c0d --- /dev/null +++ b/src/Makefile @@ -0,0 +1,10 @@ +SHOBJ_LDFLAGS = -dynamiclib -current_version 1.0 + +.c.o: + $(CC) $(CFLAGS) -c -o $@ $< + +../libexec/rbenv-realpath.dylib: realpath.o + $(CC) $(CFLAGS) $(SHOBJ_LDFLAGS) -o $@ realpath.o + +clean: + rm -f *.o ../libexec/*.dylib diff --git a/src/bash.h b/src/bash.h new file mode 100644 index 00000000..1b29fd05 --- /dev/null +++ b/src/bash.h @@ -0,0 +1,31 @@ +#ifndef __BASH_H__ +#define __BASH_H__ + +#define EXECUTION_SUCCESS 0 +#define EXECUTION_FAILURE 1 +#define EX_USAGE 258 + +#define BUILTIN_ENABLED 1 + +typedef struct word_desc { + char *word; + int flags; +} WORD_DESC; + +typedef struct word_list { + struct word_list *next; + WORD_DESC *word; +} WORD_LIST; + +typedef int sh_builtin_func_t(WORD_LIST *); + +struct builtin { + char *name; + sh_builtin_func_t *function; + int flags; + char * const *long_doc; + const char *short_doc; + char *unused; +}; + +#endif diff --git a/src/realpath.c b/src/realpath.c new file mode 100644 index 00000000..6c0c9f3c --- /dev/null +++ b/src/realpath.c @@ -0,0 +1,43 @@ +#include "bash.h" +#include +#include + +int realpath_builtin(list) +WORD_LIST *list; +{ + int es; + char *realbuf, *p; + + if (list == 0) { + // builtin_usage(); + return (EX_USAGE); + } + + for (es = EXECUTION_SUCCESS; list; list = list->next) { + p = list->word->word; + realbuf = realpath(p, NULL); + if (realbuf == NULL) { + es = EXECUTION_FAILURE; + // builtin_error("%s: cannot resolve: %s", p, strerror(errno)); + } else { + printf("%s\n", realbuf); + free(realbuf); + } + } + return es; +} + +char *realpath_doc[] = { + "Display each PATHNAME argument, resolving symbolic links. The exit status", + "is 0 if each PATHNAME was resolved; non-zero otherwise.", + (char *)NULL +}; + +struct builtin realpath_struct = { + "realpath", + realpath_builtin, + BUILTIN_ENABLED, + realpath_doc, + "realpath pathname [pathname...]", + 0 +}; From 284588f9b4769297c8affa5419ec2e6f59047c4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Sat, 4 Jan 2014 16:32:54 +0100 Subject: [PATCH 354/384] Fix hooks tests on OS X by expanding BATS_TMPDIR With `realpath` extension, hooks tests on OS X will output `/private/tmp` instead of `/tmp` because the latter is an actual symlink to the former. Avoid this mistmach in output assertions by expanding BATS_TMPDIR if `realpath` extension is compiled. --- test/test_helper.bash | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/test_helper.bash b/test/test_helper.bash index 53ae8e64..1f772bea 100644 --- a/test/test_helper.bash +++ b/test/test_helper.bash @@ -1,7 +1,11 @@ unset RBENV_VERSION unset RBENV_DIR -RBENV_TEST_DIR="${BATS_TMPDIR}/rbenv" +if enable -f "${BATS_TEST_DIRNAME}"/../libexec/rbenv-realpath.dylib realpath 2>/dev/null; then + RBENV_TEST_DIR="$(realpath "$BATS_TMPDIR")/rbenv" +else + RBENV_TEST_DIR="${BATS_TMPDIR}/rbenv" +fi # guard against executing this block twice due to bats internals if [ "$RBENV_ROOT" != "${RBENV_TEST_DIR}/root" ]; then From 5287e2ebf46b8636af653c1c61d4dc0dffd65796 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Sat, 4 Jan 2014 16:36:02 +0100 Subject: [PATCH 355/384] Avoid slow `abs_dirname()` by loading `realpath` extension This speeds up every `rbenv` invocation significantly. --- libexec/rbenv | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/libexec/rbenv b/libexec/rbenv index 2d475857..a458c473 100755 --- a/libexec/rbenv +++ b/libexec/rbenv @@ -12,6 +12,12 @@ if [ -n "$RBENV_DEBUG" ]; then set -x fi +if enable -f "${0%/*}"/../libexec/rbenv-realpath.dylib realpath 2>/dev/null; then + abs_dirname() { + local path="$(realpath "$1")" + echo "${path%/*}" + } +else READLINK=$(type -p greadlink readlink | head -1) if [ -z "$READLINK" ]; then echo "rbenv: cannot find readlink - are you missing GNU coreutils?" >&2 @@ -35,6 +41,7 @@ abs_dirname() { pwd cd "$cwd" } +fi if [ -z "${RBENV_ROOT}" ]; then RBENV_ROOT="${HOME}/.rbenv" From 8bac95899491cc043a40b274be224236a8224483 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Sat, 4 Jan 2014 16:37:20 +0100 Subject: [PATCH 356/384] Stop using `abs_dirname()` in rbenv-init It's slow and not necessary since we expect `$0` to already be expanded. In tests this change forces us to deal with some relative paths, but it's not a big deal. The `rbenv init -` output in the most common case will be the same as before: source '/home/myuser/.rbenv/libexec/../completions/rbenv.bash' --- libexec/rbenv-init | 26 +------------------------- test/init.bats | 4 ++-- 2 files changed, 3 insertions(+), 27 deletions(-) diff --git a/libexec/rbenv-init b/libexec/rbenv-init index 5f9079a7..8718c116 100755 --- a/libexec/rbenv-init +++ b/libexec/rbenv-init @@ -28,31 +28,7 @@ if [ -z "$shell" ]; then shell="$(basename "${shell:-$SHELL}")" 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" -} - -abs_dirname() { - local cwd="$(pwd)" - local path="$1" - - while [ -n "$path" ]; do - cd "${path%/*}" - local name="${path##*/}" - path="$(resolve_link "$name" || true)" - done - - pwd - cd "$cwd" -} - -root="$(abs_dirname "$0")/.." +root="${0%/*}/.." if [ -z "$print" ]; then case "$shell" in diff --git a/test/init.bats b/test/init.bats index aa50f091..2587a014 100644 --- a/test/init.bats +++ b/test/init.bats @@ -21,7 +21,7 @@ load test_helper root="$(cd $BATS_TEST_DIRNAME/.. && pwd)" run rbenv-init - bash assert_success - assert_line "source '${root}/libexec/../completions/rbenv.bash'" + assert_line "source '${root}/test/../libexec/../completions/rbenv.bash'" } @test "detect parent shell" { @@ -35,7 +35,7 @@ load test_helper root="$(cd $BATS_TEST_DIRNAME/.. && pwd)" run rbenv-init - fish assert_success - assert_line ". '${root}/libexec/../completions/rbenv.fish'" + assert_line ". '${root}/test/../libexec/../completions/rbenv.fish'" } @test "fish instructions" { From 68b92a7f5d408b57dbba195ddd3920d533f1f429 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Sat, 4 Jan 2014 21:58:12 +0100 Subject: [PATCH 357/384] Test compiled native extensions on Travis CI --- .travis.yml | 6 ++++-- test/run | 8 ++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) create mode 100755 test/run diff --git a/.travis.yml b/.travis.yml index ca1abab7..95b46cc2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,6 @@ install: git clone https://github.com/sstephenson/bats.git -script: bats/bin/bats --tap test -# skips unnecessary Ruby-specific setup +script: PATH="./bats/bin:$PATH" test/run language: c +env: + - RBENV_NATIVE_EXT= + - RBENV_NATIVE_EXT=1 diff --git a/test/run b/test/run new file mode 100755 index 00000000..44f41288 --- /dev/null +++ b/test/run @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +set -e + +if [ -n "$RBENV_NATIVE_EXT" ]; then + make -C src +fi + +exec bats ${CI:+--tap} test From 3f74da0e73a088f1273554f8d520e893a0697d33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Sat, 4 Jan 2014 21:59:27 +0100 Subject: [PATCH 358/384] Fail hard if RBENV_NATIVE_EXT is set but extensions failed to load --- libexec/rbenv | 4 ++++ libexec/rbenv-hooks | 4 ++++ test/test_helper.bash | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/libexec/rbenv b/libexec/rbenv index a458c473..4041df82 100755 --- a/libexec/rbenv +++ b/libexec/rbenv @@ -18,6 +18,10 @@ if enable -f "${0%/*}"/../libexec/rbenv-realpath.dylib realpath 2>/dev/null; the 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 diff --git a/libexec/rbenv-hooks b/libexec/rbenv-hooks index 939891d1..201c91da 100755 --- a/libexec/rbenv-hooks +++ b/libexec/rbenv-hooks @@ -20,6 +20,10 @@ if [ -z "$RBENV_COMMAND" ]; then fi if ! enable -f "${BASH_SOURCE%/*}"/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 diff --git a/test/test_helper.bash b/test/test_helper.bash index 1f772bea..461bb085 100644 --- a/test/test_helper.bash +++ b/test/test_helper.bash @@ -4,6 +4,10 @@ unset RBENV_DIR if enable -f "${BATS_TEST_DIRNAME}"/../libexec/rbenv-realpath.dylib realpath 2>/dev/null; then RBENV_TEST_DIR="$(realpath "$BATS_TMPDIR")/rbenv" else + if [ -n "$RBENV_NATIVE_EXT" ]; then + echo "rbenv: failed to load \`realpath' builtin" >&2 + exit 1 + fi RBENV_TEST_DIR="${BATS_TMPDIR}/rbenv" fi From b5622bee3ab562dd867a1189df8551f44d36443e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Sat, 4 Jan 2014 22:04:59 +0100 Subject: [PATCH 359/384] Try without `-current_version` Seems to only work on OS X; fails on Travis https://travis-ci.org/sstephenson/rbenv/jobs/16384866 --- src/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Makefile b/src/Makefile index 3d359c0d..6b31fd06 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,4 +1,4 @@ -SHOBJ_LDFLAGS = -dynamiclib -current_version 1.0 +SHOBJ_LDFLAGS = -dynamiclib .c.o: $(CC) $(CFLAGS) -c -o $@ $< From 8facb3b3a790fd275a4e8d5f4de474bbd837c040 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Sun, 5 Jan 2014 17:58:07 +0100 Subject: [PATCH 360/384] Import `shobj-conf` script from bash Given the `-o ` parameter, the script generates environment variables with information how to compile dynamically loadable libraries for that system. Imported from bash-3.2.48 --- src/shobj-conf | 547 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 547 insertions(+) create mode 100755 src/shobj-conf diff --git a/src/shobj-conf b/src/shobj-conf new file mode 100755 index 00000000..ef7863a3 --- /dev/null +++ b/src/shobj-conf @@ -0,0 +1,547 @@ +#! /bin/sh +# +# shobj-conf -- output a series of variable assignments to be substituted +# into a Makefile by configure which specify system-dependent +# information for creating shared objects that may be loaded +# into bash with `enable -f' +# +# usage: shobj-conf [-C compiler] -c host_cpu -o host_os -v host_vendor +# +# Chet Ramey +# chet@po.cwru.edu + +# Copyright (C) 1996-2002 Free Software Foundation, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA. + +# +# defaults +# +SHOBJ_STATUS=supported +SHLIB_STATUS=supported + +SHOBJ_CC=cc +SHOBJ_CFLAGS= +SHOBJ_LD= +SHOBJ_LDFLAGS= +SHOBJ_XLDFLAGS= +SHOBJ_LIBS= + +SHLIB_XLDFLAGS= +SHLIB_LIBS= + +SHLIB_DOT='.' +SHLIB_LIBPREF='lib' +SHLIB_LIBSUFF='so' + +SHLIB_LIBVERSION='$(SHLIB_LIBSUFF)' +SHLIB_DLLVERSION='$(SHLIB_MAJOR)' + +PROGNAME=`basename $0` +USAGE="$PROGNAME [-C compiler] -c host_cpu -o host_os -v host_vendor" + +while [ $# -gt 0 ]; do + case "$1" in + -C) shift; SHOBJ_CC="$1"; shift ;; + -c) shift; host_cpu="$1"; shift ;; + -o) shift; host_os="$1"; shift ;; + -v) shift; host_vendor="$1"; shift ;; + *) echo "$USAGE" >&2 ; exit 2;; + esac +done + +case "${host_os}-${SHOBJ_CC}" in +sunos4*-*gcc*) + SHOBJ_CFLAGS=-fpic + SHOBJ_LD=/usr/bin/ld + SHOBJ_LDFLAGS='-assert pure-text' + + SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)$(SHLIB_MINOR)' + ;; + +sunos4*) + SHOBJ_CFLAGS=-pic + SHOBJ_LD=/usr/bin/ld + SHOBJ_LDFLAGS='-assert pure-text' + + SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)$(SHLIB_MINOR)' + ;; + +sunos5*-*gcc*|solaris2*-*gcc*) + SHOBJ_CFLAGS=-fpic + SHOBJ_LD='${CC}' + ld_used=`gcc -print-prog-name=ld` + if ${ld_used} -V 2>&1 | grep GNU >/dev/null 2>&1; then + # This line works for the GNU ld + SHOBJ_LDFLAGS='-shared -Wl,-h,$@' + else + # This line works for the Solaris linker in /usr/ccs/bin/ld + SHOBJ_LDFLAGS='-shared -Wl,-i -Wl,-h,$@' + fi + +# SHLIB_XLDFLAGS='-R $(libdir)' + SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)' + ;; + +sunos5*|solaris2*) + SHOBJ_CFLAGS='-K pic' + SHOBJ_LD=/usr/ccs/bin/ld + SHOBJ_LDFLAGS='-G -dy -z text -i -h $@' + +# SHLIB_XLDFLAGS='-R $(libdir)' + SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)' + ;; + +# All versions of Linux or the semi-mythical GNU Hurd. +linux*-*|gnu*-*|k*bsd*-gnu-*) + SHOBJ_CFLAGS=-fPIC + SHOBJ_LD='${CC}' + SHOBJ_LDFLAGS='-shared -Wl,-soname,$@' + + SHLIB_XLDFLAGS='-Wl,-rpath,$(libdir) -Wl,-soname,`basename $@ $(SHLIB_MINOR)`' + SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)$(SHLIB_MINOR)' + ;; + +freebsd2* | netbsd*) + SHOBJ_CFLAGS=-fpic + SHOBJ_LD=ld + SHOBJ_LDFLAGS='-x -Bshareable' + + SHLIB_XLDFLAGS='-R$(libdir)' + SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)$(SHLIB_MINOR)' + ;; + +# FreeBSD-3.x ELF +freebsd[3-9]*|freebsdelf[3-9]*|freebsdaout[3-9]*|dragonfly*) + SHOBJ_CFLAGS=-fpic + SHOBJ_LD='${CC}' + + if [ -x /usr/bin/objformat ] && [ "`/usr/bin/objformat`" = "elf" ]; then + SHOBJ_LDFLAGS='-shared -Wl,-soname,$@' + + SHLIB_XLDFLAGS='-Wl,-rpath,$(libdir)' + SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)' + else + SHOBJ_LDFLAGS='-shared' + + SHLIB_XLDFLAGS='-R$(libdir)' + SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)$(SHLIB_MINOR)' + fi + ;; + +# Darwin/MacOS X +darwin8*) + SHOBJ_STATUS=supported + SHLIB_STATUS=supported + + SHOBJ_CFLAGS='-fno-common' + + SHOBJ_LD='MACOSX_DEPLOYMENT_TARGET=10.3 ${CC}' + + SHLIB_LIBVERSION='$(SHLIB_MAJOR)$(SHLIB_MINOR).$(SHLIB_LIBSUFF)' + SHLIB_LIBSUFF='dylib' + + SHOBJ_LDFLAGS='-undefined dynamic_lookup' + SHLIB_XLDFLAGS='-dynamiclib -arch_only `/usr/bin/arch` -install_name $(libdir)/$@ -current_version $(SHLIB_MAJOR)$(SHLIB_MINOR) -compatibility_version $(SHLIB_MAJOR) -v' + + SHLIB_LIBS='-lncurses' # see if -lcurses works on MacOS X 10.1 + ;; + +darwin*|macosx*) + SHOBJ_STATUS=unsupported + SHLIB_STATUS=supported + + SHOBJ_CFLAGS='-fno-common' + + SHOBJ_LD='${CC}' + + SHLIB_LIBVERSION='$(SHLIB_MAJOR)$(SHLIB_MINOR).$(SHLIB_LIBSUFF)' + SHLIB_LIBSUFF='dylib' + + case "${host_os}" in + darwin[78]*) SHOBJ_LDFLAGS='' + SHLIB_XLDFLAGS='-dynamiclib -arch_only `/usr/bin/arch` -install_name $(libdir)/$@ -current_version $(SHLIB_MAJOR)$(SHLIB_MINOR) -compatibility_version $(SHLIB_MAJOR) -v' + ;; + *) SHOBJ_LDFLAGS='-dynamic' + SHLIB_XLDFLAGS='-arch_only `/usr/bin/arch` -install_name $(libdir)/$@ -current_version $(SHLIB_MAJOR)$(SHLIB_MINOR) -compatibility_version $(SHLIB_MAJOR) -v' + ;; + esac + + SHLIB_LIBS='-lncurses' # see if -lcurses works on MacOS X 10.1 + ;; + +openbsd*) + SHOBJ_CFLAGS=-fPIC + SHOBJ_LD='${CC}' + SHOBJ_LDFLAGS='-shared' + + SHLIB_XLDFLAGS='-R$(libdir)' + SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)$(SHLIB_MINOR)' + ;; + +bsdi2*) + SHOBJ_CC=shlicc2 + SHOBJ_CFLAGS= + SHOBJ_LD=ld + SHOBJ_LDFLAGS=-r + SHOBJ_LIBS=-lc_s.2.1.0 + + # BSD/OS 2.x and 3.x `shared libraries' are too much of a pain in + # the ass -- they require changing {/usr/lib,etc}/shlib.map on + # each system, and the library creation process is byzantine + SHLIB_STATUS=unsupported + ;; + +bsdi3*) + SHOBJ_CC=shlicc2 + SHOBJ_CFLAGS= + SHOBJ_LD=ld + SHOBJ_LDFLAGS=-r + SHOBJ_LIBS=-lc_s.3.0.0 + + # BSD/OS 2.x and 3.x `shared libraries' are too much of a pain in + # the ass -- they require changing {/usr/lib,etc}/shlib.map on + # each system, and the library creation process is byzantine + SHLIB_STATUS=unsupported + ;; + +bsdi4*) + # BSD/OS 4.x now supports ELF and SunOS-style dynamically-linked + # shared libraries. gcc 2.x is the standard compiler, and the + # `normal' gcc options should work as they do in Linux. + + SHOBJ_CFLAGS=-fPIC + SHOBJ_LD='${CC}' + SHOBJ_LDFLAGS='-shared -Wl,-soname,$@' + + SHLIB_XLDFLAGS='-Wl,-soname,`basename $@ $(SHLIB_MINOR)`' + SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)$(SHLIB_MINOR)' + ;; + +osf*-*gcc*) + # Fix to use gcc linker driver from bfischer@TechFak.Uni-Bielefeld.DE + SHOBJ_LD='${CC}' + SHOBJ_LDFLAGS='-shared -Wl,-soname,$@' + + SHLIB_XLDFLAGS='-rpath $(libdir)' + SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)' + ;; + +osf*) + SHOBJ_LD=ld + SHOBJ_LDFLAGS='-shared -soname $@ -expect_unresolved "*"' + + SHLIB_XLDFLAGS='-rpath $(libdir)' + SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)' + ;; + +aix4.[2-9]*-*gcc*) # lightly tested by jik@cisco.com + SHOBJ_CFLAGS=-fpic + SHOBJ_LD='ld' + SHOBJ_LDFLAGS='-bdynamic -bnoentry -bexpall' + SHOBJ_XLDFLAGS='-G' + + SHLIB_XLDFLAGS='-bM:SRE' + SHLIB_LIBS='-lcurses -lc' + SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)' + ;; + +aix4.[2-9]*) + SHOBJ_CFLAGS=-K + SHOBJ_LD='ld' + SHOBJ_LDFLAGS='-bdynamic -bnoentry -bexpall' + SHOBJ_XLDFLAGS='-G' + + SHLIB_XLDFLAGS='-bM:SRE' + SHLIB_LIBS='-lcurses -lc' + SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)' + ;; + +# +# THE FOLLOWING ARE UNTESTED -- and some may not support the dlopen interface +# +irix[56]*-*gcc*) + SHOBJ_CFLAGS='-fpic' + SHOBJ_LD='${CC}' + SHOBJ_LDFLAGS='-shared -Wl,-soname,$@' + + SHLIB_XLDFLAGS='-Wl,-rpath,$(libdir)' + SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)' + ;; + +irix[56]*) + SHOBJ_CFLAGS='-K PIC' + SHOBJ_LD=ld +# SHOBJ_LDFLAGS='-call_shared -hidden_symbol -no_unresolved -soname $@' +# Change from David Kaelbling . If you have problems, +# remove the `-no_unresolved' + SHOBJ_LDFLAGS='-shared -no_unresolved -soname $@' + + SHLIB_XLDFLAGS='-rpath $(libdir)' + SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)' + ;; + +hpux9*-*gcc*) + # must use gcc; the bundled cc cannot compile PIC code + SHOBJ_CFLAGS='-fpic' + SHOBJ_LD='${CC}' + SHOBJ_LDFLAGS='-shared -Wl,-b -Wl,+s' + + SHLIB_XLDFLAGS='-Wl,+b,$(libdir)' + SHLIB_LIBSUFF='sl' + SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)' + ;; + +hpux9*) + SHOBJ_STATUS=unsupported + SHLIB_STATUS=unsupported + + # If you are using the HP ANSI C compiler, you can uncomment and use + # this code (I have not tested it) +# SHOBJ_STATUS=supported +# SHLIB_STATUS=supported +# +# SHOBJ_CFLAGS='+z' +# SHOBJ_LD='ld' +# SHOBJ_LDFLAGS='-b +s' +# +# SHLIB_XLDFLAGS='+b $(libdir)' +# SHLIB_LIBSUFF='sl' +# SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)' + + ;; + +hpux10*-*gcc*) + # must use gcc; the bundled cc cannot compile PIC code + SHOBJ_CFLAGS='-fpic' + SHOBJ_LD='${CC}' + # if you have problems linking here, moving the `-Wl,+h,$@' from + # SHLIB_XLDFLAGS to SHOBJ_LDFLAGS has been reported to work + SHOBJ_LDFLAGS='-shared -Wl,-b -Wl,+s' + + SHLIB_XLDFLAGS='-Wl,+h,$@ -Wl,+b,$(libdir)' + SHLIB_LIBSUFF='sl' + SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)' + ;; + +hpux10*) + SHOBJ_STATUS=unsupported + SHLIB_STATUS=unsupported + + # If you are using the HP ANSI C compiler, you can uncomment and use + # this code (I have not tested it) +# SHOBJ_STATUS=supported +# SHLIB_STATUS=supported +# +# SHOBJ_CFLAGS='+z' +# SHOBJ_LD='ld' +# SHOBJ_LDFLAGS='-b +s +h $@' +# +# SHLIB_XLDFLAGS='+b $(libdir)' +# SHLIB_LIBSUFF='sl' +# SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)' + + ;; + +hpux11*-*gcc*) + # must use gcc; the bundled cc cannot compile PIC code + SHOBJ_CFLAGS='-fpic' + SHOBJ_LD='${CC}' +# SHOBJ_LDFLAGS='-shared -Wl,-b -Wl,-B,symbolic -Wl,+s -Wl,+std -Wl,+h,$@' + SHOBJ_LDFLAGS='-shared -fpic -Wl,-b -Wl,+s -Wl,+h,$@' + + SHLIB_XLDFLAGS='-Wl,+b,$(libdir)' + SHLIB_LIBSUFF='sl' + SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)' + ;; + +hpux11*) + SHOBJ_STATUS=unsupported + SHLIB_STATUS=unsupported + + # If you are using the HP ANSI C compiler, you can uncomment and use + # this code (I have not tested it) +# SHOBJ_STATUS=supported +# SHLIB_STATUS=supported +# +# SHOBJ_CFLAGS='+z' +# SHOBJ_LD='ld' +# SHOBJ_LDFLAGS='-b +s +h $@' +# +# SHLIB_XLDFLAGS='+b $(libdir)' +# SHLIB_LIBSUFF='sl' +# SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)' + + ;; + +sysv4*-*gcc*) + SHOBJ_CFLAGS=-shared + SHOBJ_LDFLAGS='-shared -h $@' + SHOBJ_LD='${CC}' + + SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)' + ;; + +sysv4*) + SHOBJ_CFLAGS='-K PIC' + SHOBJ_LD=ld + SHOBJ_LDFLAGS='-dy -z text -G -h $@' + + SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)' + ;; + +sco3.2v5*-*gcc*) + SHOBJ_CFLAGS='-fpic' # DEFAULTS TO ELF + SHOBJ_LD='${CC}' + SHOBJ_LDFLAGS='-shared' + + SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)' + ;; + +sco3.2v5*) + SHOBJ_CFLAGS='-K pic -b elf' + SHOBJ_LD=ld + SHOBJ_LDFLAGS='-G -b elf -dy -z text -h $@' + + SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)' + ;; + +sysv5uw7*-*gcc*) + SHOBJ_CFLAGS='-fpic' + SHOBJ_LD='${CC}' + SHOBJ_LDFLAGS='-shared' + + SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)' + ;; + +sysv5uw7*) + SHOBJ_CFLAGS='-K PIC' + SHOBJ_LD=ld + SHOBJ_LDFLAGS='-G -dy -z text -h $@' + + SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)' + ;; + +sysv5UnixWare*-*gcc*) + SHOBJ_CFLAGS=-fpic + SHOBJ_LD='${CC}' + SHOBJ_LDFLAGS='-shared' + + SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)' + ;; + +sysv5UnixWare*) + SHOBJ_CFLAGS='-K PIC' + SHOBJ_LD=ld + SHOBJ_LDFLAGS='-G -dy -z text -h $@' + + SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)' + ;; + +sysv5OpenUNIX*-*gcc*) + SHOBJ_CFLAGS=-fpic + SHOBJ_LD='${CC}' + SHOBJ_LDFLAGS='-shared' + + SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)' + ;; + +sysv5OpenUNIX*) + SHOBJ_CFLAGS='-K PIC' + SHOBJ_LD=ld + SHOBJ_LDFLAGS='-G -dy -z text -h $@' + + SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)' + ;; + +dgux*-*gcc*) + SHOBJ_CFLAGS=-fpic + SHOBJ_LD='${CC}' + SHOBJ_LDFLAGS='-shared' + + SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)' + ;; + +dgux*) + SHOBJ_CFLAGS='-K pic' + SHOBJ_LD=ld + SHOBJ_LDFLAGS='-G -dy -h $@' + + SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)' + ;; + +msdos*) + SHOBJ_STATUS=unsupported + SHLIB_STATUS=unsupported + ;; + +cygwin*) + SHOBJ_LD='$(CC)' + SHOBJ_LDFLAGS='-shared -Wl,--enable-auto-import -Wl,--enable-auto-image-base -Wl,--export-all -Wl,--out-implib=$(@).a' + SHLIB_LIBPREF='cyg' + SHLIB_LIBSUFF='dll' + SHLIB_LIBVERSION='$(SHLIB_DLLVERSION).$(SHLIB_LIBSUFF)' + SHLIB_LIBS='$(TERMCAP_LIB)' + + SHLIB_DOT= + # For official cygwin releases, DLLVERSION will be defined in the + # environment of configure, and will be incremented any time the API + # changes in a non-backwards compatible manner. Otherwise, it is just + # SHLIB_MAJOR. + if [ -n "$DLLVERSION" ] ; then + SHLIB_DLLVERSION="$DLLVERSION" + fi + ;; + +# +# Rely on correct gcc configuration for everything else +# +*-*gcc*) + SHOBJ_CFLAGS=-fpic + SHOBJ_LD='${CC}' + SHOBJ_LDFLAGS='-shared' + + SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)' + ;; + +*) + SHOBJ_STATUS=unsupported + SHLIB_STATUS=unsupported + ;; + +esac + +echo SHOBJ_CC=\'"$SHOBJ_CC"\' +echo SHOBJ_CFLAGS=\'"$SHOBJ_CFLAGS"\' +echo SHOBJ_LD=\'"$SHOBJ_LD"\' +echo SHOBJ_LDFLAGS=\'"$SHOBJ_LDFLAGS"\' +echo SHOBJ_XLDFLAGS=\'"$SHOBJ_XLDFLAGS"\' +echo SHOBJ_LIBS=\'"$SHOBJ_LIBS"\' + +echo SHLIB_XLDFLAGS=\'"$SHLIB_XLDFLAGS"\' +echo SHLIB_LIBS=\'"$SHLIB_LIBS"\' + +echo SHLIB_DOT=\'"$SHLIB_DOT"\' + +echo SHLIB_LIBPREF=\'"$SHLIB_LIBPREF"\' +echo SHLIB_LIBSUFF=\'"$SHLIB_LIBSUFF"\' + +echo SHLIB_LIBVERSION=\'"$SHLIB_LIBVERSION"\' +echo SHLIB_DLLVERSION=\'"$SHLIB_DLLVERSION"\' + +echo SHOBJ_STATUS=\'"$SHOBJ_STATUS"\' +echo SHLIB_STATUS=\'"$SHLIB_STATUS"\' + +exit 0 From 302b317b895777cbf8a322b3362a17005131ae48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Sun, 5 Jan 2014 18:00:31 +0100 Subject: [PATCH 361/384] Fix `shobj-conf` on Darwin The `shobj-conf` script imported from bash seems to not support the latest OS X. This makes sure that `SHOBJ_LDFLAG=-dynamiclib` is output for Darwin10+ (latest version is Darwin 13.0). --- src/shobj-conf | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/shobj-conf b/src/shobj-conf index ef7863a3..593867ee 100755 --- a/src/shobj-conf +++ b/src/shobj-conf @@ -142,6 +142,17 @@ freebsd[3-9]*|freebsdelf[3-9]*|freebsdaout[3-9]*|dragonfly*) ;; # Darwin/MacOS X +darwin1*) + SHOBJ_STATUS=supported + SHLIB_STATUS=supported + + SHOBJ_CFLAGS='' + SHLIB_LIBSUFF='dylib' + + SHOBJ_LD='${CC}' + SHOBJ_LDFLAGS='-dynamiclib' + ;; + darwin8*) SHOBJ_STATUS=supported SHLIB_STATUS=supported From a6e0785b84993fa3a5192a66ee816ed7c0e0a43e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Sun, 5 Jan 2014 17:55:43 +0100 Subject: [PATCH 362/384] Create `configure` script to generate a cross-platform Makefile The previous Makefile only worked on OS X. The dynamically generated Makefile (from `Makefile.in`) should now work on multiple platforms (tested on OS X and Ubuntu). --- .gitignore | 1 + src/Makefile | 10 ---------- src/Makefile.in | 25 +++++++++++++++++++++++++ src/configure | 39 +++++++++++++++++++++++++++++++++++++++ test/run | 1 + 5 files changed, 66 insertions(+), 10 deletions(-) delete mode 100644 src/Makefile create mode 100644 src/Makefile.in create mode 100755 src/configure diff --git a/.gitignore b/.gitignore index e64b0156..84639e79 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ /sources /cache /libexec/*.dylib +/src/Makefile /src/*.o diff --git a/src/Makefile b/src/Makefile deleted file mode 100644 index 6b31fd06..00000000 --- a/src/Makefile +++ /dev/null @@ -1,10 +0,0 @@ -SHOBJ_LDFLAGS = -dynamiclib - -.c.o: - $(CC) $(CFLAGS) -c -o $@ $< - -../libexec/rbenv-realpath.dylib: realpath.o - $(CC) $(CFLAGS) $(SHOBJ_LDFLAGS) -o $@ realpath.o - -clean: - rm -f *.o ../libexec/*.dylib diff --git a/src/Makefile.in b/src/Makefile.in new file mode 100644 index 00000000..b4b1825b --- /dev/null +++ b/src/Makefile.in @@ -0,0 +1,25 @@ +CC = @CC@ + +CFLAGS = @CFLAGS@ +LOCAL_CFLAGS = @LOCAL_CFLAGS@ +DEFS = @DEFS@ +LOCAL_DEFS = @LOCAL_DEFS@ + +CCFLAGS = $(DEFS) $(LOCAL_DEFS) $(LOCAL_CFLAGS) $(CFLAGS) + +SHOBJ_CC = @SHOBJ_CC@ +SHOBJ_CFLAGS = @SHOBJ_CFLAGS@ +SHOBJ_LD = @SHOBJ_LD@ +SHOBJ_LDFLAGS = @SHOBJ_LDFLAGS@ +SHOBJ_XLDFLAGS = @SHOBJ_XLDFLAGS@ +SHOBJ_LIBS = @SHOBJ_LIBS@ +SHOBJ_STATUS = @SHOBJ_STATUS@ + +.c.o: + $(SHOBJ_CC) $(SHOBJ_CFLAGS) $(CCFLAGS) -c -o $@ $< + +../libexec/rbenv-realpath.dylib: realpath.o + $(SHOBJ_LD) $(SHOBJ_LDFLAGS) $(SHOBJ_XLDFLAGS) -o $@ realpath.o $(SHOBJ_LIBS) + +clean: + rm -f *.o ../libexec/*.dylib diff --git a/src/configure b/src/configure new file mode 100755 index 00000000..f54f09d2 --- /dev/null +++ b/src/configure @@ -0,0 +1,39 @@ +#!/usr/bin/env bash +set -e + +src_dir="${0%/*}" + +CC="${CC:-gcc}" + +if ! which "$CC" &>/dev/null; then + echo "no compiler found: $CC" >&2 + exit 1 +fi + +case "$(uname -s)" in +Darwin* ) + host_os="darwin$(uname -r)" + ;; +OpenBSD* ) + host_os="openbsd$(uname -r)" + ;; +* ) + host_os="linux-gnu" +esac + +eval "$("$src_dir"/shobj-conf -C "$CC" -o "$host_os")" + +sed " + s,@CC@,${CC}, + s,@CFLAGS@,${CFLAGS}, + s,@LOCAL_CFLAGS@,${LOCAL_CFLAGS}, + s,@DEFS@,${DEFS}, + s,@LOCAL_DEFS@,${LOCAL_DEFS}, + s,@SHOBJ_CC@,${SHOBJ_CC}, + s,@SHOBJ_CFLAGS@,${SHOBJ_CFLAGS}, + s,@SHOBJ_LD@,${SHOBJ_LD}, + s,@SHOBJ_LDFLAGS@,${SHOBJ_LDFLAGS//,/\,}, + s,@SHOBJ_XLDFLAGS@,${SHOBJ_XLDFLAGS//,/\,}, + s,@SHOBJ_LIBS@,${SHOBJ_LIBS}, + s,@SHOBJ_STATUS@,${SHOBJ_STATUS}, +" "$src_dir"/Makefile.in > "$src_dir"/Makefile diff --git a/test/run b/test/run index 44f41288..9d3b9e52 100755 --- a/test/run +++ b/test/run @@ -2,6 +2,7 @@ set -e if [ -n "$RBENV_NATIVE_EXT" ]; then + src/configure make -C src fi From 294cff3fd4a2d6bfbabf91591383f99715144d11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Sun, 5 Jan 2014 18:27:35 +0100 Subject: [PATCH 363/384] Fall back to `cc` as default compiler when `gcc` is not available --- src/configure | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/configure b/src/configure index f54f09d2..dc29eb79 100755 --- a/src/configure +++ b/src/configure @@ -3,10 +3,17 @@ set -e src_dir="${0%/*}" -CC="${CC:-gcc}" +if [ -z "$CC" ]; then + if type -p gcc >/dev/null; then + CC=gcc + else + echo "warning: gcc not found; using CC=cc" >&2 + CC=cc + fi +fi -if ! which "$CC" &>/dev/null; then - echo "no compiler found: $CC" >&2 +if ! type -p "$CC" >/dev/null; then + echo "aborted: compiler not found: $CC" >&2 exit 1 fi From 6bb7f07d2d74aee3bb02421265bd28767e94dcce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Mon, 13 Oct 2014 03:11:12 +0200 Subject: [PATCH 364/384] Avoid `rbenv-exec` calling out to `rbenv-version-name` twice Running any shim (and thus `rbenv-exec`) would always execute `rbenv-version-name` twice: once in `rbenv-exec` and another time in `rbenv-which`, even though RBENV_VERSION variable would have already been populated at this point. Now RBENV_VERSION is respected within `rbenv-which`. --- libexec/rbenv-which | 6 +++++- test/which.bats | 9 +++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/libexec/rbenv-which b/libexec/rbenv-which index 5d73673c..49906df6 100755 --- a/libexec/rbenv-which +++ b/libexec/rbenv-which @@ -48,7 +48,6 @@ remove_from_path() { echo "${result%:}" } -RBENV_VERSION="$(rbenv-version-name)" RBENV_COMMAND="$1" if [ -z "$RBENV_COMMAND" ]; then @@ -56,6 +55,8 @@ if [ -z "$RBENV_COMMAND" ]; then exit 1 fi +RBENV_VERSION="${RBENV_VERSION:-$(rbenv-version-name)}" + if [ "$RBENV_VERSION" = "system" ]; then PATH="$(remove_from_path "${RBENV_ROOT}/shims")" RBENV_COMMAND_PATH="$(command -v "$RBENV_COMMAND" || true)" @@ -72,6 +73,9 @@ 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 + exit 1 else echo "rbenv: $RBENV_COMMAND: command not found" >&2 diff --git a/test/which.bats b/test/which.bats index a9d9f82a..e52d5005 100644 --- a/test/which.bats +++ b/test/which.bats @@ -72,3 +72,12 @@ SH assert_success assert_output "HELLO=:hello:ugly:world:again" } + +@test "discovers version from rbenv-version-name" { + mkdir -p "$RBENV_ROOT" + cat > "${RBENV_ROOT}/version" <<<"1.8" + create_executable "1.8" "ruby" + + RBENV_VERSION= run rbenv-which ruby + assert_success "${RBENV_ROOT}/versions/1.8/bin/ruby" +} From e4cbf04592cfcd9d244fb83284e14524c8ba0377 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Thu, 13 Mar 2014 19:45:11 +0100 Subject: [PATCH 365/384] Improve performance of rbenv-which when RBENV_VERSION=system This implements removing of the shims path element via bash substitution, instead of jumping around in all the `$PATH` elements. --- libexec/rbenv-which | 46 ++++++++++++--------------------------------- test/which.bats | 25 ++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 34 deletions(-) diff --git a/libexec/rbenv-which b/libexec/rbenv-which index 49906df6..6b0d93a2 100755 --- a/libexec/rbenv-which +++ b/libexec/rbenv-which @@ -15,38 +15,6 @@ if [ "$1" = "--complete" ]; then exec rbenv shims --short fi -expand_path() { - if [ ! -d "$1" ]; then - return 1 - fi - - local cwd="$(pwd)" - cd "$1" - pwd - cd "$cwd" -} - -remove_from_path() { - local path_to_remove="$(expand_path "$1")" - local result="" - - if [ -z "$path_to_remove" ]; then - echo "${PATH}" - return - fi - - local paths - IFS=: paths=($PATH) - - for path in "${paths[@]}"; do - path="$(expand_path "$path" || true)" - if [ -n "$path" ] && [ "$path" != "$path_to_remove" ]; then - result="${result}${path}:" - fi - done - - echo "${result%:}" -} RBENV_COMMAND="$1" @@ -58,8 +26,18 @@ fi RBENV_VERSION="${RBENV_VERSION:-$(rbenv-version-name)}" if [ "$RBENV_VERSION" = "system" ]; then - PATH="$(remove_from_path "${RBENV_ROOT}/shims")" - RBENV_COMMAND_PATH="$(command -v "$RBENV_COMMAND" || true)" + # Remove shims from PATH. Use a loop, because Bash won't remove all ":foo:" + # in ":foo:foo:" in one go. + path=":$PATH:" + remove="${RBENV_ROOT}/shims" + while true; do + path_before="$path" + path="${path//:$remove:/:}" + if [[ "$path_before" = "$path" ]]; then + break + fi + done + RBENV_COMMAND_PATH="$(PATH=$path command -v "$RBENV_COMMAND" || true)" else RBENV_COMMAND_PATH="${RBENV_ROOT}/versions/${RBENV_VERSION}/bin/${RBENV_COMMAND}" fi diff --git a/test/which.bats b/test/which.bats index e52d5005..6e68a0e6 100644 --- a/test/which.bats +++ b/test/which.bats @@ -31,6 +31,31 @@ create_executable() { assert_success "${RBENV_TEST_DIR}/bin/kill-all-humans" } +@test "searches PATH for system version (shims prepended)" { + create_executable "${RBENV_TEST_DIR}/bin" "kill-all-humans" + create_executable "${RBENV_ROOT}/shims" "kill-all-humans" + + PATH="${RBENV_ROOT}/shims:$PATH" RBENV_VERSION=system run rbenv-which kill-all-humans + assert_success "${RBENV_TEST_DIR}/bin/kill-all-humans" +} + +@test "searches PATH for system version (shims appended)" { + create_executable "${RBENV_TEST_DIR}/bin" "kill-all-humans" + create_executable "${RBENV_ROOT}/shims" "kill-all-humans" + + PATH="$PATH:${RBENV_ROOT}/shims" RBENV_VERSION=system run rbenv-which kill-all-humans + assert_success "${RBENV_TEST_DIR}/bin/kill-all-humans" +} + +@test "searches PATH for system version (shims spread)" { + create_executable "${RBENV_TEST_DIR}/bin" "kill-all-humans" + create_executable "${RBENV_ROOT}/shims" "kill-all-humans" + + PATH="${RBENV_ROOT}/shims:${RBENV_ROOT}/shims:/tmp/non-existent:$PATH:${RBENV_ROOT}/shims" \ + RBENV_VERSION=system run rbenv-which kill-all-humans + assert_success "${RBENV_TEST_DIR}/bin/kill-all-humans" +} + @test "version not installed" { create_executable "2.0" "rspec" RBENV_VERSION=1.9 run rbenv-which rspec From 3ee395f9b576e4111650cef67328f4ffe3687b5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Mon, 13 Oct 2014 12:24:45 +0200 Subject: [PATCH 366/384] Clean up PATH sanitization in rbenv-which --- libexec/rbenv-which | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/libexec/rbenv-which b/libexec/rbenv-which index 6b0d93a2..f656537d 100755 --- a/libexec/rbenv-which +++ b/libexec/rbenv-which @@ -15,6 +15,16 @@ if [ "$1" = "--complete" ]; then exec rbenv shims --short fi +remove_from_path() { + local path_to_remove="$1" + local path_before + local result=":$PATH:" + while [ "$path_before" != "$result" ]; do + path_before="$result" + result="${result//:$path_to_remove:/:}" + done + echo "${result%:}" +} RBENV_COMMAND="$1" @@ -26,18 +36,8 @@ fi RBENV_VERSION="${RBENV_VERSION:-$(rbenv-version-name)}" if [ "$RBENV_VERSION" = "system" ]; then - # Remove shims from PATH. Use a loop, because Bash won't remove all ":foo:" - # in ":foo:foo:" in one go. - path=":$PATH:" - remove="${RBENV_ROOT}/shims" - while true; do - path_before="$path" - path="${path//:$remove:/:}" - if [[ "$path_before" = "$path" ]]; then - break - fi - done - RBENV_COMMAND_PATH="$(PATH=$path command -v "$RBENV_COMMAND" || true)" + PATH="$(remove_from_path "${RBENV_ROOT}/shims")" + RBENV_COMMAND_PATH="$(command -v "$RBENV_COMMAND" || true)" else RBENV_COMMAND_PATH="${RBENV_ROOT}/versions/${RBENV_VERSION}/bin/${RBENV_COMMAND}" fi From c69d9a1128283f20ad883178e3649d7ed92be663 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Mon, 13 Oct 2014 12:39:47 +0200 Subject: [PATCH 367/384] Isolate rbenv-which tests from any `.ruby-version` file on the system Having a `.ruby-version` file in any of the parent directories of the local clone of rbenv could cause the test suite to fail because it wasn't expecting a local version to be set. Fixes #533 --- test/which.bats | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/which.bats b/test/which.bats index 6e68a0e6..3f68a31a 100644 --- a/test/which.bats +++ b/test/which.bats @@ -93,7 +93,7 @@ echo HELLO="\$(printf ":%s" "\${hellos[@]}")" exit SH - RBENV_HOOK_PATH="$hook_path" IFS=$' \t\n' run rbenv-which anything + RBENV_HOOK_PATH="$hook_path" IFS=$' \t\n' RBENV_VERSION=system run rbenv-which anything assert_success assert_output "HELLO=:hello:ugly:world:again" } @@ -103,6 +103,9 @@ SH cat > "${RBENV_ROOT}/version" <<<"1.8" create_executable "1.8" "ruby" + mkdir -p "$RBENV_TEST_DIR" + cd "$RBENV_TEST_DIR" + RBENV_VERSION= run rbenv-which ruby assert_success "${RBENV_ROOT}/versions/1.8/bin/ruby" } From e851250da66307a2584218b555068c941b493d44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Wed, 15 Oct 2014 01:24:45 +0200 Subject: [PATCH 368/384] Speed up obtaining `exec/which/whence` completions Delegate to `rbenv-shims` instead of `rbenv shims` and therefore skip going through the main `rbenv` executable again that would set up a lot of the environment that was already set. --- libexec/rbenv-exec | 2 +- libexec/rbenv-whence | 2 +- libexec/rbenv-which | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libexec/rbenv-exec b/libexec/rbenv-exec index a9309d0e..e05ce511 100755 --- a/libexec/rbenv-exec +++ b/libexec/rbenv-exec @@ -18,7 +18,7 @@ set -e # Provide rbenv completions if [ "$1" = "--complete" ]; then - exec rbenv shims --short + exec rbenv-shims --short fi RBENV_VERSION="$(rbenv-version-name)" diff --git a/libexec/rbenv-whence b/libexec/rbenv-whence index df1d6604..3d4c89b4 100755 --- a/libexec/rbenv-whence +++ b/libexec/rbenv-whence @@ -8,7 +8,7 @@ set -e # Provide rbenv completions if [ "$1" = "--complete" ]; then echo --path - exec rbenv shims --short + exec rbenv-shims --short fi if [ "$1" = "--path" ]; then diff --git a/libexec/rbenv-which b/libexec/rbenv-which index f656537d..3cf91de7 100755 --- a/libexec/rbenv-which +++ b/libexec/rbenv-which @@ -12,7 +12,7 @@ set -e # Provide rbenv completions if [ "$1" = "--complete" ]; then - exec rbenv shims --short + exec rbenv-shims --short fi remove_from_path() { From e2173df4aa91c8d365ca1596fb857fcac9fdd787 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Wed, 15 Oct 2014 01:36:20 +0200 Subject: [PATCH 369/384] Revert "Don't duplicate shims in PATH" Too many of our users have a shell initialization set up that inadvertently duplicates some or most of the entries in their PATH, bringing the system paths again in front of rbenv's shims. If this was a nested shell (a typical scenario when starting up tmux), `rbenv init` would get eval'd again but this time, shims won't get added to the front of the PATH and would only stay and the end of the path, effectively rendering them useless. I tried to argue that this is a user problem rather than rbenv's, but I can't fix everybody shell init when they report bugs. Instead, let's revert to simpler times in rbenv where we just roll along with the duplication and don't ask any questions. This reverts commit 03fa148e814d50aba8012dc94b866213a00ea8a9. Fixes #369 --- libexec/rbenv-init | 13 ++----------- libexec/rbenv-realpath.dylib | Bin 0 -> 8672 bytes test/init.bats | 4 ++-- 3 files changed, 4 insertions(+), 13 deletions(-) create mode 100755 libexec/rbenv-realpath.dylib diff --git a/libexec/rbenv-init b/libexec/rbenv-init index 5f9079a7..fbffb85f 100755 --- a/libexec/rbenv-init +++ b/libexec/rbenv-init @@ -92,22 +92,13 @@ fi mkdir -p "${RBENV_ROOT}/"{shims,versions} -if [[ ":${PATH}:" != *:"${RBENV_ROOT}/shims":* ]]; then - case "$shell" in - fish ) - echo "setenv PATH '${RBENV_ROOT}/shims' \$PATH" - ;; - * ) - echo 'export PATH="'${RBENV_ROOT}'/shims:${PATH}"' - ;; - esac -fi - case "$shell" in fish ) + echo "setenv PATH '${RBENV_ROOT}/shims' \$PATH" echo "setenv RBENV_SHELL $shell" ;; * ) + echo 'export PATH="'${RBENV_ROOT}'/shims:${PATH}"' echo "export RBENV_SHELL=$shell" ;; esac diff --git a/libexec/rbenv-realpath.dylib b/libexec/rbenv-realpath.dylib new file mode 100755 index 0000000000000000000000000000000000000000..c42aca38256af4e3c9531371636e35fb94e1bfe3 GIT binary patch literal 8672 zcmeHNL2MgE6#Z@rN!vgi)I*?vrd3h}N;gIzQA8`*D2q0tL}?O4B`DLiJ*ihXYiD=e zBo!7#r3cF@#foo2c-Gd?Eml2 z%-fmgwX`$i@3#N^XAmGY008%5xgX2eJpk7sjS;|uSSI%YaK31sUkp?Im#A4UCoysY z(uAB;$$22w0*WF_@^$Wu@}J9k!uw?$y8Uo94mtOOTHfDHCHX$4iJ(0YIUt;pF}Weh zM{_2N_;^W_tHKL$|9rocd`8$BfH2C^vpdFD@B`0rFUc0k@%<(FK9ThbE5bf*Ombdx zR~@&=9e1e`;{Ng79Eo~bl7MiMLso^3b5Y_;p1mxhY;t^?l5b3QB23T7UPjN!DHNFV z>D*#2)=E7edw6XSNcBVnDerIH@>taQu8Dn z@2{R?;wIy~Xa{x_N4S5!8Of)<2f}^Naj$C_k#5wM^RqLvFPhUc>Nm#1YLGue0Et_u zF&T|Zh9Rb(&nYZ4k9giNrpiuUtck*umly8klb*24RXZpd#dWNJV*pn(#K59krO_)b zC_RaocrQv%&lJ_S5Yrf{N3ozkgk=s(+(<_%cboql_8*FOlJODrbf2F;-G1S{b7wN2 zjZd$9u=3&HIOb4NfCC4^^0>m3LmS3IP^vynPC$YQ9HGP+3^_1F>v8FD1ZM z0LQTq@B1to&tnqbL`-%93)K_OqSvMs&B&5qT~4p~jG8s=@QS--uxO!)gz>lSQ26NdFx!~Ah`f|_8F#KhBSzt!z_o90%-+-aIS z*0rxQ7rxr)PP~S6-HF%3>qWetz41s6U2dT}@g(|<64A8(z`iA#RQnf-9-`<6j3)ep zFzxu&vc1lPT_~}++@dv`d&y+Bcd524+~5i33BOXlj4L-5Ekm3FD?9ERzQGntf{8UJ zV18f+H6I+GWtg*+U|O|($svl*F}LELydt~`s{|$CtvbFiK)r(R28>?FU0jQ?S5;&f z#s!)R&Iul-04?t6-ImtKPot-z*1HtbJNGd5OozP@AkE>>VQ^(0Qfui{dU$YXgUA#1 zyivFt7d;od|Iv#RX&hdt>YE7S`XC|?NvYRwE|iJt$7lgfWk{4BlIldVE5UcG N`=!3)Tf=dY{R^K+djJ3c literal 0 HcmV?d00001 diff --git a/test/init.bats b/test/init.bats index aa50f091..78a762f1 100644 --- a/test/init.bats +++ b/test/init.bats @@ -64,11 +64,11 @@ load test_helper assert_line 0 "setenv PATH '${RBENV_ROOT}/shims' \$PATH" } -@test "doesn't add shims to PATH more than once" { +@test "can add shims to PATH more than once" { export PATH="${RBENV_ROOT}/shims:$PATH" run rbenv-init - bash assert_success - refute_line 'export PATH="'${RBENV_ROOT}'/shims:${PATH}"' + assert_line 0 'export PATH="'${RBENV_ROOT}'/shims:${PATH}"' } @test "doesn't add shims to PATH more than once (fish)" { From a8df5d587cb8da3537bd0ecbb11ac6016828c75d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Wed, 15 Oct 2014 03:39:04 +0200 Subject: [PATCH 370/384] Avoid changing directories during rehash process --- libexec/rbenv-rehash | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/libexec/rbenv-rehash b/libexec/rbenv-rehash index 5ec195ec..d89af7fa 100755 --- a/libexec/rbenv-rehash +++ b/libexec/rbenv-rehash @@ -70,9 +70,10 @@ SH # 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 + local shim + for shim in "$SHIM_PATH"/*; do if ! diff "$PROTOTYPE_SHIM_PATH" "$shim" >/dev/null 2>&1; then - for shim in *; do rm -f "$shim"; done + rm -f "$SHIM_PATH"/* fi break done @@ -82,10 +83,9 @@ remove_outdated_shims() { # 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() { - local shims=("$@") - - for file in "${shims[@]}"; do - local shim="${file##*/}" + local file shim + for file; do + shim="${file##*/}" register_shim "$shim" done } @@ -110,9 +110,10 @@ register_shim() { # `registered_shims` array and create a link if one does not already # exist. install_registered_shims() { - local shim + local shim file for shim in "${registered_shims[@]}"; do - [ -e "$shim" ] || ln -f "$PROTOTYPE_SHIM_PATH" "$shim" + file="${SHIM_PATH}/${shim}" + [ -e "$file" ] || ln -f "$PROTOTYPE_SHIM_PATH" "$file" done } @@ -122,16 +123,13 @@ install_registered_shims() { # removed. remove_stale_shims() { local shim - for shim in *; do - if [[ "$registered_shims_index" != *"/$shim/"* ]]; then + for shim in "$SHIM_PATH"/*; do + if [[ "$registered_shims_index" != *"/${shim##*/}/"* ]]; then rm -f "$shim" fi done } - -# Change to the shims directory. -cd "$SHIM_PATH" shopt -s nullglob # Create the prototype shim, then register shims for all known @@ -140,8 +138,6 @@ create_prototype_shim remove_outdated_shims make_shims ../versions/*/bin/* -# Restore the previous working directory. -cd "$OLDPWD" # Allow plugins to register shims. OLDIFS="$IFS" @@ -152,8 +148,5 @@ for script in "${scripts[@]}"; do source "$script" done -# Change back to the shims directory to install the registered shims -# and remove stale shims. -cd "$SHIM_PATH" install_registered_shims remove_stale_shims From 89d4e8a0e0e16a4afd7c834d28d1ba21b81a8182 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Wed, 15 Oct 2014 04:05:41 +0200 Subject: [PATCH 371/384] Speed up rehash process when there are many Ruby versions On my system that has 25 versions under rbenv, this speeds up rehash almost 3-fold: - before: 391 ms - after: 134 ms This is achieved by removing duplicate names of executables before registering them as shims. Since most Rubies will share a lot of the same executable names ("ruby", "rake", "bundle", ...), this is a considerable reduction in number of shims registered. --- libexec/rbenv-rehash | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/libexec/rbenv-rehash b/libexec/rbenv-rehash index d89af7fa..df221e65 100755 --- a/libexec/rbenv-rehash +++ b/libexec/rbenv-rehash @@ -79,6 +79,14 @@ remove_outdated_shims() { done } +# List basenames of executables for every Ruby version +list_executable_names() { + local file + for file in "$RBENV_ROOT"/versions/*/bin/*; do + echo "${file##*/}" + 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. @@ -136,7 +144,7 @@ shopt -s nullglob # executables. create_prototype_shim remove_outdated_shims -make_shims ../versions/*/bin/* +make_shims $(list_executable_names | sort -u) # Allow plugins to register shims. From 1381c2ca79dc515406f82cbac380706ad9c9ec55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Wed, 15 Oct 2014 05:12:28 +0200 Subject: [PATCH 372/384] Simplify the shims registration implementation in `rbenv-rehash` It doesn't need to be a bash array and we don't need a separate index of shims registered. Simply keep everything in a space-separated string and use that as an index as well. This assumes that executable names *never* have spaces in them. --- libexec/rbenv-rehash | 23 ++++++----------------- test/rehash.bats | 21 ++++++++++++++++++++- 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/libexec/rbenv-rehash b/libexec/rbenv-rehash index df221e65..19f9daa5 100755 --- a/libexec/rbenv-rehash +++ b/libexec/rbenv-rehash @@ -98,28 +98,17 @@ make_shims() { done } -# 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="" +registered_shims=" " -# We will keep track of shims registered for installation with the -# global `registered_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. +# Registers the name of a shim to be generated. register_shim() { - local shim="$@" - registered_shims["${#registered_shims[@]}"]="$shim" - registered_shims_index="$registered_shims_index/$shim/" + registered_shims="${registered_shims}${1} " } -# To install all the registered shims, we iterate over the -# `registered_shims` array and create a link if one does not already -# exist. +# Install all the shims registered via `make_shims` or `register_shim` directly. install_registered_shims() { local shim file - for shim in "${registered_shims[@]}"; do + for shim in $registered_shims; do file="${SHIM_PATH}/${shim}" [ -e "$file" ] || ln -f "$PROTOTYPE_SHIM_PATH" "$file" done @@ -132,7 +121,7 @@ install_registered_shims() { remove_stale_shims() { local shim for shim in "$SHIM_PATH"/*; do - if [[ "$registered_shims_index" != *"/${shim##*/}/"* ]]; then + if [[ "$registered_shims" != *" ${shim##*/} "* ]]; then rm -f "$shim" fi done diff --git a/test/rehash.bats b/test/rehash.bats index ba12a245..74f55a97 100755 --- a/test/rehash.bats +++ b/test/rehash.bats @@ -53,7 +53,7 @@ ruby OUT } -@test "removes stale shims" { +@test "removes outdated shims" { mkdir -p "${RBENV_ROOT}/shims" touch "${RBENV_ROOT}/shims/oldshim1" chmod +x "${RBENV_ROOT}/shims/oldshim1" @@ -67,6 +67,25 @@ OUT assert [ ! -e "${RBENV_ROOT}/shims/oldshim1" ] } +@test "do exact matches when removing stale shims" { + create_executable "2.0" "unicorn_rails" + create_executable "2.0" "rspec-core" + + rbenv-rehash + + cp "$RBENV_ROOT"/shims/{rspec-core,rspec} + cp "$RBENV_ROOT"/shims/{rspec-core,rails} + cp "$RBENV_ROOT"/shims/{rspec-core,uni} + chmod +x "$RBENV_ROOT"/shims/{rspec,rails,uni} + + run rbenv-rehash + assert_success "" + + assert [ ! -e "${RBENV_ROOT}/shims/rails" ] + assert [ ! -e "${RBENV_ROOT}/shims/rake" ] + assert [ ! -e "${RBENV_ROOT}/shims/uni" ] +} + @test "binary install locations containing spaces" { create_executable "dirname1 p247" "ruby" create_executable "dirname2 preview1" "rspec" From bf39d88d11ef341d0be5a845f170699bd40678c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Sun, 19 Oct 2014 14:34:27 +0200 Subject: [PATCH 373/384] Add tests for rbenv PATH and RBENV_HOOK_PATH handling --- test/libexec/rbenv-echo | 9 ++++++++- test/rbenv.bats | 23 +++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/test/libexec/rbenv-echo b/test/libexec/rbenv-echo index 0a802df4..a94af7bb 100755 --- a/test/libexec/rbenv-echo +++ b/test/libexec/rbenv-echo @@ -1,2 +1,9 @@ #!/usr/bin/env bash -eval "echo \$$1" +# Usage: rbenv echo [-F] VAR + +if [[ $1 == -F* ]]; then + sep="${1:2}" + echo "${!2}" | tr "${sep:-:}" $'\n' +else + echo "${!1}" +fi diff --git a/test/rbenv.bats b/test/rbenv.bats index e8a939af..e7cea6f0 100644 --- a/test/rbenv.bats +++ b/test/rbenv.bats @@ -45,3 +45,26 @@ load test_helper assert_failure assert_output "rbenv: cannot change working directory to \`$dir'" } + +@test "adds its own libexec to PATH" { + run rbenv echo "PATH" + assert_success "${BATS_TEST_DIRNAME%/*}/libexec:$PATH" +} + +@test "adds plugin bin dirs to PATH" { + mkdir -p "$RBENV_ROOT"/plugins/ruby-build/bin + mkdir -p "$RBENV_ROOT"/plugins/rbenv-each/bin + run rbenv echo -F: "PATH" + assert_success + assert_line 0 "${BATS_TEST_DIRNAME%/*}/libexec" + assert_line 1 "${RBENV_ROOT}/plugins/ruby-build/bin" + assert_line 2 "${RBENV_ROOT}/plugins/rbenv-each/bin" +} + +@test "RBENV_HOOK_PATH preserves value from environment" { + RBENV_HOOK_PATH=/my/hook/path:/other/hooks run rbenv echo -F: "RBENV_HOOK_PATH" + assert_success + assert_line 0 "/my/hook/path" + assert_line 1 "/other/hooks" + assert_line 2 "${RBENV_ROOT}/rbenv.d" +} From 632263568e637817e8efb0b460667f5a021f2dd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Thu, 16 Oct 2014 16:31:51 +0200 Subject: [PATCH 374/384] Add rbenv's own `rbenv.d` directory to hook paths This allows rbenv source code to ship with built-in hooks. --- libexec/rbenv | 13 +++++++++---- libexec/rbenv-realpath.dylib | Bin 8672 -> 0 bytes test/rbenv.bats | 5 +++++ 3 files changed, 14 insertions(+), 4 deletions(-) delete mode 100755 libexec/rbenv-realpath.dylib diff --git a/libexec/rbenv b/libexec/rbenv index 4041df82..de7ea692 100755 --- a/libexec/rbenv +++ b/libexec/rbenv @@ -71,15 +71,20 @@ shopt -s nullglob bin_path="$(abs_dirname "$0")" for plugin_bin in "${RBENV_ROOT}/plugins/"*/bin; do - bin_path="${bin_path}:${plugin_bin}" + PATH="${plugin_bin}:${PATH}" done export PATH="${bin_path}:${PATH}" -hook_path="${RBENV_HOOK_PATH}:${RBENV_ROOT}/rbenv.d:/usr/local/etc/rbenv.d:/etc/rbenv.d:/usr/lib/rbenv/hooks" +RBENV_HOOK_PATH="${RBENV_HOOK_PATH}:${RBENV_ROOT}/rbenv.d" +if [ "${bin_path%/*}" != "$RBENV_ROOT" ]; then + # Add rbenv's own `rbenv.d` unless rbenv was cloned to RBENV_ROOT + RBENV_HOOK_PATH="${RBENV_HOOK_PATH}:${bin_path%/*}/rbenv.d" +fi +RBENV_HOOK_PATH="${RBENV_HOOK_PATH}:/usr/local/etc/rbenv.d:/etc/rbenv.d:/usr/lib/rbenv/hooks" for plugin_hook in "${RBENV_ROOT}/plugins/"*/etc/rbenv.d; do - hook_path="${hook_path}:${plugin_hook}" + RBENV_HOOK_PATH="${RBENV_HOOK_PATH}:${plugin_hook}" done -export RBENV_HOOK_PATH="$hook_path" +export RBENV_HOOK_PATH shopt -u nullglob diff --git a/libexec/rbenv-realpath.dylib b/libexec/rbenv-realpath.dylib deleted file mode 100755 index c42aca38256af4e3c9531371636e35fb94e1bfe3..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 8672 zcmeHNL2MgE6#Z@rN!vgi)I*?vrd3h}N;gIzQA8`*D2q0tL}?O4B`DLiJ*ihXYiD=e zBo!7#r3cF@#foo2c-Gd?Eml2 z%-fmgwX`$i@3#N^XAmGY008%5xgX2eJpk7sjS;|uSSI%YaK31sUkp?Im#A4UCoysY z(uAB;$$22w0*WF_@^$Wu@}J9k!uw?$y8Uo94mtOOTHfDHCHX$4iJ(0YIUt;pF}Weh zM{_2N_;^W_tHKL$|9rocd`8$BfH2C^vpdFD@B`0rFUc0k@%<(FK9ThbE5bf*Ombdx zR~@&=9e1e`;{Ng79Eo~bl7MiMLso^3b5Y_;p1mxhY;t^?l5b3QB23T7UPjN!DHNFV z>D*#2)=E7edw6XSNcBVnDerIH@>taQu8Dn z@2{R?;wIy~Xa{x_N4S5!8Of)<2f}^Naj$C_k#5wM^RqLvFPhUc>Nm#1YLGue0Et_u zF&T|Zh9Rb(&nYZ4k9giNrpiuUtck*umly8klb*24RXZpd#dWNJV*pn(#K59krO_)b zC_RaocrQv%&lJ_S5Yrf{N3ozkgk=s(+(<_%cboql_8*FOlJODrbf2F;-G1S{b7wN2 zjZd$9u=3&HIOb4NfCC4^^0>m3LmS3IP^vynPC$YQ9HGP+3^_1F>v8FD1ZM z0LQTq@B1to&tnqbL`-%93)K_OqSvMs&B&5qT~4p~jG8s=@QS--uxO!)gz>lSQ26NdFx!~Ah`f|_8F#KhBSzt!z_o90%-+-aIS z*0rxQ7rxr)PP~S6-HF%3>qWetz41s6U2dT}@g(|<64A8(z`iA#RQnf-9-`<6j3)ep zFzxu&vc1lPT_~}++@dv`d&y+Bcd524+~5i33BOXlj4L-5Ekm3FD?9ERzQGntf{8UJ zV18f+H6I+GWtg*+U|O|($svl*F}LELydt~`s{|$CtvbFiK)r(R28>?FU0jQ?S5;&f z#s!)R&Iul-04?t6-ImtKPot-z*1HtbJNGd5OozP@AkE>>VQ^(0Qfui{dU$YXgUA#1 zyivFt7d;od|Iv#RX&hdt>YE7S`XC|?NvYRwE|iJt$7lgfWk{4BlIldVE5UcG N`=!3)Tf=dY{R^K+djJ3c diff --git a/test/rbenv.bats b/test/rbenv.bats index e7cea6f0..5b52adc1 100644 --- a/test/rbenv.bats +++ b/test/rbenv.bats @@ -68,3 +68,8 @@ load test_helper assert_line 1 "/other/hooks" assert_line 2 "${RBENV_ROOT}/rbenv.d" } + +@test "RBENV_HOOK_PATH includes rbenv built-in plugins" { + run rbenv echo "RBENV_HOOK_PATH" + assert_success ":${RBENV_ROOT}/rbenv.d:${BATS_TEST_DIRNAME%/*}/rbenv.d:/usr/local/etc/rbenv.d:/etc/rbenv.d:/usr/lib/rbenv/hooks" +} From 67f429c41de851052950ffdb372fda90a21a4356 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Thu, 16 Oct 2014 16:33:22 +0200 Subject: [PATCH 375/384] Bring automatic gem-rehash functionality to rbenv core This bakes in the functionality of rbenv-gem-rehash plugin. The Rubygems hook is improved: - It will not rehash for gems installed in locations that rbenv otherwise doesn't search for binstubs; for instance in case of `bundle --path vendor/bundle`. - It rescues exceptions and makes them non-lethal by warning on stderr. --- rbenv.d/exec/gem-rehash.bash | 1 + rbenv.d/exec/gem-rehash/rubygems_plugin.rb | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 rbenv.d/exec/gem-rehash.bash create mode 100644 rbenv.d/exec/gem-rehash/rubygems_plugin.rb diff --git a/rbenv.d/exec/gem-rehash.bash b/rbenv.d/exec/gem-rehash.bash new file mode 100644 index 00000000..99614b53 --- /dev/null +++ b/rbenv.d/exec/gem-rehash.bash @@ -0,0 +1 @@ +export RUBYLIB="${BASH_SOURCE%.bash}:$RUBYLIB" diff --git a/rbenv.d/exec/gem-rehash/rubygems_plugin.rb b/rbenv.d/exec/gem-rehash/rubygems_plugin.rb new file mode 100644 index 00000000..e1d7b262 --- /dev/null +++ b/rbenv.d/exec/gem-rehash/rubygems_plugin.rb @@ -0,0 +1,18 @@ +hook = lambda do |installer| + begin + # Ignore gems that aren't installed in locations that rbenv searches for binstubs + if installer.spec.executables.any? && + [Gem.default_bindir, Gem.bindir(Gem.user_dir)].include?(installer.bin_dir) + system "rbenv", "rehash" + end + rescue + warn "rbenv: error in gem-rehash (#{$!})" + end +end + +begin + Gem.post_install(&hook) + Gem.post_uninstall(&hook) +rescue + warn "rbenv: error installing gem-rehash hooks (#{$!})" +end From 7e0e85bdda092d94aef0374af720682c6ea8999d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Sun, 19 Oct 2014 18:06:09 +0200 Subject: [PATCH 376/384] Avoid JRuby warning during rehash Rubygems plugin As it seems, JRuby 1.7 complains on stderr every time you invoke `system`: warning: executable? does not in this environment and will return a dummy value It doesn't seem to complain when backtics are used. It's safe to use backticks here because `rbenv rehash` doesn't output anything on stdout, and the exit status of the command is irrelevant. --- rbenv.d/exec/gem-rehash/rubygems_plugin.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rbenv.d/exec/gem-rehash/rubygems_plugin.rb b/rbenv.d/exec/gem-rehash/rubygems_plugin.rb index e1d7b262..21d5ad9a 100644 --- a/rbenv.d/exec/gem-rehash/rubygems_plugin.rb +++ b/rbenv.d/exec/gem-rehash/rubygems_plugin.rb @@ -3,7 +3,7 @@ hook = lambda do |installer| # Ignore gems that aren't installed in locations that rbenv searches for binstubs if installer.spec.executables.any? && [Gem.default_bindir, Gem.bindir(Gem.user_dir)].include?(installer.bin_dir) - system "rbenv", "rehash" + `rbenv rehash` end rescue warn "rbenv: error in gem-rehash (#{$!})" From 6820704c91afdd875e2a11bc647659c4d557aa5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Thu, 29 Jan 2015 01:55:58 -0800 Subject: [PATCH 377/384] Remove warning about extraneous "ruby-" prefix in `.ruby-version` When we started to support reading `.ruby-version` files, we made a commitment to not support fuzzy version matching. Treating "ruby-2.1.5" as "2.1.5" is a sort of fuzzy matching, so we put in place a warning telling you to remove the extraneous "ruby-" prefix popularly used by other Ruby version managers to denote MRI. (Their logic is that MRI is "ruby" and other rubies are not "ruby", apparently.) However, people are often not able to remove the prefix in their projects because they want to support other coworkers and tools that sadly still require the prefix, like RubyMine. So to restore sanity for a big portion of our users, the warning is gone. --- libexec/rbenv-version-name | 3 --- test/version-name.bats | 6 +----- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/libexec/rbenv-version-name b/libexec/rbenv-version-name index 3eef70a8..3769a7cd 100755 --- a/libexec/rbenv-version-name +++ b/libexec/rbenv-version-name @@ -21,9 +21,6 @@ version_exists() { if version_exists "$RBENV_VERSION"; then echo "$RBENV_VERSION" elif version_exists "${RBENV_VERSION#ruby-}"; then - { echo "warning: ignoring extraneous \`ruby-' prefix in version \`${RBENV_VERSION}'" - echo " (set by $(rbenv-version-origin))" - } >&2 echo "${RBENV_VERSION#ruby-}" else echo "rbenv: version \`$RBENV_VERSION' is not installed" >&2 diff --git a/test/version-name.bats b/test/version-name.bats index 3f4d9b36..d6438b5b 100644 --- a/test/version-name.bats +++ b/test/version-name.bats @@ -57,9 +57,5 @@ setup() { cat > ".ruby-version" <<<"ruby-1.8.7" run rbenv-version-name assert_success - assert_output < Date: Thu, 29 Jan 2015 02:09:05 -0800 Subject: [PATCH 378/384] Remove rbenv version history from README We won't maintain it anymore. Instead, the changelogs can be obtained from the project's Releases page: https://github.com/sstephenson/rbenv/releases --- README.md | 126 ------------------------------------------------------ 1 file changed, 126 deletions(-) diff --git a/README.md b/README.md index 7999645f..9988c45c 100644 --- a/README.md +++ b/README.md @@ -419,132 +419,6 @@ Tests are executed using [Bats](https://github.com/sstephenson/bats): Please feel free to submit pull requests and file bugs on the [issue tracker](https://github.com/sstephenson/rbenv/issues). -### Version History - -**0.4.0** (January 4, 2013) - -* rbenv now prefers `.ruby-version` files to `.rbenv-version` files - for specifying local application-specific versions. The - `.ruby-version` file has the same format as `.rbenv-version` but is - [compatible with other Ruby version - managers](https://gist.github.com/1912050). -* Deprecated `ruby-local-exec` and moved its functionality into the - standard `ruby` shim. See the [ruby-local-exec wiki - page](https://github.com/sstephenson/rbenv/wiki/ruby-local-exec) for - upgrade instructions. -* Modified shims to include the full path to rbenv so that they can be - invoked without having rbenv's bin directory in the `$PATH`. -* Sped up `rbenv init` by avoiding rbenv reinitialization and by - using a simpler indexing approach. (Users of - [chef-rbenv](https://github.com/fnichol/chef-rbenv) should upgrade - to the latest version to fix a [compatibility - issue](https://github.com/fnichol/chef-rbenv/pull/26).) -* Reworked `rbenv help` so that usage and documentation is stored as a - comment in each subcommand, enabling plugin commands to hook into - the help system. -* Added support for full completion of the command line, not just the - first argument. -* Updated installation instructions for Zsh and Ubuntu users. -* Fixed `rbenv which` and `rbenv prefix` with system Ruby versions. -* Changed `rbenv exec` to avoid prepending the system Ruby location to - `$PATH` to fix issues running system Ruby commands that invoke other - commands. -* Changed `rbenv rehash` to ensure it exits with a 0 status code under - normal operation, and to ensure outdated shims are removed first - when rehashing. -* Modified `rbenv rehash` to run `hash -r` afterwards, when shell - integration is enabled, to ensure the shell's command cache is - cleared. -* Removed use of the `+=` operator to support older versions of Bash. -* Adjusted non-bare `rbenv versions` output to include `system`, if - present. -* Improved documentation for installing and uninstalling Ruby - versions. -* Fixed `rbenv versions` not to display a warning if the currently - specified version doesn't exist. -* Fixed an instance of local variable leakage in the `rbenv` shell - function wrapper. -* Changed `rbenv shell` to ensure it exits with a non-zero status on - failure. -* Added `rbenv --version` for printing the current version of rbenv. -* Added `/usr/lib/rbenv/hooks` to the plugin hook search path. -* Fixed `rbenv which` to account for path entries with spaces. -* Changed `rbenv init` to accept option arguments in any order. - -**0.3.0** (December 25, 2011) - -* Added an `rbenv root` command which prints the value of - `$RBENV_ROOT`, or the default root directory if it's unset. -* Clarified Zsh installation instructions in the Readme. -* Removed some redundant code in `rbenv rehash`. -* Fixed an issue with calling `readlink` for paths with spaces. -* Changed Zsh initialization code to install completion hooks only for - interactive shells. -* Added preliminary support for ksh. -* `rbenv rehash` creates or removes shims only when necessary instead - of removing and re-creating all shims on each invocation. -* Fixed that `RBENV_DIR`, when specified, would be incorrectly - expanded to its parent directory. -* Removed the deprecated `set-default` and `set-local` commands. -* Added a `--no-rehash` option to `rbenv init` for skipping the - automatic rehash when opening a new shell. - -**0.2.1** (October 1, 2011) - -* Changed the `rbenv` command to ensure that `RBENV_DIR` is always an - absolute path. This fixes an issue where Ruby scripts using the - `ruby-local-exec` wrapper would go into an infinite loop when - invoked with a relative path from the command line. - -**0.2.0** (September 28, 2011) - -* Renamed `rbenv set-default` to `rbenv global` and `rbenv set-local` - to `rbenv local`. The `set-` commands are deprecated and will be - removed in the next major release. -* rbenv now uses `greadlink` on Solaris. -* Added a `ruby-local-exec` command which can be used in shebangs in - place of `#!/usr/bin/env ruby` to properly set the project-specific - Ruby version regardless of current working directory. -* Fixed an issue with `rbenv rehash` when no binaries are present. -* Added support for `rbenv-sh-*` commands, which run inside the - current shell instead of in a child process. -* Added an `rbenv shell` command for conveniently setting the - `$RBENV_VERSION` environment variable. -* Added support for storing rbenv versions and shims in directories - other than `~/.rbenv` with the `$RBENV_ROOT` environment variable. -* Added support for debugging rbenv via `set -x` when the - `$RBENV_DEBUG` environment variable is set. -* Refactored the autocompletion system so that completions are now - built-in to each command and shared between bash and Zsh. -* Added support for plugin bundles in `~/.rbenv/plugins` as documented - in [issue #102](https://github.com/sstephenson/rbenv/pull/102). -* Added `/usr/local/etc/rbenv.d` to the list of directories searched - for rbenv hooks. -* Added support for an `$RBENV_DIR` environment variable which - defaults to the current working directory for specifying where rbenv - searches for local version files. - -**0.1.2** (August 16, 2011) - -* Fixed rbenv to be more resilient against nonexistent entries in - `$PATH`. -* Made the `rbenv rehash` command operate atomically. -* Modified the `rbenv init` script to automatically run `rbenv - rehash` so that shims are recreated whenever a new shell is opened. -* Added initial support for Zsh autocompletion. -* Removed the dependency on egrep for reading version files. - -**0.1.1** (August 14, 2011) - -* Fixed a syntax error in the `rbenv help` command. -* Removed `-e` from the shebang in favor of `set -e` at the top of - each file for compatibility with operating systems that do not - support more than one argument in the shebang. - -**0.1.0** (August 11, 2011) - -* Initial public release. - ### License (The MIT license) From b155380a06be671b77f204e17a37ef8d745cb789 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Thu, 29 Jan 2015 02:10:28 -0800 Subject: [PATCH 379/384] Remove license information from README The license information is already present in the LICENSE file. --- README.md | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/README.md b/README.md index 9988c45c..702174f9 100644 --- a/README.md +++ b/README.md @@ -419,30 +419,5 @@ Tests are executed using [Bats](https://github.com/sstephenson/bats): Please feel free to submit pull requests and file bugs on the [issue tracker](https://github.com/sstephenson/rbenv/issues). -### License - -(The MIT license) - -Copyright (c) 2013 Sam Stephenson - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - [ruby-build]: https://github.com/sstephenson/ruby-build#readme From 70c6d3f67edfcf19ee902d39d6578a537f798ccf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Pineau?= Date: Mon, 16 Feb 2015 04:03:08 +0100 Subject: [PATCH 380/384] [README] Updated link to bundler.io --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7999645f..608e1ee1 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Use rbenv to pick a Ruby version for your application and guarantee that your development environment matches production. Put rbenv to work -with [Bundler](http://gembundler.com/) for painless Ruby upgrades and +with [Bundler](http://bundler.io/) for painless Ruby upgrades and bulletproof deployments. **Powerful in development.** Specify your app's Ruby version once, From 9ae8ba8a2990cbeedcb391467ad509606cbcd6e5 Mon Sep 17 00:00:00 2001 From: Adam Prescott Date: Mon, 16 Feb 2015 10:56:38 -0500 Subject: [PATCH 381/384] Update README to make rbenv version consistent with previous `versions` output The `rbenv versions` info highlights 1.9.3-p327 as the current version, and making `rbenv version` sample output match that helps make it clearer. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 608e1ee1..acd32729 100644 --- a/README.md +++ b/README.md @@ -378,7 +378,7 @@ Displays the currently active Ruby version, along with information on how it was set. $ rbenv version - 1.8.7-p352 (set by /Volumes/37signals/basecamp/.ruby-version) + 1.9.3-p327 (set by /Users/sam/.rbenv/version) ### rbenv rehash From c54fa3731fd14b3749d211ccd9481713bf644b65 Mon Sep 17 00:00:00 2001 From: Lorenzo Manacorda Date: Thu, 26 Feb 2015 11:39:31 +0100 Subject: [PATCH 382/384] Remove dead links to Version history and License Cfr. #688 --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index 397d0c86..905cc02c 100644 --- a/README.md +++ b/README.md @@ -55,8 +55,6 @@ RVM?**](https://github.com/sstephenson/rbenv/wiki/Why-rbenv%3F) * [rbenv which](#rbenv-which) * [rbenv whence](#rbenv-whence) * [Development](#development) - * [Version History](#version-history) - * [License](#license) ## How It Works From 6b908bf39f383fdc5332604d2705d1b652ee5440 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Fri, 27 Feb 2015 02:08:38 +1300 Subject: [PATCH 383/384] Opt into fast Travis CI builds --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 95b46cc2..d1369089 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,4 @@ +sudo: false install: git clone https://github.com/sstephenson/bats.git script: PATH="./bats/bin:$PATH" test/run language: c From b6ac87c220672acfa70ee2dbf43c42d77c0e2590 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Fri, 27 Feb 2015 02:17:31 +1300 Subject: [PATCH 384/384] Faster bats clone --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index d1369089..acc69ef2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,5 @@ sudo: false -install: git clone https://github.com/sstephenson/bats.git +install: git clone --depth 1 https://github.com/sstephenson/bats.git script: PATH="./bats/bin:$PATH" test/run language: c env: