diff --git a/bin/rbenv-install b/bin/rbenv-install index a9e904fe..b7e6b5ae 100755 --- a/bin/rbenv-install +++ b/bin/rbenv-install @@ -62,6 +62,23 @@ definitions() { ruby-build --definitions | $(type -p ggrep grep | head -1) -F "$query" || true } +suggest_selecting_global() { + # shellcheck disable=SC2155 + local version_file="$(rbenv-version-file)" + [[ "$version_file" != "$RBENV_ROOT"/version || -e "$version_file" ]] && return 0 + echo + colorize 1 "NOTE:" + echo -n " to activate this Ruby version as the new default, run: " + colorize 33 "rbenv global $VERSION_NAME" + echo +} + +colorize() { + if [ -t 1 ]; then printf "\e[%sm%s\e[m" "$1" "$2" + else printf "%s" "$2" + fi +} + indent() { sed 's/^/ /' } @@ -190,6 +207,7 @@ fi # REE installer requires an existing Ruby installation to run. An # unsatisfied local .ruby-version file can cause the installer to # fail.) +# shellcheck disable=SC2155 export RBENV_VERSION="$(rbenv-global 2>/dev/null || true)" @@ -238,6 +256,7 @@ for hook in "${after_hooks[@]}"; do eval "$hook"; done # Run `rbenv-rehash` after a successful installation. if [ "$STATUS" == "0" ]; then rbenv-rehash + suggest_selecting_global else cleanup fi diff --git a/test/hooks.bats b/test/hooks.bats index fa6f9951..c1b32b05 100644 --- a/test/hooks.bats +++ b/test/hooks.bats @@ -15,6 +15,7 @@ after_install 'echo after: \$STATUS' OUT stub rbenv-hooks "install : echo '$HOOK_PATH'/install.bash" stub rbenv-rehash "echo rehashed" + stub rbenv-version-file "echo .ruby-version" definition="${TMP}/2.0.0" cat > "$definition" <<<"echo ruby-build" diff --git a/test/rbenv.bats b/test/rbenv.bats index bca34d30..c24ebd05 100644 --- a/test/rbenv.bats +++ b/test/rbenv.bats @@ -6,6 +6,9 @@ export RBENV_ROOT="${TMP}/rbenv" setup() { stub rbenv-hooks 'install : true' stub rbenv-rehash 'true' + stub rbenv-version-file 'echo $RBENV_ROOT/version' + mkdir -p "$RBENV_ROOT" + echo "system" > "$RBENV_ROOT/version" } stub_ruby_build() { @@ -23,6 +26,20 @@ stub_ruby_build() { unstub rbenv-rehash } +@test "suggest running rbenv global after install" { + rm -rf "$RBENV_ROOT/version" + stub_ruby_build 'echo ruby-build "$@"' + + run rbenv-install 2.1.2 + assert_success <