From 081d704f3273df6095b712096e3f334b04f52782 Mon Sep 17 00:00:00 2001 From: Olivier Mehani Date: Wed, 20 Nov 2024 06:32:01 +1100 Subject: [PATCH] feat(pyenv): add prompt customization (#12738) Co-authored-by: Carlo Sala --- plugins/pyenv/README.md | 8 ++++++++ plugins/pyenv/pyenv.plugin.zsh | 10 ++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/plugins/pyenv/README.md b/plugins/pyenv/README.md index 95d79cb52..2476bbd95 100644 --- a/plugins/pyenv/README.md +++ b/plugins/pyenv/README.md @@ -26,6 +26,14 @@ eval "$(pyenv init --path)" - `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 b5c9a7bd3..cd2a9e0ac 100644 --- a/plugins/pyenv/pyenv.plugin.zsh +++ b/plugins/pyenv/pyenv.plugin.zsh @@ -88,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