From 5c1094adb9f119f14820bc8ab408f911a7d85f3d Mon Sep 17 00:00:00 2001 From: kou1okada Date: Thu, 9 Jan 2014 15:31:29 +0900 Subject: [PATCH 01/40] Response enhancement for in the case of the working directory under the UNC path. finding_local_version_file is extremely slow, when working directory is under the UNC path. Because //host/.rbenv-version and //.rbenv-version do not exist, but testing them is so slow. It's the reason to make a serious delay of the response, when the Ruby runs with a current working directory under the UNC path under Cygwin environment. A response of before applying this patch. //somehost/somedir $ time ruby -e "exit" real 0m13.922s user 0m0.168s sys 0m0.287s A response of after applying this patch. //somehost/somedir $ time ruby -e "exit" real 0m0.721s user 0m0.153s sys 0m0.319s --- libexec/rbenv-version-file | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libexec/rbenv-version-file b/libexec/rbenv-version-file index 2413834f..f1cfbd2a 100755 --- a/libexec/rbenv-version-file +++ b/libexec/rbenv-version-file @@ -5,7 +5,7 @@ set -e find_local_version_file() { local root="$1" - while [ -n "$root" ]; do + while [[ -n "$root" && ! "$root" =~ ^//[^/]*$ ]]; do if [ -e "${root}/.ruby-version" ]; then echo "${root}/.ruby-version" exit From 024bee1a6f62d370dfaf952bc60b7ff0b3e431f2 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Thu, 13 Mar 2014 20:40:47 +0100 Subject: [PATCH 02/40] Use `mktemp -d` for RBENV_TEST_DIR This prevents the tests from removing an existing directory. Fixes #561 (https://github.com/sstephenson/rbenv/issues/561) --- test/test_helper.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_helper.bash b/test/test_helper.bash index 53ae8e64..24e8ffea 100644 --- a/test/test_helper.bash +++ b/test/test_helper.bash @@ -1,7 +1,7 @@ unset RBENV_VERSION unset RBENV_DIR -RBENV_TEST_DIR="${BATS_TMPDIR}/rbenv" +RBENV_TEST_DIR="$(mktemp -d --tmpdir=$BATS_TMPDIR rbenv.bats.XXX)" # guard against executing this block twice due to bats internals if [ "$RBENV_ROOT" != "${RBENV_TEST_DIR}/root" ]; then From c9a96c9f79c1cce3d4b44e59b789ca92e0053937 Mon Sep 17 00:00:00 2001 From: Kevin Burke Date: Fri, 28 Nov 2014 21:16:14 -0800 Subject: [PATCH 03/40] Use `command` to run rbenv rehash In the event that `eval "$(rbenv init -)"` is called from a function named rbenv (which I do to get rbenv to load lazily in my shell), evaluating the phrase `rbenv rehash` will cause the outer function to run again (causing an infinite loop). This change makes it clear you want the command named rbenv and not a function which may exist in the environment. --- libexec/rbenv-init | 2 +- test/init.bats | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libexec/rbenv-init b/libexec/rbenv-init index 0b2c13aa..867b3bb8 100755 --- a/libexec/rbenv-init +++ b/libexec/rbenv-init @@ -88,7 +88,7 @@ if [ -r "$completion" ]; then fi if [ -z "$no_rehash" ]; then - echo 'rbenv rehash 2>/dev/null' + echo 'command rbenv rehash 2>/dev/null' fi commands=(`rbenv-commands --sh`) diff --git a/test/init.bats b/test/init.bats index 95db0fec..b59b8086 100644 --- a/test/init.bats +++ b/test/init.bats @@ -14,7 +14,7 @@ load test_helper @test "auto rehash" { run rbenv-init - assert_success - assert_line "rbenv rehash 2>/dev/null" + assert_line "command rbenv rehash 2>/dev/null" } @test "setup shell completions" { From 55341f4436c76640cfe4c775ebb1b990d604c3bc Mon Sep 17 00:00:00 2001 From: No GUI Date: Tue, 20 Jan 2015 13:21:22 -0700 Subject: [PATCH 04/40] Include gems dir in .gitignore Since communal-gems is maintainer-approved, thought it would be useful to include the directory it uses in the ignore list. (This also helps me, since I install rbenv as submodule and without this entry, the submodule is perpetually marked dirty.) --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 84639e79..00f2f052 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ /libexec/*.dylib /src/Makefile /src/*.o +/gems From 050f75056389d79780b76c4d37ad596903e2fdfa Mon Sep 17 00:00:00 2001 From: "Mark H. Wilkinson" Date: Wed, 11 Mar 2015 13:14:52 +0000 Subject: [PATCH 05/40] Fix pattern replacement to allow flags with commas. --- src/configure | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/configure b/src/configure index dc29eb79..86e25ac1 100755 --- a/src/configure +++ b/src/configure @@ -39,8 +39,8 @@ sed " 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_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 From 7ad01b2b485fb635d7a96daef33f6a733e5b1c80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Fri, 13 Mar 2015 01:14:24 -0700 Subject: [PATCH 06/40] Document rbenv environment variables Closes #699, fixes #666 [ci skip] --- README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/README.md b/README.md index 905cc02c..7cad9055 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,7 @@ RVM?**](https://github.com/sstephenson/rbenv/wiki/Why-rbenv%3F) * [rbenv rehash](#rbenv-rehash) * [rbenv which](#rbenv-which) * [rbenv whence](#rbenv-whence) +* [Environment variables](#environment-variables) * [Development](#development) ## How It Works @@ -403,6 +404,18 @@ Lists all Ruby versions with the given command installed. jruby-1.7.1 ree-1.8.7-2011.03 +## Environment variables + +You can affect how rbenv operates with the following settings: + +name | default | description +-----|---------|------------ +`RBENV_VERSION` | | Specifies the Ruby version to be used.
Also see [`rbenv shell`](#rbenv-shell) +`RBENV_ROOT` | `~/.rbenv` | Defines the directory under which Ruby versions and shims reside.
Also see `rbenv root` +`RBENV_DEBUG` | | Outputs debug information.
Also as: `rbenv --debug ` +`RBENV_HOOK_PATH` | [_see wiki_][hooks] | Colon-separated list of paths searched for rbenv hooks. +`RBENV_DIR` | `$PWD` | Directory to start searching for `.ruby-version` files. + ## Development The rbenv source code is [hosted on @@ -419,3 +432,4 @@ tracker](https://github.com/sstephenson/rbenv/issues). [ruby-build]: https://github.com/sstephenson/ruby-build#readme + [hooks]: https://github.com/sstephenson/rbenv/wiki/Authoring-plugins#rbenv-hooks From 06c1959e785e4f4043e9697f04c0cb5906fd6241 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Sun, 19 Apr 2015 23:53:19 +0200 Subject: [PATCH 07/40] Fix test for adding shims in fish Commit e2173df4 (for issue #369) did not handle the fish test properly. This renames it and fixes the assertion. --- test/init.bats | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/init.bats b/test/init.bats index 95db0fec..32b32f60 100644 --- a/test/init.bats +++ b/test/init.bats @@ -71,11 +71,11 @@ load test_helper assert_line 0 'export PATH="'${RBENV_ROOT}'/shims:${PATH}"' } -@test "doesn't add shims to PATH more than once (fish)" { +@test "can add shims to PATH more than once (fish)" { export PATH="${RBENV_ROOT}/shims:$PATH" run rbenv-init - fish assert_success - refute_line 'setenv PATH "'${RBENV_ROOT}'/shims" $PATH ;' + assert_line 0 "setenv PATH '${RBENV_ROOT}/shims' \$PATH" } @test "outputs sh-compatible syntax" { From 4ea7d0849be6d0383ddd6c95301b5f028e2cc59b Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Sun, 10 May 2015 16:17:35 +0200 Subject: [PATCH 08/40] rbenv-init: do not use basename for $shell This can be done using bash directly. --- libexec/rbenv-init | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libexec/rbenv-init b/libexec/rbenv-init index 0b2c13aa..83521d37 100755 --- a/libexec/rbenv-init +++ b/libexec/rbenv-init @@ -25,7 +25,8 @@ if [ -z "$shell" ]; then shell="$(ps c -p "$PPID" -o 'ucomm=' 2>/dev/null || true)" shell="${shell##-}" shell="${shell%% *}" - shell="$(basename "${shell:-$SHELL}")" + shell="${shell:-$SHELL}" + shell="${shell##*/}" fi root="${0%/*}/.." From 43b28caa9482badd990b6c7ef0fc37129f25904d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Tue, 9 Jun 2015 17:24:15 +0200 Subject: [PATCH 09/40] Fix discovering `.ruby-version` files in root directory It's not that this is a preferred way to set a global version (one should use `rbenv global ` instead), but this fixes the function purely for correctness: all parent directories should be scanned, even the root directory. Fixes #745 --- libexec/rbenv-version-file | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libexec/rbenv-version-file b/libexec/rbenv-version-file index 2413834f..7a2b9c6e 100755 --- a/libexec/rbenv-version-file +++ b/libexec/rbenv-version-file @@ -5,7 +5,7 @@ set -e find_local_version_file() { local root="$1" - while [ -n "$root" ]; do + while true; do if [ -e "${root}/.ruby-version" ]; then echo "${root}/.ruby-version" exit @@ -13,6 +13,7 @@ find_local_version_file() { echo "${root}/.rbenv-version" exit fi + [ -n "$root" ] || break root="${root%/*}" done } From 46fbc5414a83885a7356ad3d030ad2692832a1c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Tue, 9 Jun 2015 23:27:21 +0200 Subject: [PATCH 10/40] Provide uninstall instructions in the README --- README.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/README.md b/README.md index 7cad9055..b32e4102 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,7 @@ RVM?**](https://github.com/sstephenson/rbenv/wiki/Why-rbenv%3F) * [How rbenv hooks into your shell](#how-rbenv-hooks-into-your-shell) * [Installing Ruby Versions](#installing-ruby-versions) * [Uninstalling Ruby Versions](#uninstalling-ruby-versions) + * [Uninstalling rbenv](#uninstalling-rbenv) * [Command Reference](#command-reference) * [rbenv local](#rbenv-local) * [rbenv global](#rbenv-global) @@ -298,6 +299,30 @@ Ruby version with the `rbenv prefix` command, e.g. `rbenv prefix The [ruby-build][] plugin provides an `rbenv uninstall` command to automate the removal process. +### Uninstalling rbenv + +The simplicity of rbenv makes it easy to temporarily disable it, or +uninstall from the system. + +1. To **disable** rbenv managing your Ruby versions, simply remove the + `rbenv init` line from your shell startup configuration. This will + remove rbenv shims directory from PATH, and future invocations like + `ruby` will execute the system Ruby version, as before rbenv. + + `rbenv` will still be accessible on the command line, but your Ruby + apps won't be affected by version switching. + +2. To completely **uninstall** rbenv, perform step (1) and then remove + its root directory. This will **delete all Ruby versions** that were + installed under `` `rbenv root`/versions/ `` directory: + + rm -rf `rbenv root` + + If you've installed rbenv using a package manager, as a final step + perform the rbenv package removal. For instance, for Homebrew: + + brew uninstall rbenv + ## Command Reference Like `git`, the `rbenv` command delegates to subcommands based on its From e3982fae388cebf981fdec880bd460d31f5ca941 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Fri, 17 Jul 2015 17:10:33 +0200 Subject: [PATCH 11/40] Display version origin with non-installed versions This is useful as an indicator where it is coming from. --- libexec/rbenv-version-name | 2 +- libexec/rbenv-which | 2 +- test/exec.bats | 2 +- test/version-name.bats | 2 +- test/which.bats | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/libexec/rbenv-version-name b/libexec/rbenv-version-name index 3769a7cd..90609d7f 100755 --- a/libexec/rbenv-version-name +++ b/libexec/rbenv-version-name @@ -23,6 +23,6 @@ if version_exists "$RBENV_VERSION"; then elif version_exists "${RBENV_VERSION#ruby-}"; then echo "${RBENV_VERSION#ruby-}" else - echo "rbenv: version \`$RBENV_VERSION' is not installed" >&2 + echo "rbenv: version \`$RBENV_VERSION' is not installed (set by $(rbenv-version-origin))" >&2 exit 1 fi diff --git a/libexec/rbenv-which b/libexec/rbenv-which index 3cf91de7..8019be21 100755 --- a/libexec/rbenv-which +++ b/libexec/rbenv-which @@ -52,7 +52,7 @@ 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 + echo "rbenv: version \`$RBENV_VERSION' is not installed (set by $(rbenv-version-origin))" >&2 exit 1 else echo "rbenv: $RBENV_COMMAND: command not found" >&2 diff --git a/test/exec.bats b/test/exec.bats index 889eb897..ff1e248d 100644 --- a/test/exec.bats +++ b/test/exec.bats @@ -17,7 +17,7 @@ create_executable() { @test "fails with invalid version" { export RBENV_VERSION="2.0" run rbenv-exec ruby -v - assert_failure "rbenv: version \`2.0' is not installed" + assert_failure "rbenv: version \`2.0' is not installed (set by RBENV_VERSION environment variable)" } @test "completes with names of executables" { diff --git a/test/version-name.bats b/test/version-name.bats index d6438b5b..8d61ac55 100644 --- a/test/version-name.bats +++ b/test/version-name.bats @@ -49,7 +49,7 @@ setup() { @test "missing version" { RBENV_VERSION=1.2 run rbenv-version-name - assert_failure "rbenv: version \`1.2' is not installed" + assert_failure "rbenv: version \`1.2' is not installed (set by RBENV_VERSION environment variable)" } @test "version with prefix in name" { diff --git a/test/which.bats b/test/which.bats index 3f68a31a..bf10effe 100644 --- a/test/which.bats +++ b/test/which.bats @@ -59,7 +59,7 @@ create_executable() { @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" + assert_failure "rbenv: version \`1.9' is not installed (set by RBENV_VERSION environment variable)" } @test "no executable found" { From 9e664b5d27cd7b2bdb94a9ec8ce55c32ebe1ad7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Sat, 12 Sep 2015 15:27:32 -0700 Subject: [PATCH 12/40] Suggest that rbenv should be loaded at end of shell rc file Closes #725 --- libexec/rbenv-init | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libexec/rbenv-init b/libexec/rbenv-init index 0b2c13aa..d0daa682 100755 --- a/libexec/rbenv-init +++ b/libexec/rbenv-init @@ -49,7 +49,7 @@ if [ -z "$print" ]; then ;; esac - { echo "# Load rbenv automatically by adding" + { echo "# Load rbenv automatically by appending" echo "# the following to ${profile}:" echo case "$shell" in From 3a265c1af9daebd09aa36a4ce27c3f766a33f151 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Sat, 10 Oct 2015 18:30:44 +0200 Subject: [PATCH 13/40] Unset XDG_CONFIG_HOME and related variables during tests If set by the user's environment, `git config --global` writes will go to that destination instead of temporary $HOME. We definitely don't want that. Fixes #742 --- test/test_helper.bash | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/test_helper.bash b/test/test_helper.bash index 461bb085..5fac8bb3 100644 --- a/test/test_helper.bash +++ b/test/test_helper.bash @@ -22,6 +22,9 @@ if [ "$RBENV_ROOT" != "${RBENV_TEST_DIR}/root" ]; then PATH="${BATS_TEST_DIRNAME}/libexec:$PATH" PATH="${RBENV_ROOT}/shims:$PATH" export PATH + + for xdg_var in `env 2>/dev/null | grep ^XDG_ | cut -d= -f1`; do unset "$xdg_var"; done + unset xdg_var fi teardown() { From 8a0555f8ef03ac4b169a87d0ac9de4b7ddd88d00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Sat, 10 Oct 2015 19:02:11 +0200 Subject: [PATCH 14/40] Init RBENV_TEST_DIR properly and only once during test setup --- test/test_helper.bash | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/test/test_helper.bash b/test/test_helper.bash index f9150792..0c21dea7 100644 --- a/test/test_helper.bash +++ b/test/test_helper.bash @@ -1,18 +1,20 @@ unset RBENV_VERSION 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="$(mktemp -d --tmpdir=$BATS_TMPDIR rbenv.bats.XXX)" -fi - # guard against executing this block twice due to bats internals -if [ "$RBENV_ROOT" != "${RBENV_TEST_DIR}/root" ]; then +if [ -z "$RBENV_TEST_DIR" ]; then + RBENV_TEST_DIR="${BATS_TMPDIR}/rbenv" + export RBENV_TEST_DIR="$(mktemp -d "${RBENV_TEST_DIR}.XXX" 2>/dev/null || echo "$RBENV_TEST_DIR")" + + if enable -f "${BATS_TEST_DIRNAME}"/../libexec/rbenv-realpath.dylib realpath 2>/dev/null; then + export RBENV_TEST_DIR="$(realpath "$RBENV_TEST_DIR")" + else + if [ -n "$RBENV_NATIVE_EXT" ]; then + echo "rbenv: failed to load \`realpath' builtin" >&2 + exit 1 + fi + fi + export RBENV_ROOT="${RBENV_TEST_DIR}/root" export HOME="${RBENV_TEST_DIR}/home" From c101052a7fb6b5757083f41d139109f4a991508e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Sat, 10 Oct 2015 21:48:40 +0200 Subject: [PATCH 15/40] Fix eval'ing multiline `sh-*` command output with fish --- libexec/rbenv-init | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libexec/rbenv-init b/libexec/rbenv-init index 76540f9f..13cd237c 100755 --- a/libexec/rbenv-init +++ b/libexec/rbenv-init @@ -102,7 +102,7 @@ function rbenv switch "\$command" case ${commands[*]} - eval (rbenv "sh-\$command" \$argv) + . (rbenv "sh-\$command" \$argv|psub) case '*' command rbenv "\$command" \$argv end From 0f44c57d0868885fd20e11348f73b575035696ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Mon, 12 Oct 2015 01:31:57 +0200 Subject: [PATCH 16/40] Fix eval'ing multiline `sh-*` command output with bash --- libexec/rbenv-init | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libexec/rbenv-init b/libexec/rbenv-init index d0027680..29f521f3 100755 --- a/libexec/rbenv-init +++ b/libexec/rbenv-init @@ -133,7 +133,7 @@ cat < Date: Sun, 25 Oct 2015 16:54:38 +0100 Subject: [PATCH 17/40] Improve `rbenv --version` git checkout discovery When `rbenv --version` is called, this now happens: 1. It changes into the directory where `libexec/rbenv--version` resides and checks if it's a checkout of the rbenv repo (as opposed to Homebrew checkout or something else). Then it reads the git revision. 2. If that failed, change to `$RBENV_ROOT` directory and repeat step 1. --- libexec/rbenv---version | 12 ++++++++---- test/--version.bats | 28 ++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/libexec/rbenv---version b/libexec/rbenv---version index 79cb64d8..1254a2fd 100755 --- a/libexec/rbenv---version +++ b/libexec/rbenv---version @@ -13,10 +13,14 @@ set -e [ -n "$RBENV_DEBUG" ] && set -x version="0.4.0" +git_revision="" -if cd "$RBENV_ROOT" 2>/dev/null; then - git_revision="$(git describe --tags HEAD 2>/dev/null || true)" - git_revision="${git_revision#v}" -fi +for source_dir in "${BASH_SOURCE%/*}" "$RBENV_ROOT"; do + if cd "$source_dir" 2>/dev/null && git remote -v 2>/dev/null | grep -q rbenv; then + git_revision="$(git describe --tags HEAD 2>/dev/null || true)" + git_revision="${git_revision#v}" + [ -z "$git_revision" ] || break + fi +done echo "rbenv ${git_revision:-$version}" diff --git a/test/--version.bats b/test/--version.bats index 4e0e452d..9993e6dc 100644 --- a/test/--version.bats +++ b/test/--version.bats @@ -6,6 +6,18 @@ setup() { mkdir -p "$HOME" git config --global user.name "Tester" git config --global user.email "tester@test.local" + + mkdir -p "${RBENV_TEST_DIR}/bin" + cat > "${RBENV_TEST_DIR}/bin/git" <&2 + exit 1 +else + exec $(which git) "\$@" +fi +CMD + chmod +x "${RBENV_TEST_DIR}/bin/git" } git_commit() { @@ -19,10 +31,25 @@ git_commit() { [[ $output == "rbenv 0."* ]] } +@test "doesn't read version from non-rbenv repo" { + mkdir -p "$RBENV_ROOT" + cd "$RBENV_ROOT" + git init + git remote add origin https://github.com/homebrew/homebrew.git + git_commit + git tag v1.0 + + cd "$RBENV_TEST_DIR" + run rbenv---version + assert_success + [[ $output == "rbenv 0."* ]] +} + @test "reads version from git repo" { mkdir -p "$RBENV_ROOT" cd "$RBENV_ROOT" git init + git remote add origin https://github.com/sstephenson/rbenv.git git_commit git tag v0.4.1 git_commit @@ -38,6 +65,7 @@ git_commit() { mkdir -p "$RBENV_ROOT" cd "$RBENV_ROOT" git init + git remote add origin https://github.com/sstephenson/rbenv.git git_commit cd "$RBENV_TEST_DIR" From 7b289bcee662929b46a9b27f966d93dd91c59efb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Sun, 19 Oct 2014 13:43:29 +0200 Subject: [PATCH 18/40] Avoid running `rbenv rehash` multiple times during `bundle install` This is an attempt to work around the fact that Rubygems post_install hooks may happen multiple times per single `bundle install` and ideally we want `rbenv rehash` to run only once if new gems have been installed. However, due to Bundler parallelism using `fork` on platforms that support it, it's impossible for the child processes to communicate with the master process to signal it to run `rbenv rehash` in the end. This hooks into Bundler `install` command and runs `rbenv rehash` after all gems have finished installing, but only if the install location was system gems location and not a custom path (such as per-project `vendor/bundle`). This is limited because we can't tell whether any gems have been installed at all, let alone do those gems have executables. However it's better than having multiple `rbenv rehash` being run in parallel and outputting confusing error messages as a result. --- rbenv.d/exec/gem-rehash/rubygems_plugin.rb | 31 +++++++++++++++++----- 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/rbenv.d/exec/gem-rehash/rubygems_plugin.rb b/rbenv.d/exec/gem-rehash/rubygems_plugin.rb index 21d5ad9a..8d1df091 100644 --- a/rbenv.d/exec/gem-rehash/rubygems_plugin.rb +++ b/rbenv.d/exec/gem-rehash/rubygems_plugin.rb @@ -6,13 +6,32 @@ hook = lambda do |installer| `rbenv rehash` end rescue - warn "rbenv: error in gem-rehash (#{$!})" + warn "rbenv: error in gem-rehash (#{$!.class.name}: #{$!.message})" end end -begin - Gem.post_install(&hook) - Gem.post_uninstall(&hook) -rescue - warn "rbenv: error installing gem-rehash hooks (#{$!})" +if defined?(Bundler::Installer) && Bundler::Installer.respond_to?(:install) + Bundler::Installer.class_eval do + class << self + alias install_without_rbenv_rehash install + def install(root, definition, options = {}) + result = install_without_rbenv_rehash(root, definition, options) + begin + if result && Gem.default_path.include?(Bundler.bundle_path.to_s) + `rbenv rehash` + end + rescue + warn "rbenv: error in Bundler post-install hook (#{$!.class.name}: #{$!.message})" + end + result + end + end + end +else + begin + Gem.post_install(&hook) + Gem.post_uninstall(&hook) + rescue + warn "rbenv: error installing gem-rehash hooks (#{$!.class.name}: #{$!.message})" + end end From 2b0f16757ac855c1fc603adb1cc8577cf15be3cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Sun, 25 Oct 2015 18:31:50 +0100 Subject: [PATCH 19/40] Only rehash if `bundle install` actually created new executables This avoids running `rbenv rehash` after installing libraries that don't have executables, or after a no-op `bundle install` that didn't install anything. --- rbenv.d/exec/gem-rehash/rubygems_plugin.rb | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/rbenv.d/exec/gem-rehash/rubygems_plugin.rb b/rbenv.d/exec/gem-rehash/rubygems_plugin.rb index 8d1df091..0f718b13 100644 --- a/rbenv.d/exec/gem-rehash/rubygems_plugin.rb +++ b/rbenv.d/exec/gem-rehash/rubygems_plugin.rb @@ -15,14 +15,20 @@ if defined?(Bundler::Installer) && Bundler::Installer.respond_to?(:install) class << self alias install_without_rbenv_rehash install def install(root, definition, options = {}) - result = install_without_rbenv_rehash(root, definition, options) begin - if result && Gem.default_path.include?(Bundler.bundle_path.to_s) - `rbenv rehash` + if Gem.default_path.include?(Bundler.bundle_path.to_s) + bin_dir = Gem.bindir(Bundler.bundle_path.to_s) + bins_before = File.exist?(bin_dir) ? Dir.entries(bin_dir).size : 2 end rescue warn "rbenv: error in Bundler post-install hook (#{$!.class.name}: #{$!.message})" end + + result = install_without_rbenv_rehash(root, definition, options) + + if bin_dir && File.exist?(bin_dir) && Dir.entries(bin_dir).size > bins_before + `rbenv rehash` + end result end end From 6913fee89aad51a8175c1a14fe9fb9bc295d4437 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Mon, 26 Oct 2015 15:45:52 +0100 Subject: [PATCH 20/40] If there is `.bashrc` but no `.bash_profile`, recommend the former This is for Linux desktop platforms that have Terminal application configured to start shells in interactive but not login mode. Creating a `~/.bash_profile` would also cause `~/.profile` to not run, which might be a problem on Ubuntu which ships with a default `~/.profile`. --- libexec/rbenv-init | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libexec/rbenv-init b/libexec/rbenv-init index 29f521f3..88f9e69c 100755 --- a/libexec/rbenv-init +++ b/libexec/rbenv-init @@ -34,7 +34,11 @@ root="${0%/*}/.." if [ -z "$print" ]; then case "$shell" in bash ) - profile='~/.bash_profile' + if [ -f "${HOME}/.bashrc" ] && [ ! -f "${HOME}/.bash_profile" ]; then + profile='~/.bashrc' + else + profile='~/.bash_profile' + fi ;; zsh ) profile='~/.zshrc' From d508822f9af75b72164e1fa375d8ad9b2ffb72dc Mon Sep 17 00:00:00 2001 From: Roman Sandler Date: Tue, 27 Oct 2015 09:24:04 +1100 Subject: [PATCH 21/40] Make sure the alias statement only executes if there is not already an alias in place --- 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 0f718b13..7ced31a9 100644 --- a/rbenv.d/exec/gem-rehash/rubygems_plugin.rb +++ b/rbenv.d/exec/gem-rehash/rubygems_plugin.rb @@ -10,7 +10,7 @@ hook = lambda do |installer| end end -if defined?(Bundler::Installer) && Bundler::Installer.respond_to?(:install) +if defined?(Bundler::Installer) && Bundler::Installer.respond_to?(:install) && !Bundler::Installer.respond_to?(:install_without_rbenv_rehash) Bundler::Installer.class_eval do class << self alias install_without_rbenv_rehash install From 6e02b944f7a42a393048fd188f9ec0e26fec93d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Mon, 26 Oct 2015 15:53:20 +0100 Subject: [PATCH 22/40] Use `$BASH_SOURCE` instead of `$0` BASH_SOURCE might be more reliable. --- libexec/rbenv | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libexec/rbenv b/libexec/rbenv index de7ea692..7be3eed7 100755 --- a/libexec/rbenv +++ b/libexec/rbenv @@ -12,7 +12,7 @@ if [ -n "$RBENV_DEBUG" ]; then set -x fi -if enable -f "${0%/*}"/../libexec/rbenv-realpath.dylib realpath 2>/dev/null; then +if enable -f "${BASH_SOURCE%/*}"/../libexec/rbenv-realpath.dylib realpath 2>/dev/null; then abs_dirname() { local path="$(realpath "$1")" echo "${path%/*}" From e80886e9bed1fb51d6df7d37725537fae875e3f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Tue, 27 Oct 2015 10:49:29 +0100 Subject: [PATCH 23/40] Add `rbenv versions --skip-aliases` option Useful in combination with `--bare` to list just the unique version numbers without the extra directory entries that are symlinks to other version numbers in the same directory. --- libexec/rbenv-rehash | 9 ++++--- libexec/rbenv-versions | 61 +++++++++++++++++++++++++++++++++++++++--- test/versions.bats | 15 +++++++++++ 3 files changed, 79 insertions(+), 6 deletions(-) diff --git a/libexec/rbenv-rehash b/libexec/rbenv-rehash index 19f9daa5..53ab045f 100755 --- a/libexec/rbenv-rehash +++ b/libexec/rbenv-rehash @@ -81,9 +81,12 @@ remove_outdated_shims() { # List basenames of executables for every Ruby version list_executable_names() { - local file - for file in "$RBENV_ROOT"/versions/*/bin/*; do - echo "${file##*/}" + local version file + rbenv-versions --bare --skip-aliases | \ + while read version; do + for file in "${RBENV_ROOT}/versions/${version}/bin/"*; do + echo "${file##*/}" + done done } diff --git a/libexec/rbenv-versions b/libexec/rbenv-versions index b35cef48..a80506a8 100755 --- a/libexec/rbenv-versions +++ b/libexec/rbenv-versions @@ -1,13 +1,64 @@ #!/usr/bin/env bash # Summary: List all Ruby versions available to rbenv -# Usage: rbenv versions [--bare] +# Usage: rbenv versions [--bare] [--skip-aliases] # # Lists all Ruby versions found in `$RBENV_ROOT/versions/*'. set -e [ -n "$RBENV_DEBUG" ] && set -x -if [ "$1" = "--bare" ]; then +unset bare +unset skip_aliases +for arg; do + case "$arg" in + --bare ) bare=1 ;; + --skip-aliases ) skip_aliases=1 ;; + * ) + rbenv-help --usage versions >&2 + exit 1 + ;; + esac +done + +versions_dir="${RBENV_ROOT}/versions" + +if ! enable -f "${BASH_SOURCE%/*}"/../libexec/rbenv-realpath.dylib realpath 2>/dev/null; then + if [ -n "$RBENV_NATIVE_EXT" ]; then + echo "rbenv: failed to load \`realpath' builtin" >&2 + exit 1 + fi + + READLINK=$(type -p greadlink readlink | head -1) + if [ -z "$READLINK" ]; then + echo "rbenv: cannot find readlink - are you missing GNU coreutils?" >&2 + exit 1 + fi + + resolve_link() { + $READLINK "$1" + } + + realpath() { + local cwd="$PWD" + local path="$1" + local name + + while [ -n "$path" ]; do + name="${path##*/}" + [ "$name" = "$path" ] || cd "${path%/*}" + path="$(resolve_link "$name" || true)" + done + + echo "${PWD}/$name" + cd "$cwd" + } +fi + +if [ -d "$versions_dir" ]; then + versions_dir="$(realpath "$versions_dir")" +fi + +if [ -n "$bare" ]; then hit_prefix="" miss_prefix="" current_version="" @@ -36,8 +87,12 @@ if [ -n "$include_system" ] && RBENV_VERSION=system rbenv-which ruby >/dev/null fi shopt -s nullglob -for path in "${RBENV_ROOT}/versions/"*; do +for path in "$versions_dir"/*; do if [ -d "$path" ]; then + if [ -n "$skip_aliases" ] && [ -L "$path" ]; then + target="$(realpath "$path")" + [ "${target%/*}" != "$versions_dir" ] || continue + fi print_version "${path##*/}" fi done diff --git a/test/versions.bats b/test/versions.bats index 5d79ed5a..3273b375 100644 --- a/test/versions.bats +++ b/test/versions.bats @@ -139,3 +139,18 @@ OUT 1.8.7 OUT } + +@test "doesn't list symlink aliases when --skip-aliases" { + create_version "1.8.7" + ln -s "1.8.7" "${RBENV_ROOT}/versions/1.8" + mkdir moo + ln -s "${PWD}/moo" "${RBENV_ROOT}/versions/1.9" + + run rbenv-versions --bare --skip-aliases + assert_success + + assert_output < Date: Tue, 27 Oct 2015 20:50:14 +0100 Subject: [PATCH 24/40] Fix `realpath` fallback in `rbenv hooks` The symlinks weren't correctly resolved if they were pointing to a single path component, such as `ln -s foo bar`. --- libexec/rbenv-hooks | 9 +++++---- test/hooks.bats | 8 +++++++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/libexec/rbenv-hooks b/libexec/rbenv-hooks index 201c91da..6291e78a 100755 --- a/libexec/rbenv-hooks +++ b/libexec/rbenv-hooks @@ -35,16 +35,17 @@ resolve_link() { } realpath() { - local cwd="$(pwd)" + local cwd="$PWD" local path="$1" + local name while [ -n "$path" ]; do - cd "${path%/*}" - local name="${path##*/}" + name="${path##*/}" + [ "$name" = "$path" ] || cd "${path%/*}" path="$(resolve_link "$name" || true)" done - echo "$(pwd)/$name" + echo "${PWD}/$name" cd "$cwd" } fi diff --git a/test/hooks.bats b/test/hooks.bats index 0b53d430..99dc4bf0 100644 --- a/test/hooks.bats +++ b/test/hooks.bats @@ -59,7 +59,13 @@ OUT mkdir -p "$HOME" touch "${HOME}/hola.bash" ln -s "../../home/hola.bash" "${path}/exec/hello.bash" + touch "${path}/exec/bright.sh" + ln -s "bright.sh" "${path}/exec/world.bash" RBENV_HOOK_PATH="$path" run rbenv-hooks exec - assert_success "${HOME}/hola.bash" + assert_success + assert_output < Date: Wed, 28 Oct 2015 21:35:39 +0100 Subject: [PATCH 25/40] Never use hardlinks. Never. --- libexec/rbenv-rehash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libexec/rbenv-rehash b/libexec/rbenv-rehash index 53ab045f..8f0c9b40 100755 --- a/libexec/rbenv-rehash +++ b/libexec/rbenv-rehash @@ -113,7 +113,7 @@ install_registered_shims() { local shim file for shim in $registered_shims; do file="${SHIM_PATH}/${shim}" - [ -e "$file" ] || ln -f "$PROTOTYPE_SHIM_PATH" "$file" + [ -e "$file" ] || cp "$PROTOTYPE_SHIM_PATH" "$file" done } From 6296bf3f8baab76a2a8a126e07a5a31249df28a7 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Thu, 12 Nov 2015 21:19:37 +0100 Subject: [PATCH 26/40] tests: fix path_without to handle /bin properly I was seeing /bin being left. This patch fixes it by anchoring the search pattern with ':' on both sides. --- test/test_helper.bash | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/test_helper.bash b/test/test_helper.bash index 0c21dea7..b62cdc15 100644 --- a/test/test_helper.bash +++ b/test/test_helper.bash @@ -111,7 +111,7 @@ assert() { # but in which system utils necessary for rbenv operation are still available. path_without() { local exe="$1" - local path="${PATH}:" + local path=":${PATH}:" local found alt util for found in $(which -a "$exe"); do found="${found%/*}" @@ -123,8 +123,9 @@ path_without() { ln -s "${found}/$util" "${alt}/$util" fi done - path="${path/${found}:/${alt}:}" + path="${path/:${found}:/:${alt}:}" fi done + path="${path#:}" echo "${path%:}" } From 8c3cab61c7c5f26d8c731f0e6544d1b9860df940 Mon Sep 17 00:00:00 2001 From: Jason Karns Date: Fri, 13 Nov 2015 15:06:29 -0500 Subject: [PATCH 27/40] add completion block for rbenv-help --- libexec/rbenv-help | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/libexec/rbenv-help b/libexec/rbenv-help index 9a3049aa..13bdcf1b 100755 --- a/libexec/rbenv-help +++ b/libexec/rbenv-help @@ -15,6 +15,13 @@ set -e [ -n "$RBENV_DEBUG" ] && set -x +# Provide rbenv completions +if [ "$1" = "--complete" ]; then + echo --usage + rbenv-commands + exit +fi + command_path() { local command="$1" command -v rbenv-"$command" || command -v rbenv-sh-"$command" || true From 09b18cf6f5824be9c4fa30bca9cd9dfe6932be92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Fri, 13 Nov 2015 22:53:27 -0500 Subject: [PATCH 28/40] Add test for version-origin when version not found in `rbenv-exec` --- test/exec.bats | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/exec.bats b/test/exec.bats index ff1e248d..6c5c7880 100644 --- a/test/exec.bats +++ b/test/exec.bats @@ -20,6 +20,12 @@ create_executable() { assert_failure "rbenv: version \`2.0' is not installed (set by RBENV_VERSION environment variable)" } +@test "fails with invalid version set from file" { + echo 1.9 > .ruby-version + run rbenv-exec rspec + assert_failure "rbenv: version \`1.9' is not installed (set by $PWD/.ruby-version)" +} + @test "completes with names of executables" { export RBENV_VERSION="2.0" create_executable "ruby" "#!/bin/sh" From 3405c4d03cc4b1e63c2829e2565f7651b09bebb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Fri, 13 Nov 2015 22:57:22 -0500 Subject: [PATCH 29/40] Fix error message when command is not found for "system" version If `foo` didn't exist and `RBENV_VERSION=system rbenv which foo` was called, the error message used to be misleading: rbenv: version `system' is not installed Instead, have the error message simply say that the command was not found. Fixes #770 --- libexec/rbenv-which | 2 +- test/which.bats | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/libexec/rbenv-which b/libexec/rbenv-which index 8019be21..f4d46245 100755 --- a/libexec/rbenv-which +++ b/libexec/rbenv-which @@ -51,7 +51,7 @@ done if [ -x "$RBENV_COMMAND_PATH" ]; then echo "$RBENV_COMMAND_PATH" -elif ! [ -d "${RBENV_ROOT}/versions/${RBENV_VERSION}" ]; then +elif [ "$RBENV_VERSION" != "system" ] && [ ! -d "${RBENV_ROOT}/versions/${RBENV_VERSION}" ]; then echo "rbenv: version \`$RBENV_VERSION' is not installed (set by $(rbenv-version-origin))" >&2 exit 1 else diff --git a/test/which.bats b/test/which.bats index bf10effe..25c80528 100644 --- a/test/which.bats +++ b/test/which.bats @@ -68,6 +68,12 @@ create_executable() { assert_failure "rbenv: rake: command not found" } +@test "no executable found for system version" { + export PATH="$(path_without "rake")" + RBENV_VERSION=system 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" From 8f87f43e2286616cf3fb7b7bde7d924d7e1267a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Sat, 14 Nov 2015 12:21:16 +0000 Subject: [PATCH 30/40] Fix broken version-dependent test Broken in dcca61c0bc9747a8886bf7a1d790d902c2426ed0 --- test/rbenv.bats | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/rbenv.bats b/test/rbenv.bats index 5b52adc1..4a6d1414 100644 --- a/test/rbenv.bats +++ b/test/rbenv.bats @@ -5,7 +5,7 @@ load test_helper @test "blank invocation" { run rbenv assert_success - assert [ "${lines[0]}" = "rbenv 0.4.0" ] + assert_line 0 "$(rbenv---version)" } @test "invalid command" { From 825de5d2e3151b283dfcee8d2c782ba2af39eec6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Thu, 19 Nov 2015 01:52:48 +0100 Subject: [PATCH 31/40] Fix argument handling in main `rbenv` command - Explicitly asking for help with `-h` or `--help` exits with 0 status and displays help on stdout. - Not providing any arguments to rbenv results in failure status and displays version and help on stderr. --- libexec/rbenv | 12 +++++++++--- test/rbenv.bats | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/libexec/rbenv b/libexec/rbenv index 7be3eed7..609eda11 100755 --- a/libexec/rbenv +++ b/libexec/rbenv @@ -91,12 +91,18 @@ shopt -u nullglob command="$1" case "$command" in -"" | "-h" | "--help" ) - echo -e "$(rbenv---version)\n$(rbenv-help)" >&2 +"" ) + { rbenv---version + rbenv-help + } >&2 + exit 1 ;; -"-v" ) +-v ) exec rbenv---version ;; +-h | --help ) + exec rbenv-help + ;; * ) command_path="$(command -v "rbenv-$command" || true)" if [ -z "$command_path" ]; then diff --git a/test/rbenv.bats b/test/rbenv.bats index 4a6d1414..4e6b32b0 100644 --- a/test/rbenv.bats +++ b/test/rbenv.bats @@ -4,7 +4,7 @@ load test_helper @test "blank invocation" { run rbenv - assert_success + assert_failure assert_line 0 "$(rbenv---version)" } From 06e4f1b682334560f291cd0a759ee7b91dd21e9c Mon Sep 17 00:00:00 2001 From: Jason Karns Date: Tue, 17 Nov 2015 14:46:02 -0500 Subject: [PATCH 32/40] explicit --version flag Without it, it falls back to `--version` being executed as a subcommand, which works but isn't obvious --- libexec/rbenv | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libexec/rbenv b/libexec/rbenv index 609eda11..b65ca112 100755 --- a/libexec/rbenv +++ b/libexec/rbenv @@ -97,7 +97,7 @@ case "$command" in } >&2 exit 1 ;; --v ) +-v | --version ) exec rbenv---version ;; -h | --help ) From 2c4dd63f777ac2219dd21b806b1d422b897d64be Mon Sep 17 00:00:00 2001 From: Jason Karns Date: Tue, 17 Nov 2015 14:51:10 -0500 Subject: [PATCH 33/40] handle --help for subcommands If subcommand is provided (and exists) and its first arg is -h/--help, go ahead and intercept the call; redirecting to rbenv-help This means subcommands and plugins need not handle --help flag themselves --- libexec/rbenv | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libexec/rbenv b/libexec/rbenv index b65ca112..a7c4cc5a 100755 --- a/libexec/rbenv +++ b/libexec/rbenv @@ -111,6 +111,10 @@ case "$command" in fi shift 1 - exec "$command_path" "$@" + if [ "$1" = --help ]; then + exec rbenv-help "$command" + else + exec "$command_path" "$@" + fi ;; esac From d7ca2aba2ac0c986b0232a9592a33da2823bc81d Mon Sep 17 00:00:00 2001 From: Jason Karns Date: Tue, 17 Nov 2015 15:01:33 -0500 Subject: [PATCH 34/40] add --help to subcommand completions ensure subcommand exists, then include --help in its completion output --- libexec/rbenv-completions | 4 ++++ test/completions.bats | 9 +++++++-- test/exec.bats | 1 + 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/libexec/rbenv-completions b/libexec/rbenv-completions index 196212e4..4cb020cf 100755 --- a/libexec/rbenv-completions +++ b/libexec/rbenv-completions @@ -11,6 +11,10 @@ if [ -z "$COMMAND" ]; then fi COMMAND_PATH="$(command -v "rbenv-$COMMAND" || command -v "rbenv-sh-$COMMAND")" + +# --help is provided automatically +echo --help + if grep -iE "^([#%]|--|//) provide rbenv completions" "$COMMAND_PATH" >/dev/null; then shift exec "$COMMAND_PATH" --complete "$@" diff --git a/test/completions.bats b/test/completions.bats index 9091f082..6871cf5e 100644 --- a/test/completions.bats +++ b/test/completions.bats @@ -13,7 +13,7 @@ create_command() { create_command "rbenv-hello" "#!$BASH echo hello" run rbenv-completions hello - assert_success "" + assert_success "--help" } @test "command with completion support" { @@ -25,7 +25,11 @@ else exit 1 fi" run rbenv-completions hello - assert_success "hello" + assert_success + assert_output < Date: Mon, 16 Nov 2015 11:54:22 -0500 Subject: [PATCH 35/40] completions for rbenv-versions --- libexec/rbenv-versions | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libexec/rbenv-versions b/libexec/rbenv-versions index a80506a8..b646cb54 100755 --- a/libexec/rbenv-versions +++ b/libexec/rbenv-versions @@ -9,8 +9,13 @@ set -e unset bare unset skip_aliases +# Provide rbenv completions for arg; do case "$arg" in + --complete ) + echo --bare + echo --skip-aliases + exit ;; --bare ) bare=1 ;; --skip-aliases ) skip_aliases=1 ;; * ) From 2f917312f18c36c9ee745cd11636071ea85be16d Mon Sep 17 00:00:00 2001 From: Jason Karns Date: Fri, 20 Nov 2015 09:12:10 -0500 Subject: [PATCH 36/40] completions for rbenv-completions --- libexec/rbenv-completions | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libexec/rbenv-completions b/libexec/rbenv-completions index 4cb020cf..19551c2e 100755 --- a/libexec/rbenv-completions +++ b/libexec/rbenv-completions @@ -10,6 +10,11 @@ if [ -z "$COMMAND" ]; then exit 1 fi +# Provide rbenv completions +if [ "$COMMAND" = "--complete" ]; then + exec rbenv-commands +fi + COMMAND_PATH="$(command -v "rbenv-$COMMAND" || command -v "rbenv-sh-$COMMAND")" # --help is provided automatically From a6cb4b6317bfc5fcca40ec7d14ff5ea18cfad292 Mon Sep 17 00:00:00 2001 From: Jason Karns Date: Fri, 20 Nov 2015 09:15:06 -0500 Subject: [PATCH 37/40] consistent completions for rbenv-help --- libexec/rbenv-help | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libexec/rbenv-help b/libexec/rbenv-help index 13bdcf1b..c899cf0d 100755 --- a/libexec/rbenv-help +++ b/libexec/rbenv-help @@ -18,8 +18,7 @@ set -e # Provide rbenv completions if [ "$1" = "--complete" ]; then echo --usage - rbenv-commands - exit + exec rbenv-commands fi command_path() { From 2dcb9d0611d5e1d69c5093068dbd8503897edd1d Mon Sep 17 00:00:00 2001 From: Jason Karns Date: Fri, 20 Nov 2015 09:20:01 -0500 Subject: [PATCH 38/40] completions for rbenv-init --- libexec/rbenv-init | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/libexec/rbenv-init b/libexec/rbenv-init index 88f9e69c..8e6ee3d8 100755 --- a/libexec/rbenv-init +++ b/libexec/rbenv-init @@ -5,6 +5,17 @@ set -e [ -n "$RBENV_DEBUG" ] && set -x +# Provide rbenv completions +if [ "$1" = "--complete" ]; then + echo - + echo --no-rehash + echo bash + echo fish + echo ksh + echo zsh + exit +fi + print="" no_rehash="" for args in "$@" From a3ff3adc391c25a82247d441215a1042dd5c61c5 Mon Sep 17 00:00:00 2001 From: Jason Karns Date: Fri, 20 Nov 2015 09:51:21 -0500 Subject: [PATCH 39/40] create local .ruby-version file in test dir This new test was creating an (intentionally invalid) .ruby-version file in current working directory; typically the rbenv project dir. Immediately after test runs, I had a leftover .ruby-version file. The version-file tests create and cd into the RBENV_TEST_DIR as part of setup(). I'm using the same directory for this test fix, but am only using it for this particular test. None of the other exec tests seem to need to be in a temp test dir, so no use putting it in setup(). --- test/exec.bats | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/exec.bats b/test/exec.bats index 28003794..aeb0456c 100644 --- a/test/exec.bats +++ b/test/exec.bats @@ -21,6 +21,8 @@ create_executable() { } @test "fails with invalid version set from file" { + mkdir -p "$RBENV_TEST_DIR" + cd "$RBENV_TEST_DIR" echo 1.9 > .ruby-version run rbenv-exec rspec assert_failure "rbenv: version \`1.9' is not installed (set by $PWD/.ruby-version)" From 3ddedc021a06f3f75103f0b6c591f1d4b54eb53c Mon Sep 17 00:00:00 2001 From: Jason Karns Date: Tue, 17 Nov 2015 15:30:33 -0500 Subject: [PATCH 40/40] Extract `abort` helper function fail helper prints message to stderr and exits 1 (prefixes 'rbenv: ' if given a string arg) --- libexec/rbenv | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/libexec/rbenv b/libexec/rbenv index a7c4cc5a..dd68cdfe 100755 --- a/libexec/rbenv +++ b/libexec/rbenv @@ -12,21 +12,24 @@ if [ -n "$RBENV_DEBUG" ]; then set -x fi +abort() { + { if [ "$#" -eq 0 ]; then cat - + else echo "rbenv: $*" + fi + } >&2 + exit 1 +} + if enable -f "${BASH_SOURCE%/*}"/../libexec/rbenv-realpath.dylib realpath 2>/dev/null; then abs_dirname() { local path="$(realpath "$1")" echo "${path%/*}" } else - if [ -n "$RBENV_NATIVE_EXT" ]; then - echo "rbenv: failed to load \`realpath' builtin" >&2 - exit 1 - fi + [ -z "$RBENV_NATIVE_EXT" ] || abort "failed to load \`realpath' builtin" + 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 +[ -n "$READLINK" ] || abort "cannot find readlink - are you missing GNU coreutils?" resolve_link() { $READLINK "$1" @@ -57,10 +60,7 @@ export RBENV_ROOT if [ -z "${RBENV_DIR}" ]; then RBENV_DIR="$(pwd)" else - cd "$RBENV_DIR" 2>/dev/null || { - echo "rbenv: cannot change working directory to \`$RBENV_DIR'" - exit 1 - } >&2 + cd "$RBENV_DIR" 2>/dev/null || abort "cannot change working directory to \`$RBENV_DIR'" RBENV_DIR="$(pwd)" cd "$OLDPWD" fi @@ -94,8 +94,7 @@ case "$command" in "" ) { rbenv---version rbenv-help - } >&2 - exit 1 + } | abort ;; -v | --version ) exec rbenv---version @@ -105,10 +104,7 @@ case "$command" in ;; * ) command_path="$(command -v "rbenv-$command" || true)" - if [ -z "$command_path" ]; then - echo "rbenv: no such command \`$command'" >&2 - exit 1 - fi + [ -n "$command_path" ] || abort "no such command \`$command'" shift 1 if [ "$1" = --help ]; then