diff options
author | Tuowen Zhao <ztuowen@gmail.com> | 2021-09-10 20:10:26 -0600 |
---|---|---|
committer | Tuowen Zhao <ztuowen@gmail.com> | 2021-09-10 20:10:26 -0600 |
commit | 3c73976ef306d68a85d60c94be9a1dcdc33fa2bf (patch) | |
tree | 619ba4b5874b92ada9dc089c67a435dd3149748a /plugins/pyenv/pyenv.plugin.zsh | |
parent | f8b7b6584bf1ca7e836ba9cc13fcce573047fb07 (diff) | |
parent | 735808f48d54aabce540f6c90294e21118104cf4 (diff) | |
download | zsh-3c73976ef306d68a85d60c94be9a1dcdc33fa2bf.tar.gz zsh-3c73976ef306d68a85d60c94be9a1dcdc33fa2bf.tar.bz2 zsh-3c73976ef306d68a85d60c94be9a1dcdc33fa2bf.zip |
Merge remote-tracking branch 'origin/master'
Diffstat (limited to 'plugins/pyenv/pyenv.plugin.zsh')
-rw-r--r-- | plugins/pyenv/pyenv.plugin.zsh | 57 |
1 files changed, 41 insertions, 16 deletions
diff --git a/plugins/pyenv/pyenv.plugin.zsh b/plugins/pyenv/pyenv.plugin.zsh index 813f64b42..d91b5daa7 100644 --- a/plugins/pyenv/pyenv.plugin.zsh +++ b/plugins/pyenv/pyenv.plugin.zsh @@ -1,3 +1,24 @@ +pyenv_config_warning() { + [[ "$ZSH_PYENV_QUIET" != true ]] || return 0 + + local reason="$1" + local pyenv_root="${PYENV_ROOT/#$HOME/\$HOME}" + cat >&2 <<EOF +Found pyenv, but it is badly configured ($reason). pyenv might not +work correctly for non-interactive shells (for example, when run from a script). +${(%):-"%B%F{yellow}"} +To fix this message, add these lines to the '.profile' and '.zprofile' files +in your home directory: +${(%):-"%f"} +export PYENV_ROOT="$pyenv_root" +export PATH="\$PYENV_ROOT/bin:\$PATH" +eval "\$(pyenv init --path)" +${(%):-"%F{yellow}"} +You'll need to restart your user session for the changes to take effect.${(%):-%b%f} +For more information go to https://github.com/pyenv/pyenv/#installation. +EOF +} + # This plugin loads pyenv into the current shell and provides prompt info via # the 'pyenv_prompt_info' function. Also loads pyenv-virtualenv if available. @@ -30,31 +51,34 @@ if [[ $FOUND_PYENV -ne 1 ]]; then # 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 PYENV_ROOT="$dir" export PATH="$PYENV_ROOT/bin:$PATH" eval "$(pyenv init --path)" + + # Show warning due to bad pyenv configuration + pyenv_config_warning 'pyenv command not found in $PATH' fi fi if [[ $FOUND_PYENV -eq 1 ]]; then + if [[ -z "$PYENV_ROOT" ]]; then + # This is only for backwards compatibility with users that previously relied + # on this plugin exporting it. pyenv itself does not require it to be exported + export PYENV_ROOT="$(pyenv root)" + fi + + # Add pyenv shims to $PATH if not already added + if [[ -z "${path[(Re)$(pyenv root)/shims]}" ]]; then + eval "$(pyenv init --path)" + pyenv_config_warning 'missing pyenv shims in $PATH' + fi + + # Load pyenv eval "$(pyenv init - --no-rehash zsh)" - if (( ${+commands[pyenv-virtualenv-init]} )); then + # If pyenv-virtualenv exists, load it + if [[ -d "$(pyenv root)/plugins/pyenv-virtualenv" && "$ZSH_PYENV_VIRTUALENV" != false ]]; then eval "$(pyenv virtualenv-init - zsh)" fi @@ -69,3 +93,4 @@ else fi unset FOUND_PYENV pyenvdirs dir +unfunction pyenv_config_warning |