diff options
| author | Marc Cornellà <marc.cornella@live.com> | 2019-10-24 17:57:01 +0200 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-10-24 17:57:01 +0200 | 
| commit | cad48e38bfbfa6e3e0096caddf330d6fc8f1ffb9 (patch) | |
| tree | 2b07ec259bbd2b1a4919245669900a87fa87a03b /plugins/pyenv | |
| parent | 225425fe091ca052997833279ccc08643818c24a (diff) | |
| parent | 40df67bc3b9b51caa24df5d220487043040d1f9a (diff) | |
| download | zsh-cad48e38bfbfa6e3e0096caddf330d6fc8f1ffb9.tar.gz zsh-cad48e38bfbfa6e3e0096caddf330d6fc8f1ffb9.tar.bz2 zsh-cad48e38bfbfa6e3e0096caddf330d6fc8f1ffb9.zip  | |
Merge branch 'master' into fabric_task_description
Diffstat (limited to 'plugins/pyenv')
| -rw-r--r-- | plugins/pyenv/README.md | 16 | ||||
| -rw-r--r-- | plugins/pyenv/pyenv.plugin.zsh | 60 | 
2 files changed, 49 insertions, 27 deletions
diff --git a/plugins/pyenv/README.md b/plugins/pyenv/README.md new file mode 100644 index 000000000..d063b55b9 --- /dev/null +++ b/plugins/pyenv/README.md @@ -0,0 +1,16 @@ +# pyenv  + +This plugin looks for [pyenv](https://github.com/pyenv/pyenv), a Simple Python version +management system, and loads it if it's found. It also loads pyenv-virtualenv, a pyenv +plugin to manage virtualenv, if it's found. + +To use it, add `pyenv` to the plugins array in your zshrc file: + +```zsh +plugins=(... pyenv) +``` + +## Functions + +- `pyenv_prompt_info`: displays the Python version in use by pyenv; or the global Python +  version, if pyenv wasn't found. diff --git a/plugins/pyenv/pyenv.plugin.zsh b/plugins/pyenv/pyenv.plugin.zsh index aa1f9488a..40e58b5c2 100644 --- a/plugins/pyenv/pyenv.plugin.zsh +++ b/plugins/pyenv/pyenv.plugin.zsh @@ -1,35 +1,41 @@ -_homebrew-installed() { -    type brew &> /dev/null -} +# This plugin loads pyenv into the current shell and provides prompt info via +# the 'pyenv_prompt_info' function. Also loads pyenv-virtualenv if available. -_pyenv-from-homebrew-installed() { -    brew --prefix pyenv &> /dev/null -} +FOUND_PYENV=$+commands[pyenv] -FOUND_PYENV=0 -pyenvdirs=("$HOME/.pyenv" "/usr/local/pyenv" "/opt/pyenv") -if _homebrew-installed && _pyenv-from-homebrew-installed ; then -    pyenvdirs=($(brew --prefix pyenv) "${pyenvdirs[@]}") +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" +            FOUND_PYENV=1 +            break +        fi +    done  fi -for pyenvdir in "${pyenvdirs[@]}" ; do -    if [ -d $pyenvdir/bin -a $FOUND_PYENV -eq 0 ] ; then -        FOUND_PYENV=1 -        export PYENV_ROOT=$pyenvdir -        export PATH=${pyenvdir}/bin:$PATH -        eval "$(pyenv init - zsh)" - -        if pyenv commands | command grep -q virtualenv-init; then -            eval "$(pyenv virtualenv-init - zsh)" +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" +            FOUND_PYENV=1          fi - -        function pyenv_prompt_info() { -            echo "$(pyenv version-name)" -        }      fi -done -unset pyenvdir +fi -if [ $FOUND_PYENV -eq 0 ] ; then -    function pyenv_prompt_info() { echo "system: $(python -V 2>&1 | cut -f 2 -d ' ')" } +if [[ $FOUND_PYENV -eq 1 ]]; then +    eval "$(pyenv init - zsh)" +    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 +    function pyenv_prompt_info() { +        echo "system: $(python -V 2>&1 | cut -f 2 -d ' ')" +    }  fi + +unset FOUND_PYENV pyenvdirs dir  | 
