1
0
mirror of https://github.com/pyenv/pyenv.git synced 2025-11-14 14:23:53 -05:00

rbenv exec: avoid mutating PATH

Enables shelling out from a ruby process started with rbenv to a ruby
process with a different RBENV_VERSION. Fixes #121

This removes the workaround created for #15 and solves `ruby -S` support
by setting RUBYPATH. PATH is never changed.

To illustrate how RUBYPATH changes in various configurations:

    PATH=~/bin:~/.rbenv/shims:/usr/bin:/bin
    RBENV_VERSION=1.8 ruby -S rake
    #=> executes ~/.rbenv/versions/1.8/bin/rake
    #=> RUBYPATH=~/bin:~/.rbenv/versions/1.8/bin:/usr/bin:/bin

    RBENV_VERSION=2.0 ruby -S rake
    #=> executes ~/.rbenv/versions/2.0/bin/rake
    #=> RUBYPATH=~/bin:~/.rbenv/versions/2.0/bin:/usr/bin:/bin

    RBENV_VERSION=system ruby -S rake
    #=> executes /usr/bin/rake
    #=> RUBYPATH=~/bin:/rbenv_shims_were_here:/usr/bin:/bin

    RBENV_VERSION=1.8 ruby -S rake
    #=> executes ~/.rbenv/versions/1.8/bin/rake
    #=> RUBYPATH=~/bin:~/.rbenv/versions/1.8/bin:/usr/bin:/bin
This commit is contained in:
Mislav Marohnić
2013-06-20 17:22:15 +02:00
parent 8b043038b8
commit db143bb654
3 changed files with 275 additions and 37 deletions

View File

@@ -45,10 +45,12 @@ create_prototype_shim() {
set -e
[ -n "\$RBENV_DEBUG" ] && set -x
opt=""
program="\${0##*/}"
if [ "\$program" = "ruby" ]; then
for arg; do
case "\$arg" in
-S* ) opt=--rubypath ;;
-e* | -- ) break ;;
*/* )
if [ -f "\$arg" ]; then
@@ -61,7 +63,7 @@ if [ "\$program" = "ruby" ]; then
fi
export RBENV_ROOT="$RBENV_ROOT"
exec "$(command -v rbenv)" exec "\$program" "\$@"
exec "$(command -v rbenv)" exec \$opt "\$program" "\$@"
SH
chmod +x "$PROTOTYPE_SHIM_PATH"
}