feat(pyenv): add prompt customization (#12738)
Co-authored-by: Carlo Sala <carlosalag@protonmail.com>
Diff
1diff --git a/plugins/pyenv/README.md b/plugins/pyenv/README.md
2index 95d79cb52ef3bed8866e799c1716d502d8303844..2476bbd95fbb10326f652596dabd052af151ac83 100644
3--- a/plugins/pyenv/README.md
4+++ b/plugins/pyenv/README.md
5@@ -26,6 +26,14 @@ eval "$(pyenv init --path)"
6 - `ZSH_PYENV_VIRTUALENV`: if set to `false`, the plugin will not load pyenv-virtualenv
7 when it finds it.
8 9+- `ZSH_THEME_PYENV_NO_SYSTEM`: if set to `true`, the plugin will not show the system or
10+ default Python version when it finds it.
11+- `ZSH_THEME_PYENV_PREFIX`: the prefix to display before the Python version in
12+ the prompt.
13+
14+- `ZSH_THEME_PYENV_SUFFIX`: the prefix to display after the Python version in
15+ the prompt.
16+
17 ## Functions
1819 - `pyenv_prompt_info`: displays the Python version in use by pyenv; or the global Python
20diff --git a/plugins/pyenv/pyenv.plugin.zsh b/plugins/pyenv/pyenv.plugin.zsh
21index b5c9a7bd3294897f45997e92c1b535439b85c77d..cd2a9e0ac0b3a240f3b3a54501eb380e80f81d26 100644
22--- a/plugins/pyenv/pyenv.plugin.zsh
23+++ b/plugins/pyenv/pyenv.plugin.zsh
24@@ -88,13 +88,19 @@ if [[ $FOUND_PYENV -eq 1 ]]; then
2526 function pyenv_prompt_info() {
27 local version="$(pyenv version-name)"
28- echo "${version:gs/%/%%}"
29+ if [[ "$ZSH_THEME_PYENV_NO_SYSTEM" == "true" ]] && [[ "${version}" == "system" ]]; then
30+ return
31+ fi
32+ echo "${ZSH_THEME_PYENV_PREFIX=}${version:gs/%/%%}${ZSH_THEME_PYENV_SUFFIX=}"
33 }
34 else
35 # Fall back to system python
36 function pyenv_prompt_info() {
37+ if [[ "$ZSH_THEME_PYENV_NO_SYSTEM" == "true" ]]; then
38+ return
39+ fi
40 local version="$(python3 -V 2>&1 | cut -d' ' -f2)"
41- echo "system: ${version:gs/%/%%}"
42+ echo "${ZSH_THEME_PYENV_PREFIX=}system: ${version:gs/%/%%}${ZSH_THEME_PYENV_SUFFIX=}"
43 }
44 fi
45