When the ruby shim is invoked with a script, set RBENV_DIR to the script's dirname

This commit is contained in:
Sam Stephenson 2012-12-27 13:41:55 -06:00
parent 6c1fb9ffd0
commit 283e67b57e

View file

@ -37,8 +37,25 @@ create_prototype_shim() {
cat > "$PROTOTYPE_SHIM_PATH" <<SH
#!/usr/bin/env bash
set -e
[ -n "\$RBENV_DEBUG" ] && set -x
program="\${0##*/}"
if [ "\$program" = "ruby" ]; then
for arg; do
case "\$arg" in
-e* | -- ) break ;;
*/* )
if [ -f "\$arg" ]; then
export RBENV_DIR="\${arg%/*}"
break
fi
;;
esac
done
fi
export RBENV_ROOT="$RBENV_ROOT"
exec rbenv exec "\${0##*/}" "\$@"
exec rbenv exec "\$program" "\$@"
SH
chmod +x "$PROTOTYPE_SHIM_PATH"
}