From d4c9655e26a10e03c664410a6653cf5073bf3bcb Mon Sep 17 00:00:00 2001 From: Jovier Jimenez <51138002+jimenezj8@users.noreply.github.com> Date: Sun, 15 Sep 2024 02:40:44 -0400 Subject: [PATCH] Add prompt customization (#476) --- README.md | 1 + bin/pyenv-sh-activate | 7 ++++++- test/activate.bats | 26 ++++++++++++++++++++++++++ test/conda-activate.bats | 30 ++++++++++++++++++++++++++++++ test/hooks.bats | 1 + 5 files changed, 64 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d533888..01c18d0 100644 --- a/README.md +++ b/README.md @@ -243,6 +243,7 @@ You can set certain environment variables to control pyenv-virtualenv. * `PIP_VERSION`, if set and `venv` is preferred over `virtualenv`, install the specified version of pip. * `PYENV_VIRTUALENV_VERBOSE_ACTIVATE`, if set, shows some verbose outputs on activation and deactivation +* `PYENV_VIRTUALENV_PROMPT`, if set, allows users to customize how `pyenv-virtualenv` modifies their shell prompt. The default prompt ("(venv)") is overwritten with any user-specified text. Specify the location of the virtual environment name with the string `{venv}`. For example, the default prompt string would be `({venv})`. ## Version History diff --git a/bin/pyenv-sh-activate b/bin/pyenv-sh-activate index 38091ee..5c53b50 100755 --- a/bin/pyenv-sh-activate +++ b/bin/pyenv-sh-activate @@ -262,9 +262,14 @@ EOS fi ;; * ) + if [ -z "${PYENV_VIRTUALENV_PROMPT}" ]; then + PYENV_VIRTUALENV_PROMPT="(${venv})" + else + PYENV_VIRTUALENV_PROMPT="${PYENV_VIRTUALENV_PROMPT/\{venv\}/${venv}}" + fi cat <