mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2024-11-11 00:10:08 +00:00
fix(pyenv): fix pyenv PATH settings with a warning (#9935)
This change fixes the setting of $PATH for pyenv and its shims, while warning the user about non-interactive shells. Co-authored-by: Marc Cornellà <hello@mcornella.com>
This commit is contained in:
parent
d9ad99531f
commit
c8a258698d
1 changed files with 52 additions and 29 deletions
|
@ -8,36 +8,59 @@ else
|
|||
FOUND_PYENV=0
|
||||
fi
|
||||
|
||||
# Look for pyenv and try to load it (will only work on interactive shells)
|
||||
if [[ $FOUND_PYENV -ne 1 ]]; then
|
||||
pyenvdirs=("$HOME/.pyenv" "/usr/local/pyenv" "/opt/pyenv" "/usr/local/opt/pyenv")
|
||||
for dir in $pyenvdirs; do
|
||||
if [[ -d $dir/bin ]]; then
|
||||
export PATH="$PATH:$dir/bin"
|
||||
if [[ -d "$dir/bin" ]]; then
|
||||
FOUND_PYENV=1
|
||||
break
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
if [[ $FOUND_PYENV -ne 1 ]]; then
|
||||
if (( $+commands[brew] )) && dir=$(brew --prefix pyenv 2>/dev/null); then
|
||||
if [[ -d $dir/bin ]]; then
|
||||
export PATH="$PATH:$dir/bin"
|
||||
if [[ -d "$dir/bin" ]]; then
|
||||
FOUND_PYENV=1
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
# If we found pyenv, load it but show a caveat about non-interactive shells
|
||||
if [[ $FOUND_PYENV -eq 1 ]]; then
|
||||
cat <<EOF
|
||||
Found pyenv, but it is badly configured. pyenv might not work for
|
||||
non-interactive shells (for example, when run from a script).
|
||||
${bold_color}
|
||||
To fix this message, add these lines to the '.profile' and '.zprofile' files
|
||||
in your home directory:
|
||||
|
||||
export PYENV_ROOT="${dir/#$HOME/\$HOME}"
|
||||
export PATH="\$PYENV_ROOT/bin:\$PATH"
|
||||
eval "\$(pyenv init --path)"
|
||||
${reset_color}
|
||||
For more info go to https://github.com/pyenv/pyenv/#installation.
|
||||
EOF
|
||||
|
||||
# Configuring in .zshrc only makes pyenv available for interactive shells
|
||||
export PYENV_ROOT=$dir
|
||||
export PATH="$PYENV_ROOT/bin:$PATH"
|
||||
eval "$(pyenv init --path)"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ $FOUND_PYENV -eq 1 ]]; then
|
||||
eval "$(pyenv init - --no-rehash zsh)"
|
||||
if (( $+commands[pyenv-virtualenv-init] )); then
|
||||
|
||||
if (( ${+commands[pyenv-virtualenv-init]} )); then
|
||||
eval "$(pyenv virtualenv-init - zsh)"
|
||||
fi
|
||||
|
||||
function pyenv_prompt_info() {
|
||||
echo "$(pyenv version-name)"
|
||||
}
|
||||
else
|
||||
# fallback to system python
|
||||
# Fall back to system python
|
||||
function pyenv_prompt_info() {
|
||||
echo "system: $(python -V 2>&1 | cut -f 2 -d ' ')"
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue