From 9f3afd0cfb7e24e4693761761a03fc6a0e122df1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jovier=20A=2E=20Jim=C3=A9nez?= Date: Mon, 19 Feb 2024 21:18:56 -0800 Subject: [PATCH 1/6] allow users to configure prompt add-on --- bin/pyenv-sh-activate | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/bin/pyenv-sh-activate b/bin/pyenv-sh-activate index d6b0d35a..70072b92 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 < Date: Mon, 19 Feb 2024 21:19:08 -0800 Subject: [PATCH 2/6] update tests --- test/activate.bats | 25 +++++++++++++++++++++++++ test/conda-activate.bats | 29 +++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/test/activate.bats b/test/activate.bats index 9c1fc675..4a3455ab 100644 --- a/test/activate.bats +++ b/test/activate.bats @@ -44,6 +44,31 @@ EOS unstub pyenv-sh-deactivate } +@test "activate virtualenv from current version with custom prompt" { + export PYENV_VIRTUALENV_INIT=1 + + stub pyenv-version-name "echo venv" + stub pyenv-virtualenv-prefix "venv : echo \"${PYENV_ROOT}/versions/venv\"" + stub pyenv-prefix "venv : echo \"${PYENV_ROOT}/versions/venv\"" + stub pyenv-sh-deactivate "--force --quiet : echo deactivated" + + PYENV_SHELL="bash" PYENV_VERSION="venv" PYENV_VIRTUALENV_PROMPT='venv:{venv}' run pyenv-sh-activate + + assert_success + assert_output < Date: Mon, 19 Feb 2024 21:30:57 -0800 Subject: [PATCH 3/6] update README with example --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 66829808..dbbaf06b 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}`. ## Version History From 119c4db68c32cfe2559af2d5f0746b703a8ac118 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jovier=20A=2E=20Jim=C3=A9nez?= Date: Sat, 14 Sep 2024 16:23:01 -0700 Subject: [PATCH 4/6] update test setup to unset PYENV_VIRTUALENV_PROMPT --- test/activate.bats | 2 ++ test/conda-activate.bats | 1 + test/hooks.bats | 1 + 3 files changed, 4 insertions(+) diff --git a/test/activate.bats b/test/activate.bats index 4a3455ab..8fc951c1 100644 --- a/test/activate.bats +++ b/test/activate.bats @@ -15,6 +15,7 @@ setup() { unset PYENV_VIRTUALENV_DISABLE_PROMPT unset PYENV_VIRTUAL_ENV_DISABLE_PROMPT unset VIRTUAL_ENV_DISABLE_PROMPT + unset PYENV_VIRTUALENV_PROMPT unset _OLD_VIRTUAL_PS1 stub pyenv-hooks "activate : echo" } @@ -46,6 +47,7 @@ EOS @test "activate virtualenv from current version with custom prompt" { export PYENV_VIRTUALENV_INIT=1 + export PYENV_VIRTUALENV_PROMPT='venv:{venv}' stub pyenv-version-name "echo venv" stub pyenv-virtualenv-prefix "venv : echo \"${PYENV_ROOT}/versions/venv\"" diff --git a/test/conda-activate.bats b/test/conda-activate.bats index 1d76fb00..51721c96 100644 --- a/test/conda-activate.bats +++ b/test/conda-activate.bats @@ -16,6 +16,7 @@ setup() { unset PYENV_VIRTUALENV_DISABLE_PROMPT unset PYENV_VIRTUAL_ENV_DISABLE_PROMPT unset VIRTUAL_ENV_DISABLE_PROMPT + unset PYENV_VIRTUALENV_PROMPT unset _OLD_VIRTUAL_PS1 stub pyenv-hooks "activate : echo" } diff --git a/test/hooks.bats b/test/hooks.bats index 3f7bfdfd..9173cf22 100644 --- a/test/hooks.bats +++ b/test/hooks.bats @@ -6,6 +6,7 @@ setup() { export PYENV_ROOT="${TMP}/pyenv" export HOOK_PATH="${TMP}/i has hooks" mkdir -p "$HOOK_PATH" + unset PYENV_VIRTUALENV_PROMPT } @test "pyenv-virtualenv hooks" { From 6c523f4ce3275d8b7f16de9b53933d2c9f529da3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jovier=20A=2E=20Jim=C3=A9nez?= Date: Sat, 14 Sep 2024 16:24:29 -0700 Subject: [PATCH 5/6] add example of custom prompt string --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index dbbaf06b..cdacd780 100644 --- a/README.md +++ b/README.md @@ -243,7 +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}`. +* `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 From e83e7496fa613b10a545892fd4b3713a8238c99c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jovier=20A=2E=20Jim=C3=A9nez?= Date: Sat, 14 Sep 2024 16:26:24 -0700 Subject: [PATCH 6/6] remove redundant environment variable declaration --- test/activate.bats | 1 - 1 file changed, 1 deletion(-) diff --git a/test/activate.bats b/test/activate.bats index 8fc951c1..a3aadb66 100644 --- a/test/activate.bats +++ b/test/activate.bats @@ -47,7 +47,6 @@ EOS @test "activate virtualenv from current version with custom prompt" { export PYENV_VIRTUALENV_INIT=1 - export PYENV_VIRTUALENV_PROMPT='venv:{venv}' stub pyenv-version-name "echo venv" stub pyenv-virtualenv-prefix "venv : echo \"${PYENV_ROOT}/versions/venv\""