Commit 56c8f296 authored by Mislav Marohnić's avatar Mislav Marohnić
Browse files

`rbenv install` completion includes definitions from plugins

Before, `ruby-build --definitions` was invoked sooner than
RUBY_BUILD_DEFINITIONS was built up with paths from rbenv plugins.
parent aaf50ec6
Loading
Loading
Loading
Loading
+13 −13
Original line number Diff line number Diff line
@@ -24,15 +24,24 @@
set -e
[ -n "$RBENV_DEBUG" ] && set -x

if [ -z "$RBENV_ROOT" ]; then
  RBENV_ROOT="${HOME}/.rbenv"
fi

# Add `share/ruby-build/` directory from each rbenv plugin to the list of
# paths where build definitions are looked up.
shopt -s nullglob
for plugin_path in "$RBENV_ROOT"/plugins/*/share/ruby-build; do
  RUBY_BUILD_DEFINITIONS="${RUBY_BUILD_DEFINITIONS}:${plugin_path}"
done
export RUBY_BUILD_DEFINITIONS
shopt -u nullglob

# Provide rbenv completions
if [ "$1" = "--complete" ]; then
  exec ruby-build --definitions
fi

if [ -z "$RBENV_ROOT" ]; then
  RBENV_ROOT="${HOME}/.rbenv"
fi

# Load shared library functions
eval "$(ruby-build --lib)"

@@ -51,15 +60,6 @@ indent() {
  sed 's/^/  /'
}

# Add `share/ruby-build/` directory from each rbenv plugin to the list of
# paths where build definitions are looked up.
shopt -s nullglob
for plugin_path in "$RBENV_ROOT"/plugins/*/share/ruby-build; do
  RUBY_BUILD_DEFINITIONS="${RUBY_BUILD_DEFINITIONS}:${plugin_path}"
done
export RUBY_BUILD_DEFINITIONS
shopt -u nullglob

unset FORCE
unset SKIP_EXISTING
unset KEEP
+14 −0
Original line number Diff line number Diff line
@@ -110,3 +110,17 @@ Available versions:
  ${RBENV_ROOT}/plugins/foo/share/ruby-build
OUT
}

@test "completion results include build definitions from plugins" {
  mkdir -p "${RBENV_ROOT}/plugins/foo/share/ruby-build"
  mkdir -p "${RBENV_ROOT}/plugins/bar/share/ruby-build"
  stub ruby-build "--definitions : echo \$RUBY_BUILD_DEFINITIONS | tr ':' $'\\n'"

  run rbenv-install --complete
  assert_success
  assert_output <<OUT

${RBENV_ROOT}/plugins/bar/share/ruby-build
${RBENV_ROOT}/plugins/foo/share/ruby-build
OUT
}