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/pyenv.plugin.zsh') 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/pyenv.plugin.zsh') 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 From a43cef34043dae63d73cd40b7e887a43e7b93680 Mon Sep 17 00:00:00 2001 From: Oleg Smelov Date: Fri, 29 Mar 2019 23:17:19 +0200 Subject: pyenv: detect pyenv from Homebrew faster (#7670) --- plugins/pyenv/pyenv.plugin.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugins/pyenv/pyenv.plugin.zsh') diff --git a/plugins/pyenv/pyenv.plugin.zsh b/plugins/pyenv/pyenv.plugin.zsh index dbc7da472..4e92b8017 100644 --- a/plugins/pyenv/pyenv.plugin.zsh +++ b/plugins/pyenv/pyenv.plugin.zsh @@ -4,7 +4,7 @@ FOUND_PYENV=$+commands[pyenv] if [[ $FOUND_PYENV -ne 1 ]]; then - pyenvdirs=("$HOME/.pyenv" "/usr/local/pyenv" "/opt/pyenv") + 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" -- cgit v1.2.3-70-g09d2 From 20ecca2ba9a9cf88a48fdfc48c4d3e2718752843 Mon Sep 17 00:00:00 2001 From: Thomas Kriechbaumer Date: Wed, 8 May 2019 09:51:05 +0200 Subject: rbenv: improve rbenv loading based on pyenv (#7626) --- plugins/pyenv/pyenv.plugin.zsh | 2 +- plugins/rbenv/rbenv.plugin.zsh | 87 ++++++++++++++++++++++-------------------- 2 files changed, 47 insertions(+), 42 deletions(-) (limited to 'plugins/pyenv/pyenv.plugin.zsh') diff --git a/plugins/pyenv/pyenv.plugin.zsh b/plugins/pyenv/pyenv.plugin.zsh index 4e92b8017..40e58b5c2 100644 --- a/plugins/pyenv/pyenv.plugin.zsh +++ b/plugins/pyenv/pyenv.plugin.zsh @@ -38,4 +38,4 @@ else } fi -unset FOUND_PYENV dir +unset FOUND_PYENV pyenvdirs dir diff --git a/plugins/rbenv/rbenv.plugin.zsh b/plugins/rbenv/rbenv.plugin.zsh index 7430e9625..ed46d355b 100644 --- a/plugins/rbenv/rbenv.plugin.zsh +++ b/plugins/rbenv/rbenv.plugin.zsh @@ -1,60 +1,65 @@ -_homebrew-installed() { - type brew &> /dev/null -} - -FOUND_RBENV=0 -rbenvdirs=("$HOME/.rbenv" "/usr/local/rbenv" "/opt/rbenv" "/usr/local/opt/rbenv") -if _homebrew-installed && rbenv_homebrew_path=$(brew --prefix rbenv 2>/dev/null); then - rbenvdirs=($rbenv_homebrew_path "${rbenvdirs[@]}") - unset rbenv_homebrew_path - if [[ $RBENV_ROOT = '' ]]; then - RBENV_ROOT="$HOME/.rbenv" - fi +# This plugin loads rbenv into the current shell and provides prompt info via +# the 'rbenv_prompt_info' function. + +FOUND_RBENV=$+commands[rbenv] + +if [[ $FOUND_RBENV -ne 1 ]]; then + rbenvdirs=("$HOME/.rbenv" "/usr/local/rbenv" "/opt/rbenv" "/usr/local/opt/rbenv") + for dir in $rbenvdirs; do + if [[ -d $dir/bin ]]; then + export PATH="$dir/bin:$PATH" + FOUND_RBENV=1 + break + fi + done fi -for rbenvdir in "${rbenvdirs[@]}" ; do - if [ -d $rbenvdir/bin -a $FOUND_RBENV -eq 0 ] ; then - FOUND_RBENV=1 - if [[ $RBENV_ROOT = '' ]]; then - RBENV_ROOT=$rbenvdir +if [[ $FOUND_RBENV -ne 1 ]]; then + if (( $+commands[brew] )) && dir=$(brew --prefix rbenv 2>/dev/null); then + if [[ -d $dir/bin ]]; then + export PATH="$dir/bin:$PATH" + FOUND_RBENV=1 + fi fi - export RBENV_ROOT - export PATH=${rbenvdir}/bin:$PATH +fi + +if [[ $FOUND_RBENV -eq 1 ]]; then eval "$(rbenv init --no-rehash - zsh)" alias rubies="rbenv versions" alias gemsets="rbenv gemset list" function current_ruby() { - echo "$(rbenv version-name)" + echo "$(rbenv version-name)" } function current_gemset() { - echo "$(rbenv gemset active 2&>/dev/null | sed -e ":a" -e '$ s/\n/+/gp;N;b a' | head -n1)" + echo "$(rbenv gemset active 2&>/dev/null | sed -e ":a" -e '$ s/\n/+/gp;N;b a' | head -n1)" } - function gems { - local rbenv_path=$(rbenv prefix) - gem list $@ | sed -E \ - -e "s/\([0-9a-z, \.]+( .+)?\)/$fg[blue]&$reset_color/g" \ - -e "s|$(echo $rbenv_path)|$fg[magenta]\$rbenv_path$reset_color|g" \ - -e "s/$current_ruby@global/$fg[yellow]&$reset_color/g" \ - -e "s/$current_ruby$current_gemset$/$fg[green]&$reset_color/g" + function gems() { + local rbenv_path=$(rbenv prefix) + gem list $@ | sed -E \ + -e "s/\([0-9a-z, \.]+( .+)?\)/$fg[blue]&$reset_color/g" \ + -e "s|$(echo $rbenv_path)|$fg[magenta]\$rbenv_path$reset_color|g" \ + -e "s/$current_ruby@global/$fg[yellow]&$reset_color/g" \ + -e "s/$current_ruby$current_gemset$/$fg[green]&$reset_color/g" } function rbenv_prompt_info() { - if [[ -n $(current_gemset) ]] ; then - echo "$(current_ruby)@$(current_gemset)" - else - echo "$(current_ruby)" - fi + if [[ -n $(current_gemset) ]] ; then + echo "$(current_ruby)@$(current_gemset)" + else + echo "$(current_ruby)" + fi } - fi -done -unset rbenvdir - -if [ $FOUND_RBENV -eq 0 ] ; then - alias rubies='ruby -v' - function gemsets() { echo 'not supported' } - function rbenv_prompt_info() { echo "system: $(ruby -v | cut -f-2 -d ' ')" } +else + alias rubies="ruby -v" + function gemsets() { echo "not supported" } + function current_ruby() { echo "not supported" } + function current_gemset() { echo "not supported" } + function gems() { echo "not supported" } + function rbenv_prompt_info() { echo "system: $(ruby -v | cut -f-2 -d ' ')" } fi + +unset FOUND_RBENV rbenvdirs dir -- cgit v1.2.3-70-g09d2