From 5bff9c773a24f801bf68a65011b55ef453a7e273 Mon Sep 17 00:00:00 2001 From: Yamashita Yuu Date: Thu, 26 Dec 2013 13:48:43 +0900 Subject: [PATCH] Reliably detect parent shell in `pyenv init` (fixes #93) Imported changes from sstephenson/rbenv#453. --- libexec/pyenv-init | 22 +++++++++++++++++++--- libexec/pyenv-sh-rehash | 8 +++----- libexec/pyenv-sh-shell | 2 +- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/libexec/pyenv-init b/libexec/pyenv-init index 25a029b0..c66e33e4 100755 --- a/libexec/pyenv-init +++ b/libexec/pyenv-init @@ -22,7 +22,9 @@ 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="${shell##-}" + shell="$(basename "${shell:-$SHELL}")" fi READLINK=$(type -p greadlink readlink | head -1) @@ -75,7 +77,7 @@ if [ -z "$print" ]; then echo case "$shell" in fish ) - echo '. (pyenv init -|psub)' + echo 'status --is-interactive; and . (pyenv init -|psub)' ;; * ) echo 'eval "$(pyenv init -)"' @@ -100,8 +102,22 @@ if [[ ":${PATH}:" != *:"${PYENV_ROOT}/shims":* ]]; then esac fi +case "$shell" in +fish ) + echo "setenv PYENV_SHELL $shell" +;; +* ) + echo "export PYENV_SHELL=$shell" +;; +esac + completion="${root}/completions/pyenv.${shell}" -[ -r "$completion" ] && echo ". '$completion'" +if [ -r "$completion" ]; then + case "$shell" in + fish ) echo ". '$completion'" ;; + * ) echo "source '$completion'" ;; + esac +fi if [ -z "$no_rehash" ]; then echo 'pyenv rehash 2>/dev/null' diff --git a/libexec/pyenv-sh-rehash b/libexec/pyenv-sh-rehash index e117d8b9..ab50346d 100755 --- a/libexec/pyenv-sh-rehash +++ b/libexec/pyenv-sh-rehash @@ -7,7 +7,7 @@ if [ "$1" = "--complete" ]; then exec pyenv-rehash --complete fi -shell="$(basename "$SHELL")" +shell="$(basename "${PYENV_SHELL:-$SHELL}")" # When pyenv shell integration is enabled, delegate to pyenv-rehash, # then tell the shell to empty its command lookup cache. @@ -15,11 +15,9 @@ pyenv-rehash case "$shell" in fish ) - or='; or' + # no rehash support ;; * ) - or='||' + echo "hash -r 2>/dev/null || true" ;; esac - -echo "hash -r 2>/dev/null $or true" diff --git a/libexec/pyenv-sh-shell b/libexec/pyenv-sh-shell index 857359a4..1e9f5667 100755 --- a/libexec/pyenv-sh-shell +++ b/libexec/pyenv-sh-shell @@ -24,7 +24,7 @@ if [ "$1" = "--complete" ]; then fi versions=("$@") -shell="$(basename "$SHELL")" +shell="$(basename "${PYENV_SHELL:-$SHELL}")" if [ -z "$versions" ]; then if [ -z "$PYENV_VERSION" ]; then