diff --git a/libexec/rbenv-init b/libexec/rbenv-init index 8e6ee3d8..7ddae5e5 100755 --- a/libexec/rbenv-init +++ b/libexec/rbenv-init @@ -33,9 +33,9 @@ done shell="$1" if [ -z "$shell" ]; then - shell="$(ps c -p "$PPID" -o 'ucomm=' 2>/dev/null || true)" - shell="${shell##-}" + shell="$(ps -p "$PPID" -o 'args=' 2>/dev/null || true)" shell="${shell%% *}" + shell="${shell##-}" shell="${shell:-$SHELL}" shell="${shell##*/}" fi diff --git a/test/init.bats b/test/init.bats index 0a46dd0d..d7005489 100644 --- a/test/init.bats +++ b/test/init.bats @@ -25,12 +25,24 @@ load test_helper } @test "detect parent shell" { - root="$(cd $BATS_TEST_DIRNAME/.. && pwd)" SHELL=/bin/false run rbenv-init - assert_success assert_line "export RBENV_SHELL=bash" } +@test "detect parent shell from script" { + mkdir -p "$RBENV_TEST_DIR" + cd "$RBENV_TEST_DIR" + cat > myscript.sh <