summaryrefslogtreecommitdiff
path: root/plugins/pyenv
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/pyenv')
-rw-r--r--plugins/pyenv/README.md18
-rw-r--r--plugins/pyenv/pyenv.plugin.zsh14
2 files changed, 29 insertions, 3 deletions
diff --git a/plugins/pyenv/README.md b/plugins/pyenv/README.md
index b9ee937b7..2476bbd95 100644
--- a/plugins/pyenv/README.md
+++ b/plugins/pyenv/README.md
@@ -2,7 +2,7 @@
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.
+plugin to manage virtualenv, if it's found. If a venv is found pyenv won't load.
To use it, add `pyenv` to the plugins array in your zshrc file:
@@ -10,6 +10,14 @@ To use it, add `pyenv` to the plugins array in your zshrc file:
plugins=(... pyenv)
```
+If you receive a `Found pyenv, but it is badly configured.` error on startup, you may need to ensure that `pyenv` is initialized before the oh-my-zsh pyenv plugin is loaded. This can be achieved by adding the following earlier in the `.zshrc` file than the `plugins=(...)` line:
+
+```zsh
+export PYENV_ROOT="$HOME/.pyenv"
+export PATH="$PYENV_ROOT/bin:$PATH"
+eval "$(pyenv init --path)"
+```
+
## Settings
- `ZSH_PYENV_QUIET`: if set to `true`, the plugin will not print any messages if it
@@ -18,6 +26,14 @@ plugins=(... pyenv)
- `ZSH_PYENV_VIRTUALENV`: if set to `false`, the plugin will not load pyenv-virtualenv
when it finds it.
+- `ZSH_THEME_PYENV_NO_SYSTEM`: if set to `true`, the plugin will not show the system or
+ default Python version when it finds it.
+- `ZSH_THEME_PYENV_PREFIX`: the prefix to display before the Python version in
+ the prompt.
+
+- `ZSH_THEME_PYENV_SUFFIX`: the prefix to display after the Python version in
+ the prompt.
+
## Functions
- `pyenv_prompt_info`: displays the Python version in use by pyenv; or the global Python
diff --git a/plugins/pyenv/pyenv.plugin.zsh b/plugins/pyenv/pyenv.plugin.zsh
index 48c8ffaf5..cd2a9e0ac 100644
--- a/plugins/pyenv/pyenv.plugin.zsh
+++ b/plugins/pyenv/pyenv.plugin.zsh
@@ -1,3 +1,7 @@
+# if there is a virtualenv already loaded pyenv should not be loaded
+# see https://github.com/ohmyzsh/ohmyzsh/issues/12589
+[[ -n ${VIRTUAL_ENV:-} ]] && return
+
pyenv_config_warning() {
[[ "$ZSH_PYENV_QUIET" != true ]] || return 0
@@ -84,13 +88,19 @@ if [[ $FOUND_PYENV -eq 1 ]]; then
function pyenv_prompt_info() {
local version="$(pyenv version-name)"
- echo "${version:gs/%/%%}"
+ if [[ "$ZSH_THEME_PYENV_NO_SYSTEM" == "true" ]] && [[ "${version}" == "system" ]]; then
+ return
+ fi
+ echo "${ZSH_THEME_PYENV_PREFIX=}${version:gs/%/%%}${ZSH_THEME_PYENV_SUFFIX=}"
}
else
# Fall back to system python
function pyenv_prompt_info() {
+ if [[ "$ZSH_THEME_PYENV_NO_SYSTEM" == "true" ]]; then
+ return
+ fi
local version="$(python3 -V 2>&1 | cut -d' ' -f2)"
- echo "system: ${version:gs/%/%%}"
+ echo "${ZSH_THEME_PYENV_PREFIX=}system: ${version:gs/%/%%}${ZSH_THEME_PYENV_SUFFIX=}"
}
fi