mirror of
https://github.com/pyenv/pyenv.git
synced 2025-11-17 15:53:45 -05:00
reliably detect parent shell in rbenv init
`$SHELL` variable is a terrible way of detecting the current shell because it's not even supposed to reflect the current shell; it's meant for keeping the value of the default shell for programs to start. If an explicit `<shell>` argument wasn't passed to `rbenv init`, it tries to detect the shell by getting the name of its parent process. If this fails, it falls back on the value of `$SHELL` as before. Furthermore, `rbenv init` will set the RBENV_SHELL variable in the current shell to the value of the detected shell so that `sh-shell` and `sh-rehash` commands don't have to repeat the detection.
This commit is contained in:
@@ -22,7 +22,8 @@ done
|
||||
|
||||
shell="$1"
|
||||
if [ -z "$shell" ]; then
|
||||
shell="$(basename "$SHELL")"
|
||||
shell="$(ps c -p $(ps -p $$ -o 'ppid=' 2>/dev/null) -o 'comm=' 2>/dev/null || true)"
|
||||
shell="$(basename "${shell:-$SHELL}")"
|
||||
fi
|
||||
|
||||
READLINK=$(type -p greadlink readlink | head -1)
|
||||
@@ -100,6 +101,15 @@ if [[ ":${PATH}:" != *:"${RBENV_ROOT}/shims":* ]]; then
|
||||
esac
|
||||
fi
|
||||
|
||||
case "$shell" in
|
||||
fish )
|
||||
echo "setenv RBENV_SHELL $shell"
|
||||
;;
|
||||
* )
|
||||
echo "export RBENV_SHELL=$shell"
|
||||
;;
|
||||
esac
|
||||
|
||||
completion="${root}/completions/rbenv.${shell}"
|
||||
if [ -r "$completion" ]; then
|
||||
case "$shell" in
|
||||
|
||||
@@ -7,7 +7,7 @@ if [ "$1" = "--complete" ]; then
|
||||
exec rbenv-rehash --complete
|
||||
fi
|
||||
|
||||
shell="$(basename "$SHELL")"
|
||||
shell="$(basename "${RBENV_SHELL:-$SHELL}")"
|
||||
|
||||
# When rbenv shell integration is enabled, delegate to rbenv-rehash,
|
||||
# then tell the shell to empty its command lookup cache.
|
||||
|
||||
@@ -24,7 +24,7 @@ if [ "$1" = "--complete" ]; then
|
||||
fi
|
||||
|
||||
version="$1"
|
||||
shell="$(basename "$SHELL")"
|
||||
shell="$(basename "${RBENV_SHELL:-$SHELL}")"
|
||||
|
||||
if [ -z "$version" ]; then
|
||||
if [ -z "$RBENV_VERSION" ]; then
|
||||
|
||||
Reference in New Issue
Block a user