From d9f9043f30f0fa46c1a37710cb7cae65f5d83fcf Mon Sep 17 00:00:00 2001 From: Olivier Mehani Date: Thu, 10 Oct 2024 12:07:05 +1100 Subject: [PATCH] feat(pyenv): add option to hide system Python version Added ZSH_PYENV_NO_SYSTEM option to hide the system or default Python version in the prompt. --- plugins/pyenv/README.md | 3 +++ plugins/pyenv/pyenv.plugin.zsh | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/plugins/pyenv/README.md b/plugins/pyenv/README.md index 86953895a..b340ae7b9 100644 --- a/plugins/pyenv/README.md +++ b/plugins/pyenv/README.md @@ -23,6 +23,9 @@ eval "$(pyenv init --path)" - `ZSH_PYENV_QUIET`: if set to `true`, the plugin will not print any messages if it finds that `pyenv` is not properly configured. +- `ZSH_PYENV_NO_SYSTEM`: if set to `true`, the plugin will not show the system or + default Python version when it finds it. + - `ZSH_PYENV_VIRTUALENV`: if set to `false`, the plugin will not load pyenv-virtualenv when it finds it. diff --git a/plugins/pyenv/pyenv.plugin.zsh b/plugins/pyenv/pyenv.plugin.zsh index 8d66e62e0..b07b964ca 100644 --- a/plugins/pyenv/pyenv.plugin.zsh +++ b/plugins/pyenv/pyenv.plugin.zsh @@ -88,11 +88,17 @@ if [[ $FOUND_PYENV -eq 1 ]]; then function pyenv_prompt_info() { local version="$(pyenv version-name)" + if [[ "$ZSH_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_PYENV_NO_SYSTEM" = "true" ]]; then + return + fi local version="$(python3 -V 2>&1 | cut -d' ' -f2)" echo "${ZSH_THEME_PYENV_PREFIX=}system: ${version:gs/%/%%}${ZSH_THEME_PYENV_SUFFIX=}" }