Merge branch 'detect-shell-from-script'

Closes #730
This commit is contained in:
Mislav Marohnić 2015-12-24 13:24:54 +01:00
commit d51f6d4376
2 changed files with 15 additions and 3 deletions

View file

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

View file

@ -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 <<OUT
#!/bin/sh
eval "\$(rbenv-init -)"
echo \$RBENV_SHELL
OUT
chmod +x myscript.sh
run ./myscript.sh /bin/zsh
assert_success "sh"
}
@test "setup shell completions (fish)" {
root="$(cd $BATS_TEST_DIRNAME/.. && pwd)"
run rbenv-init - fish