From 9f52b56aa8bc75c31862ef998a98cee9ce7a3bfb Mon Sep 17 00:00:00 2001 From: Max Nordlund Date: Fri, 10 Feb 2017 09:12:30 +0100 Subject: [PATCH 01/18] Fix fish subcommand completion This allows subcommand style plugins to properly autocomplete. Existing commands are not affected. Example, say you have support for `rbenv foo bar --flag`, then this allows the last `--flag` argument to be properly completed. --- completions/rbenv.fish | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/completions/rbenv.fish b/completions/rbenv.fish index 3ca8e945..762f4c07 100644 --- a/completions/rbenv.fish +++ b/completions/rbenv.fish @@ -18,5 +18,6 @@ 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)" + complete -f -c pyenv -n "__fish_pyenv_using_command $cmd" -a \ + "(rbenv completions (commandline -opc)[2..-1])" end From fab5cf912f5fe685f8b35b88f9c554b5e2f17e62 Mon Sep 17 00:00:00 2001 From: Max Nordlund Date: Fri, 10 Feb 2017 09:31:13 +0100 Subject: [PATCH 02/18] Fix pyenv -> rbenv typo --- completions/rbenv.fish | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/completions/rbenv.fish b/completions/rbenv.fish index 762f4c07..d3474105 100644 --- a/completions/rbenv.fish +++ b/completions/rbenv.fish @@ -18,6 +18,6 @@ end complete -f -c rbenv -n '__fish_rbenv_needs_command' -a '(rbenv commands)' for cmd in (rbenv commands) - complete -f -c pyenv -n "__fish_pyenv_using_command $cmd" -a \ + complete -f -c rbenv -n "__fish_rbenv_using_command $cmd" -a \ "(rbenv completions (commandline -opc)[2..-1])" end From db39044ef6e48a5913f4fcc6236421f86ea96f48 Mon Sep 17 00:00:00 2001 From: Martin Nowak Date: Mon, 27 Mar 2017 02:06:13 +0200 Subject: [PATCH 03/18] partly resolve #759 - some versions of bash (e.g. 4.3.11) complain about clobbering /dev/null, use bash's explicit >| operator to ignore noclober - not sure if the original #759 report has the same cause - https://github.com/rbenv/rbenv/issues/759#issuecomment-289326891 --- libexec/rbenv-rehash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libexec/rbenv-rehash b/libexec/rbenv-rehash index 8f0c9b40..ef24561a 100755 --- a/libexec/rbenv-rehash +++ b/libexec/rbenv-rehash @@ -16,7 +16,7 @@ mkdir -p "$SHIM_PATH" # to stderr and exit with a non-zero status. set -o noclobber { echo > "$PROTOTYPE_SHIM_PATH" -} 2>/dev/null || +} 2>| /dev/null || { if [ -w "$SHIM_PATH" ]; then echo "rbenv: cannot rehash: $PROTOTYPE_SHIM_PATH exists" else From 1f1e291385ef2fecd48e5dccc68e7aaa6c7fe36b Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Wed, 5 Apr 2017 16:29:18 -0400 Subject: [PATCH 04/18] Enforce absolute RBENV_DIR This prevents CDPATH from becoming an issue. Closes #866. --- libexec/rbenv | 1 + 1 file changed, 1 insertion(+) diff --git a/libexec/rbenv b/libexec/rbenv index 07847a66..ee13f0c7 100755 --- a/libexec/rbenv +++ b/libexec/rbenv @@ -60,6 +60,7 @@ export RBENV_ROOT if [ -z "${RBENV_DIR}" ]; then RBENV_DIR="$PWD" else + [[ $RBENV_DIR == /* ]] || RBENV_DIR=$PWD/$RBENV_DIR cd "$RBENV_DIR" 2>/dev/null || abort "cannot change working directory to \`$RBENV_DIR'" RBENV_DIR="$PWD" cd "$OLDPWD" From 9d93605e187cb44b66c9edd3086cac4d562512c3 Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Wed, 5 Apr 2017 16:36:04 -0400 Subject: [PATCH 05/18] Don't unset CDPATH --- libexec/rbenv | 1 - 1 file changed, 1 deletion(-) diff --git a/libexec/rbenv b/libexec/rbenv index ee13f0c7..a9e0c8ec 100755 --- a/libexec/rbenv +++ b/libexec/rbenv @@ -1,6 +1,5 @@ #!/usr/bin/env bash set -e -unset CDPATH if [ "$1" = "--debug" ]; then export RBENV_DEBUG=1 From 95b1b05cbe6fc0578eeba40885d97787367adecf Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Mon, 5 Jun 2017 15:40:59 +0200 Subject: [PATCH 06/18] rbenv-version-file: ensure that the version file is a file Forwarded from https://github.com/pyenv/pyenv/pull/606. --- 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 0ea8d3aa..c0550d64 100755 --- a/libexec/rbenv-version-file +++ b/libexec/rbenv-version-file @@ -9,7 +9,7 @@ target_dir="$1" find_local_version_file() { local root="$1" while ! [[ "$root" =~ ^//[^/]*$ ]]; do - if [ -e "${root}/.ruby-version" ]; then + if [ -f "${root}/.ruby-version" ]; then echo "${root}/.ruby-version" return 0 fi From e3e99cc906f28fc98644b8ade439fcba45f2d059 Mon Sep 17 00:00:00 2001 From: Jeremy Daer Date: Tue, 13 Jun 2017 10:00:14 -0700 Subject: [PATCH 07/18] Clarify Homebrew/git install guidance * Move Homebrew to the top, common case for new devs * Note that `brew install rbenv` includes ruby-build by default * Be clear that `rbenv init` instructions are needed for shell setup * Be explicit about starting a new shell to pick up PATH/init changes * Use rbenv-doctor to conclusively demonstrate correct setup * Separate upgrade instructions for Homebrew vs Git installs Related: https://github.com/rbenv/ruby-build/pull/1106 --- README.md | 122 ++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 76 insertions(+), 46 deletions(-) diff --git a/README.md b/README.md index 662d4a46..0db24eb8 100644 --- a/README.md +++ b/README.md @@ -39,9 +39,10 @@ RVM?**](https://github.com/rbenv/rbenv/wiki/Why-rbenv%3F) * [Choosing the Ruby Version](#choosing-the-ruby-version) * [Locating the Ruby Installation](#locating-the-ruby-installation) * [Installation](#installation) + * [Homebrew on macOS](#homebrew-on-mac-os) + * [Upgrading with Homebrew](#upgrading-with-homebrew) * [Basic GitHub Checkout](#basic-github-checkout) - * [Upgrading](#upgrading) - * [Homebrew on Mac OS X](#homebrew-on-mac-os-x) + * [Upgrading with Git](#upgrading-with-git) * [How rbenv hooks into your shell](#how-rbenv-hooks-into-your-shell) * [Installing Ruby versions](#installing-ruby-versions) * [Installing Ruby gems](#installing-ruby-gems) @@ -148,15 +149,63 @@ Version names to rbenv are simply the names of the directories in 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). +### Homebrew on macOS + +If you're on macOS, we recommend installing rbenv with +[Homebrew](https://brew.sh). + +1. Install rbenv. + + ~~~ sh + $ brew install rbenv + ~~~ + + Note that this also installs `ruby-build`, so you'll be ready to + install other Ruby versions out of the box. + +2. Run `rbenv init` and follow the instructions to set up + rbenv integration with your shell. This is the step that will make + running `ruby` "see" the Ruby version that you choose with rbenv. + +3. Close your Terminal window and open a new one so your changes take + effect. + +4. Verify that rbenv is properly set up using this + [rbenv-doctor](https://github.com/rbenv/rbenv-installer/blob/master/bin/rbenv-doctor) script: + + ~~~ sh + $ curl -fsSL https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-doctor | bash + Checking for `rbenv' in PATH: /usr/local/bin/rbenv + Checking for rbenv shims in PATH: OK + Checking `rbenv install' support: /usr/local/bin/rbenv-install (ruby-build 20170523) + Counting installed Ruby versions: none + There aren't any Ruby versions installed under `~/.rbenv/versions'. + You can install Ruby versions like so: rbenv install 2.2.4 + Checking RubyGems settings: OK + Auditing installed plugins: OK + ~~~ + +5. That's it! Installing rbenv includes ruby-build, so now you're ready to + [install some other Ruby versions](#installing-ruby-versions) using + `rbenv install`. + + +#### Upgrading with Homebrew + +To upgrade to the latest rbenv and update ruby-build with newly released +Ruby versions, upgrade the Homebrew packages: + +~~~ sh +$ brew upgrade rbenv ruby-build +~~~ + ### 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 without needing +a systemwide install. -1. Check out rbenv into `~/.rbenv`. +1. Clone rbenv into `~/.rbenv`. ~~~ sh $ git clone https://github.com/rbenv/rbenv.git ~/.rbenv @@ -180,61 +229,42 @@ easy to fork and contribute any changes back upstream. **Zsh note**: Modify your `~/.zshrc` file instead of `~/.bash_profile`. -3. Run `~/.rbenv/bin/rbenv init` for shell-specific instructions on how to - initialize rbenv to enable shims and autocompletion. +3. Run `~/.rbenv/bin/rbenv init` and follow the instructions to set up + rbenv integration with your shell. This is the step that will make + running `ruby` "see" the Ruby version that you choose with 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: + terminal tab will usually do it.) + +5. Verify that rbenv is properly set up using this + [rbenv-doctor](https://github.com/rbenv/rbenv-installer/blob/master/bin/rbenv-doctor) script: ~~~ sh - $ type rbenv - #=> "rbenv is a function" + $ curl -fsSL https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-doctor | bash + Checking for `rbenv' in PATH: /usr/local/bin/rbenv + Checking for rbenv shims in PATH: OK + Checking `rbenv install' support: /usr/local/bin/rbenv-install (ruby-build 20170523) + Counting installed Ruby versions: none + There aren't any Ruby versions installed under `~/.rbenv/versions'. + You can install Ruby versions like so: rbenv install 2.2.4 + Checking RubyGems settings: OK + Auditing installed plugins: OK ~~~ -5. _(Optional)_ Install [ruby-build][], which provides the +6. _(Optional)_ Install [ruby-build][], which provides the `rbenv install` command that simplifies the process of [installing new Ruby versions](#installing-ruby-versions). -#### Upgrading +#### Upgrading with Git -If you've installed rbenv manually using git, you can upgrade your -installation to the cutting-edge version at any time. +If you've installed rbenv manually using Git, you can upgrade to the +latest version by pulling from GitHub: ~~~ sh $ cd ~/.rbenv $ git pull ~~~ -To use a specific release of rbenv, check out the corresponding tag: - -~~~ sh -$ cd ~/.rbenv -$ 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 - -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 -$ rbenv init -~~~ - -You'll only ever have to run `rbenv init` once. - ### How rbenv hooks into your shell Skip this section unless you must know what every line in your shell From 6cd487db8138816d9c2898846e9066f21b47a284 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Thu, 15 Jun 2017 16:55:33 +0200 Subject: [PATCH 08/18] rbenv 1.1.1 --- libexec/rbenv---version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libexec/rbenv---version b/libexec/rbenv---version index e994f028..f7a1641e 100755 --- a/libexec/rbenv---version +++ b/libexec/rbenv---version @@ -12,7 +12,7 @@ set -e [ -n "$RBENV_DEBUG" ] && set -x -version="1.1.0" +version="1.1.1" git_revision="" if cd "${BASH_SOURCE%/*}" 2>/dev/null && git remote -v 2>/dev/null | grep -q rbenv; then From fc706daf60e32f641c90c6da9a6c77f1b40fc20d Mon Sep 17 00:00:00 2001 From: Kenaniah Cerny Date: Sun, 18 Jun 2017 20:57:52 -0700 Subject: [PATCH 09/18] properly escapes commas in cflags --- src/configure | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/configure b/src/configure index 10d0ff57..62bd7b1f 100755 --- a/src/configure +++ b/src/configure @@ -35,12 +35,12 @@ eval "$("$src_dir"/shobj-conf -C "$CC" -o "$host_os")" sed " s,@CC@,${CC}, - s,@CFLAGS@,${CFLAGS}, - s,@LOCAL_CFLAGS@,${LOCAL_CFLAGS}, + 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_CFLAGS@,${SHOBJ_CFLAGS//,/\\,}, s,@SHOBJ_LD@,${SHOBJ_LD}, s,@SHOBJ_LDFLAGS@,${SHOBJ_LDFLAGS//,/\\,}, s,@SHOBJ_XLDFLAGS@,${SHOBJ_XLDFLAGS//,/\\,}, From dbaa8c83b66fffb12ef241950989a683685c4899 Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Mon, 7 Aug 2017 13:12:37 +0200 Subject: [PATCH 10/18] Fixed support of build env vars for dynamic bash extension configure script --- src/configure | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/configure b/src/configure index 62bd7b1f..54b33798 100755 --- a/src/configure +++ b/src/configure @@ -34,16 +34,16 @@ 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}, + 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 From 650c9d345292826159568ec93bead07a50734166 Mon Sep 17 00:00:00 2001 From: MinhThienDX <13492015+MinhThienDX@users.noreply.github.com> Date: Mon, 4 Sep 2017 23:51:22 +0700 Subject: [PATCH 11/18] Fix URL fragment target --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0db24eb8..b2d4c20e 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ RVM?**](https://github.com/rbenv/rbenv/wiki/Why-rbenv%3F) * [Choosing the Ruby Version](#choosing-the-ruby-version) * [Locating the Ruby Installation](#locating-the-ruby-installation) * [Installation](#installation) - * [Homebrew on macOS](#homebrew-on-mac-os) + * [Homebrew on macOS](#homebrew-on-macos) * [Upgrading with Homebrew](#upgrading-with-homebrew) * [Basic GitHub Checkout](#basic-github-checkout) * [Upgrading with Git](#upgrading-with-git) From 1a8b5e04a943bbff56a5d567be35dc3107015ef5 Mon Sep 17 00:00:00 2001 From: Ryan Davis Date: Sun, 1 Jan 2017 22:06:39 -0800 Subject: [PATCH 12/18] Fixed `rbenv init -` output to work w/ no args and bash's `set -u`. --- libexec/rbenv-init | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libexec/rbenv-init b/libexec/rbenv-init index 1661a052..855e9a58 100755 --- a/libexec/rbenv-init +++ b/libexec/rbenv-init @@ -138,7 +138,7 @@ esac if [ "$shell" != "fish" ]; then IFS="|" cat < Date: Mon, 5 Jun 2017 15:27:58 +0200 Subject: [PATCH 13/18] test/which.bats: do not export PATH Otherwise `sed` might not be found later in bats/libexec/bats-exec-test, in case `/usr/bin` gets removed. --- test/which.bats | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/test/which.bats b/test/which.bats index d9759845..c4a0197a 100644 --- a/test/which.bats +++ b/test/which.bats @@ -57,12 +57,11 @@ create_executable() { } @test "doesn't include current directory in PATH search" { - export PATH="$(path_without "kill-all-humans")" mkdir -p "$RBENV_TEST_DIR" cd "$RBENV_TEST_DIR" touch kill-all-humans chmod +x kill-all-humans - RBENV_VERSION=system run rbenv-which kill-all-humans + PATH="$(path_without "kill-all-humans")" RBENV_VERSION=system run rbenv-which kill-all-humans assert_failure "rbenv: kill-all-humans: command not found" } @@ -79,8 +78,7 @@ create_executable() { } @test "no executable found for system version" { - export PATH="$(path_without "rake")" - RBENV_VERSION=system run rbenv-which rake + PATH="$(path_without "rake")" RBENV_VERSION=system run rbenv-which rake assert_failure "rbenv: rake: command not found" } From b80ea43e255bd7e2314cefe6cc503f656aa94130 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Wed, 29 Nov 2017 15:51:03 +0100 Subject: [PATCH 14/18] Quote directory name in variable assignment --- libexec/rbenv | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libexec/rbenv b/libexec/rbenv index a9e0c8ec..ad5c97cb 100755 --- a/libexec/rbenv +++ b/libexec/rbenv @@ -59,7 +59,7 @@ export RBENV_ROOT if [ -z "${RBENV_DIR}" ]; then RBENV_DIR="$PWD" else - [[ $RBENV_DIR == /* ]] || RBENV_DIR=$PWD/$RBENV_DIR + [[ $RBENV_DIR == /* ]] || RBENV_DIR="$PWD/$RBENV_DIR" cd "$RBENV_DIR" 2>/dev/null || abort "cannot change working directory to \`$RBENV_DIR'" RBENV_DIR="$PWD" cd "$OLDPWD" From 5f8a4c4d62a84751f50332cea38b58c627a77f85 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Sat, 24 Jun 2017 00:12:09 +0200 Subject: [PATCH 15/18] Fix some issues reported by shellcheck --- libexec/rbenv | 3 ++- libexec/rbenv-commands | 10 +++++----- libexec/rbenv-help | 6 ++++-- libexec/rbenv-rehash | 3 ++- libexec/rbenv-root | 2 +- libexec/rbenv-whence | 2 +- 6 files changed, 15 insertions(+), 11 deletions(-) diff --git a/libexec/rbenv b/libexec/rbenv index ad5c97cb..e893220b 100755 --- a/libexec/rbenv +++ b/libexec/rbenv @@ -21,7 +21,8 @@ abort() { if enable -f "${BASH_SOURCE%/*}"/../libexec/rbenv-realpath.dylib realpath 2>/dev/null; then abs_dirname() { - local path="$(realpath "$1")" + local path + path="$(realpath "$1")" echo "${path%/*}" } else diff --git a/libexec/rbenv-commands b/libexec/rbenv-commands index daeedd78..4c3d8456 100755 --- a/libexec/rbenv-commands +++ b/libexec/rbenv-commands @@ -28,15 +28,15 @@ shopt -s nullglob for command in "${path}/rbenv-"*; do command="${command##*rbenv-}" if [ -n "$sh" ]; then - if [ ${command:0:3} = "sh-" ]; then - echo ${command##sh-} + if [ "${command:0:3}" = "sh-" ]; then + echo "${command##sh-}" fi elif [ -n "$nosh" ]; then - if [ ${command:0:3} != "sh-" ]; then - echo ${command##sh-} + if [ "${command:0:3}" != "sh-" ]; then + echo "${command##sh-}" fi else - echo ${command##sh-} + echo "${command##sh-}" fi done done diff --git a/libexec/rbenv-help b/libexec/rbenv-help index e5013d3d..0b7e926a 100755 --- a/libexec/rbenv-help +++ b/libexec/rbenv-help @@ -42,6 +42,7 @@ extract_initial_comment_block() { } collect_documentation() { + # shellcheck disable=SC2016 $(type -p gawk awk | head -1) ' /^Summary:/ { summary = substr($0, 10) @@ -86,7 +87,8 @@ collect_documentation() { } documentation_for() { - local filename="$(command_path "$1")" + local filename + filename="$(command_path "$1")" if [ -n "$filename" ]; then extract_initial_comment_block < "$filename" | collect_documentation fi @@ -114,7 +116,7 @@ print_help() { eval "$(documentation_for "$command")" [ -n "$help" ] || help="$summary" - if [ -n "$usage" -o -n "$summary" ]; then + if [ -n "$usage" ] || [ -n "$summary" ]; then if [ -n "$usage" ]; then echo "$usage" else diff --git a/libexec/rbenv-rehash b/libexec/rbenv-rehash index ef24561a..b84de7f9 100755 --- a/libexec/rbenv-rehash +++ b/libexec/rbenv-rehash @@ -83,7 +83,7 @@ remove_outdated_shims() { list_executable_names() { local version file rbenv-versions --bare --skip-aliases | \ - while read version; do + while read -r version; do for file in "${RBENV_ROOT}/versions/${version}/bin/"*; do echo "${file##*/}" done @@ -136,6 +136,7 @@ shopt -s nullglob # executables. create_prototype_shim remove_outdated_shims +# shellcheck disable=SC2046 make_shims $(list_executable_names | sort -u) diff --git a/libexec/rbenv-root b/libexec/rbenv-root index 64fc90b8..42baaee8 100755 --- a/libexec/rbenv-root +++ b/libexec/rbenv-root @@ -1,3 +1,3 @@ #!/usr/bin/env bash # Summary: Display the root directory where versions and shims are kept -echo $RBENV_ROOT +echo "$RBENV_ROOT" diff --git a/libexec/rbenv-whence b/libexec/rbenv-whence index 3d4c89b4..29e08061 100755 --- a/libexec/rbenv-whence +++ b/libexec/rbenv-whence @@ -20,7 +20,7 @@ fi whence() { local command="$1" - rbenv-versions --bare | while read version; do + rbenv-versions --bare | while read -r version; do path="$(rbenv-prefix "$version")/bin/${command}" if [ -x "$path" ]; then [ "$print_paths" ] && echo "$path" || echo "$version" From af53c790cc468b50c4924e2bc11d18ca015fb04f Mon Sep 17 00:00:00 2001 From: Marco Hinz Date: Thu, 23 Mar 2017 14:47:12 +0100 Subject: [PATCH 16/18] Better error message for `rbenv shell` Shell integration is not enabled by default. This means that, from all the commands from `rbenv commands`, only "shell" won't work right away. Replace "no such command" with a more descriptive message that points to `rbenv init` instead. --- libexec/rbenv | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/libexec/rbenv b/libexec/rbenv index e893220b..4880df38 100755 --- a/libexec/rbenv +++ b/libexec/rbenv @@ -106,7 +106,13 @@ case "$command" in ;; * ) command_path="$(command -v "rbenv-$command" || true)" - [ -n "$command_path" ] || abort "no such command \`$command'" + if [ -z "$command_path" ]; then + if [ "$command" == "shell" ]; then + abort "shell integration not enabled. Run \`rbenv init' for instructions." + else + abort "no such command \`$command'" + fi + fi shift 1 if [ "$1" = --help ]; then From 643023d98fabbcdb76a749ddf7b5d6a29589faab Mon Sep 17 00:00:00 2001 From: Marco Hinz Date: Thu, 7 Dec 2017 02:29:48 +0100 Subject: [PATCH 17/18] Add tests for shell integration --- test/shell.bats | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/shell.bats b/test/shell.bats index 9d6ae14b..bbb146e1 100644 --- a/test/shell.bats +++ b/test/shell.bats @@ -2,6 +2,17 @@ load test_helper +@test "shell integration disabled" { + run rbenv shell + assert_failure "rbenv: shell integration not enabled. Run \`rbenv init' for instructions." +} + +@test "shell integration enabled" { + eval "$(rbenv init -)" + run rbenv shell + assert_success "rbenv: no shell-specific version configured" +} + @test "no shell version" { mkdir -p "${RBENV_TEST_DIR}/myproject" cd "${RBENV_TEST_DIR}/myproject" From 9daf81f16e1dc55491b20b7da1ea82bf8cf3b3e9 Mon Sep 17 00:00:00 2001 From: Victor Lim Date: Mon, 26 Feb 2018 16:32:43 +0800 Subject: [PATCH 18/18] Fix https://github.com/rbenv/rbenv/issues/1065 Command `rbenv version-name > .ruby-version` will create an empty `.ruby-version` file before running `rbenv-version-file`. This causes `rbenv-version-file` to return empty string which in turn causes `rbenv-version-name` to return `system`. Ensure size of `.ruby-version` is non-zero as a workaround. --- libexec/rbenv-version-file | 2 +- test/version-file.bats | 2 +- test/version-origin.bats | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libexec/rbenv-version-file b/libexec/rbenv-version-file index c0550d64..a8335950 100755 --- a/libexec/rbenv-version-file +++ b/libexec/rbenv-version-file @@ -9,7 +9,7 @@ target_dir="$1" find_local_version_file() { local root="$1" while ! [[ "$root" =~ ^//[^/]*$ ]]; do - if [ -f "${root}/.ruby-version" ]; then + if [ -s "${root}/.ruby-version" ]; then echo "${root}/.ruby-version" return 0 fi diff --git a/test/version-file.bats b/test/version-file.bats index d8cc74e3..075b002d 100644 --- a/test/version-file.bats +++ b/test/version-file.bats @@ -9,7 +9,7 @@ setup() { create_file() { mkdir -p "$(dirname "$1")" - touch "$1" + echo "system" > "$1" } @test "detects global 'version' file" { diff --git a/test/version-origin.bats b/test/version-origin.bats index 7bca376d..55138920 100644 --- a/test/version-origin.bats +++ b/test/version-origin.bats @@ -26,7 +26,7 @@ setup() { } @test "detects local file" { - touch .ruby-version + echo "system" > .ruby-version run rbenv-version-origin assert_success "${PWD}/.ruby-version" }