From 493f036928b8ed9e456b2112475973e23b1ec330 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Wed, 8 Jul 2015 16:20:14 +0200 Subject: [PATCH] shims: handle symlinked scripts, via new PYENV_FILE_ARG `PYENV_FILE_ARG` is used here to make use of `abs_dirname` later in `libexec/pyenv`. Fixes https://github.com/yyuu/pyenv/issues/404 --- libexec/pyenv | 13 +++++++++++++ libexec/pyenv-rehash | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/libexec/pyenv b/libexec/pyenv index 9dd464a9..8173f6dc 100755 --- a/libexec/pyenv +++ b/libexec/pyenv @@ -54,6 +54,19 @@ else fi export PYENV_ROOT +# Transfer PYENV_FILE_ARG (from shims) into PYENV_DIR. +if [ -z "${PYENV_DIR}" ]; then + if [ -n "${PYENV_FILE_ARG}" ]; then + if [ -L "${PYENV_FILE_ARG}" ]; then + PYENV_DIR="$(abs_dirname "${PYENV_FILE_ARG}")" + else + PYENV_DIR="${PYENV_FILE_ARG%/*}" + fi + export PYENV_DIR + unset PYENV_FILE_ARG + fi +fi + if [ -z "${PYENV_DIR}" ]; then PYENV_DIR="$(pwd)" else diff --git a/libexec/pyenv-rehash b/libexec/pyenv-rehash index 56756fc3..a6451e0c 100755 --- a/libexec/pyenv-rehash +++ b/libexec/pyenv-rehash @@ -52,7 +52,7 @@ if [[ "\$program" = "python"* ]]; then -c* | -- ) break ;; */* ) if [ -f "\$arg" ]; then - export PYENV_DIR="\${arg%/*}" + export PYENV_FILE_ARG="\$arg" break fi ;;