From 3194442759d40e8b577615918340db332a3df589 Mon Sep 17 00:00:00 2001 From: Zach Whaley Date: Thu, 17 Aug 2017 15:37:08 -0500 Subject: [PATCH] Edit pyenv virtualenv-init check to support non-brew installations If the pyenv virtualenv plugin is installed using the [pyenv-installer][1] app script or directly via a [Git clone][2], then the pyenv-virtualenv-init executable, that the `pyenv virtualenv-init` command uses, will not exist in the user's PATH and therefore cannot be found using `$commands[pyenv-virtualenv-init]`. Installing the pyenv-virtualenv plugin in this manner is common among Linux users. Using the pyenv `commands` command, which lists all commands pyenv can run, we can find if the virtualenv-init command is available to pyenv and subsequently the virtualenv plugin, without relying on pyenv-virtualenv-init to exist in the user's PATH. [1]: https://github.com/pyenv/pyenv-installer [2]: https://github.com/pyenv/pyenv-virtualenv#installing-as-a-pyenv-plugin --- modules/python/init.zsh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/python/init.zsh b/modules/python/init.zsh index 715ca25..7363728 100644 --- a/modules/python/init.zsh +++ b/modules/python/init.zsh @@ -93,7 +93,9 @@ if (( $+VIRTUALENVWRAPPER_VIRTUALENV || $+commands[virtualenv] )) && \ VIRTUAL_ENV_DISABLE_PROMPT=1 # Enable 'virtualenv' with 'pyenv'. - if (( $+commands[pyenv] && $+commands[pyenv-virtualenv-init] )); then + if (( $+commands[pyenv] )) && \ + pyenv commands | command grep -q virtualenv-init + then eval "$(pyenv virtualenv-init -)" # Optionall activate 'virtualenvwrapper' with 'pyenv' is available. if (( $#commands[(i)pyenv-virtualenvwrapper(_lazy|)] )); then