From 8efcf2776b2e7e00c073b149f76c04715aa695d3 Mon Sep 17 00:00:00 2001 From: Terrance Kennedy Date: Sun, 22 Apr 2018 12:03:58 -0600 Subject: pyenv plugin refactor (8x faster) (#6165) * Refactor pyenv plugin to use PATH --- plugins/pyenv/pyenv.plugin.zsh | 61 ++++++++++-------------------------------- 1 file changed, 14 insertions(+), 47 deletions(-) (limited to 'plugins/pyenv') diff --git a/plugins/pyenv/pyenv.plugin.zsh b/plugins/pyenv/pyenv.plugin.zsh index ec3ae9f5b..76880e415 100644 --- a/plugins/pyenv/pyenv.plugin.zsh +++ b/plugins/pyenv/pyenv.plugin.zsh @@ -1,50 +1,17 @@ -_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=0 -pyenvdirs=("$HOME/.pyenv" "/usr/local/pyenv" "/opt/pyenv") - -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)" - fi - - function pyenv_prompt_info() { - echo "$(pyenv version-name)" - } - fi -done -unset pyenvdir - -if [ $FOUND_PYENV -eq 0 ] ; then - pyenvdir=$(brew --prefix pyenv 2> /dev/null) - if [ $? -eq 0 -a -d $pyenvdir/bin ] ; 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)" - fi - - function pyenv_prompt_info() { - echo "$(pyenv version-name)" - } +if (( $+commands[pyenv] )); then + eval "$(pyenv init - zsh)" + if (( $+commands[pyenv-virtualenv-init] )); then + eval "$(pyenv virtualenv-init - zsh)" fi -fi - -if [ $FOUND_PYENV -eq 0 ] ; then - function pyenv_prompt_info() { echo "system: $(python -V 2>&1 | cut -f 2 -d ' ')" } + 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 -- cgit v1.2.3-70-g09d2 From 0aa645f8033ef86f8c8b0729a94fc54fbec49a25 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Tue, 15 May 2018 12:07:23 +0200 Subject: pyenv: search the pyenv command if not found (#6811) --- plugins/pyenv/pyenv.plugin.zsh | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'plugins/pyenv') diff --git a/plugins/pyenv/pyenv.plugin.zsh b/plugins/pyenv/pyenv.plugin.zsh index 76880e415..dbc7da472 100644 --- a/plugins/pyenv/pyenv.plugin.zsh +++ b/plugins/pyenv/pyenv.plugin.zsh @@ -1,7 +1,29 @@ # This plugin loads pyenv into the current shell and provides prompt info via # the 'pyenv_prompt_info' function. Also loads pyenv-virtualenv if available. -if (( $+commands[pyenv] )); then +FOUND_PYENV=$+commands[pyenv] + +if [[ $FOUND_PYENV -ne 1 ]]; then + pyenvdirs=("$HOME/.pyenv" "/usr/local/pyenv" "/opt/pyenv") + for dir in $pyenvdirs; do + if [[ -d $dir/bin ]]; then + export PATH="$PATH:$dir/bin" + 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" + FOUND_PYENV=1 + fi + fi +fi + +if [[ $FOUND_PYENV -eq 1 ]]; then eval "$(pyenv init - zsh)" if (( $+commands[pyenv-virtualenv-init] )); then eval "$(pyenv virtualenv-init - zsh)" @@ -15,3 +37,5 @@ else echo "system: $(python -V 2>&1 | cut -f 2 -d ' ')" } fi + +unset FOUND_PYENV dir -- cgit v1.2.3-70-g09d2