Merge pull request #632 from sstephenson/definitions-completion

`rbenv install` completion includes definitions from plugins
This commit is contained in:
Mislav Marohnić 2014-09-08 20:19:51 -07:00
commit b275e87cb7
2 changed files with 27 additions and 13 deletions

View file

@ -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

View file

@ -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
}