From 789ace54ec8699d5042c7cd0dda244610b2a5e1c Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Wed, 21 Sep 2011 12:36:07 -0500 Subject: [PATCH 1/6] Add bin to list plugin scripts --- libexec/rbenv-plugin-scripts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100755 libexec/rbenv-plugin-scripts diff --git a/libexec/rbenv-plugin-scripts b/libexec/rbenv-plugin-scripts new file mode 100755 index 00000000..e77c8719 --- /dev/null +++ b/libexec/rbenv-plugin-scripts @@ -0,0 +1,19 @@ +#!/usr/bin/env bash +set -e +[ -n "$RBENV_DEBUG" ] && set -x + +# Provide rbenv completions +if [ "$1" = "--complete" ]; then + echo exec + echo rehash + echo which + exit +fi + +shopt -s nullglob +RBENV_EXEC_PLUGINS=(/etc/rbenv.d/$1/*.bash ${RBENV_ROOT}/rbenv.d/$1/*.bash) +shopt -u nullglob + +for script in ${RBENV_EXEC_PLUGINS[@]}; do + echo $script +done From 96b98ed039ae39fc386d2c93dc3568df6973ec35 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Wed, 21 Sep 2011 12:38:58 -0500 Subject: [PATCH 2/6] Use plugin-scripts --- libexec/rbenv-exec | 8 ++------ libexec/rbenv-rehash | 8 ++------ libexec/rbenv-which | 8 ++------ 3 files changed, 6 insertions(+), 18 deletions(-) diff --git a/libexec/rbenv-exec b/libexec/rbenv-exec index ac060196..d940a7a3 100755 --- a/libexec/rbenv-exec +++ b/libexec/rbenv-exec @@ -16,12 +16,8 @@ fi RBENV_COMMAND_PATH="$(rbenv-which "$RBENV_COMMAND")" RBENV_BIN_PATH="${RBENV_COMMAND_PATH%/*}" -shopt -s nullglob -RBENV_EXEC_PLUGINS=(/etc/rbenv.d/exec/*.bash ${RBENV_ROOT}/rbenv.d/exec/*.bash) -shopt -u nullglob - -for script in ${RBENV_EXEC_PLUGINS[@]}; do - source $script +for script in $(rbenv-plugin-scripts exec); do + source $script; done shift 1 diff --git a/libexec/rbenv-rehash b/libexec/rbenv-rehash index 3d9a9a70..a11b64bd 100755 --- a/libexec/rbenv-rehash +++ b/libexec/rbenv-rehash @@ -67,13 +67,9 @@ create_prototype_shim shopt -s nullglob make_shims ../versions/*/bin/* -# Find and run any plugins that might want to make shims too. -RBENV_REHASH_PLUGINS=(/etc/rbenv.d/rehash/*.bash ${RBENV_ROOT}/rbenv.d/rehash/*.bash) -shopt -u nullglob - # Restore the previous working directory. cd "$CUR_PATH" -for script in ${RBENV_REHASH_PLUGINS[@]}; do - source $script +for script in $(rbenv-plugin-scripts rehash); do + source $script; done diff --git a/libexec/rbenv-which b/libexec/rbenv-which index 4ba82678..a47badd3 100755 --- a/libexec/rbenv-which +++ b/libexec/rbenv-which @@ -52,12 +52,8 @@ else RBENV_COMMAND_PATH="${RBENV_ROOT}/versions/${RBENV_VERSION}/bin/${RBENV_COMMAND}" fi -shopt -s nullglob -RBENV_WHICH_PLUGINS=(/etc/rbenv.d/which/*.bash ${RBENV_ROOT}/rbenv.d/which/*.bash) -shopt -u nullglob - -for script in ${RBENV_WHICH_PLUGINS[@]}; do - source $script +for script in $(rbenv-plugin-scripts which); do + source $script; done if [ -x "$RBENV_COMMAND_PATH" ]; then From 2b5fb40b99b555dcaed597faa1b7cd0f158c227a Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Wed, 21 Sep 2011 12:39:26 -0500 Subject: [PATCH 3/6] Not exec specific --- libexec/rbenv-plugin-scripts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libexec/rbenv-plugin-scripts b/libexec/rbenv-plugin-scripts index e77c8719..2bc5bfdf 100755 --- a/libexec/rbenv-plugin-scripts +++ b/libexec/rbenv-plugin-scripts @@ -11,9 +11,9 @@ if [ "$1" = "--complete" ]; then fi shopt -s nullglob -RBENV_EXEC_PLUGINS=(/etc/rbenv.d/$1/*.bash ${RBENV_ROOT}/rbenv.d/$1/*.bash) +SCRIPTS=(/etc/rbenv.d/$1/*.bash ${RBENV_ROOT}/rbenv.d/$1/*.bash) shopt -u nullglob -for script in ${RBENV_EXEC_PLUGINS[@]}; do +for script in ${SCRIPTS[@]}; do echo $script done From 0c7c62dc04dab195ff249bc93460a4c4c352ac00 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Wed, 21 Sep 2011 12:43:22 -0500 Subject: [PATCH 4/6] Show usage if no arguments are passed to rbenv-plugin-scripts --- libexec/rbenv-plugin-scripts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/libexec/rbenv-plugin-scripts b/libexec/rbenv-plugin-scripts index 2bc5bfdf..27568007 100755 --- a/libexec/rbenv-plugin-scripts +++ b/libexec/rbenv-plugin-scripts @@ -10,8 +10,14 @@ if [ "$1" = "--complete" ]; then exit fi +RBENV_COMMAND="$1" +if [ -z "$RBENV_COMMAND" ]; then + echo "usage: rbenv plugin-scripts COMMAND" >&2 + exit 1 +fi + shopt -s nullglob -SCRIPTS=(/etc/rbenv.d/$1/*.bash ${RBENV_ROOT}/rbenv.d/$1/*.bash) +SCRIPTS=(/etc/rbenv.d/"$RBENV_COMMAND"/*.bash ${RBENV_ROOT}/rbenv.d/"$RBENV_COMMAND"/*.bash) shopt -u nullglob for script in ${SCRIPTS[@]}; do From 096743acde3ff83e430ecc0b5c5fde1aa99163fc Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Wed, 21 Sep 2011 13:00:23 -0500 Subject: [PATCH 5/6] Add support for RBENV_PLUGIN_PATH environment variable --- libexec/rbenv | 3 +++ libexec/rbenv-plugin-scripts | 10 +++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/libexec/rbenv b/libexec/rbenv index 0a9d0122..aab66512 100755 --- a/libexec/rbenv +++ b/libexec/rbenv @@ -27,6 +27,9 @@ else fi export RBENV_ROOT + +export RBENV_PLUGIN_PATH="${RBENV_PLUGIN_PATH}:/etc/rbenv.d:${RBENV_ROOT}/rbenv.d" + libexec_path="$(abs_dirname "$0")" export PATH="${libexec_path}:${PATH}" diff --git a/libexec/rbenv-plugin-scripts b/libexec/rbenv-plugin-scripts index 27568007..af9648ed 100755 --- a/libexec/rbenv-plugin-scripts +++ b/libexec/rbenv-plugin-scripts @@ -17,9 +17,9 @@ if [ -z "$RBENV_COMMAND" ]; then fi shopt -s nullglob -SCRIPTS=(/etc/rbenv.d/"$RBENV_COMMAND"/*.bash ${RBENV_ROOT}/rbenv.d/"$RBENV_COMMAND"/*.bash) -shopt -u nullglob - -for script in ${SCRIPTS[@]}; do - echo $script +for path in ${RBENV_PLUGIN_PATH//:/$'\n'}; do + for script in $path/"$RBENV_COMMAND"/*.bash; do + echo $script + done done +shopt -u nullglob From 699cd8c2031561447e20b0163217ed3f9ae185a1 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Wed, 21 Sep 2011 13:05:08 -0500 Subject: [PATCH 6/6] Quote script path and remove unnecessary semicolon --- libexec/rbenv-exec | 2 +- libexec/rbenv-rehash | 2 +- libexec/rbenv-which | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libexec/rbenv-exec b/libexec/rbenv-exec index d940a7a3..892e17a9 100755 --- a/libexec/rbenv-exec +++ b/libexec/rbenv-exec @@ -17,7 +17,7 @@ RBENV_COMMAND_PATH="$(rbenv-which "$RBENV_COMMAND")" RBENV_BIN_PATH="${RBENV_COMMAND_PATH%/*}" for script in $(rbenv-plugin-scripts exec); do - source $script; + source "$script" done shift 1 diff --git a/libexec/rbenv-rehash b/libexec/rbenv-rehash index a11b64bd..ca83c54b 100755 --- a/libexec/rbenv-rehash +++ b/libexec/rbenv-rehash @@ -71,5 +71,5 @@ make_shims ../versions/*/bin/* cd "$CUR_PATH" for script in $(rbenv-plugin-scripts rehash); do - source $script; + source "$script" done diff --git a/libexec/rbenv-which b/libexec/rbenv-which index a47badd3..d22a91eb 100755 --- a/libexec/rbenv-which +++ b/libexec/rbenv-which @@ -53,7 +53,7 @@ else fi for script in $(rbenv-plugin-scripts which); do - source $script; + source "$script" done if [ -x "$RBENV_COMMAND_PATH" ]; then