Implement VIRTUAL_ENV_PROMPT and _DISABLE_PROMPT

Fully implements the suppression of virtualenv name display
when `$VIRTUAL_ENV_DISABLE_PROMPT` is defined and truthy.

Implements the xonsh-side "catch" of a custom prompt defined
via the `--prompt` argument to `virtualenv`. In order for this to
work, `activate.xsh` will need to be modified on the virtualenv
side to define `$VIRTUAL_ENV_PROMPT` during activate, if the
environment is created with `--prompt="foo"`.

Partially implements pypa/virtualenv#1299
This commit is contained in:
Brian Skinn 2019-01-29 15:21:08 -05:00
parent b9594fa85d
commit 9224a74bb7

View file

@ -23,13 +23,21 @@ def env_name():
``{env_prefix}`` and ``{env_postfix}`` fields.
"""
env_name = find_env_name()
if not env_name:
# no environment, just return
if (
builtins.__xonsh__.env.get("VIRTUAL_ENV_DISABLE_PROMPT")
or not env_name
):
# env name prompt printing disabled, or no environment; just return
return
pf = builtins.__xonsh__.shell.prompt_formatter
pre = pf._get_field_value("env_prefix")
post = pf._get_field_value("env_postfix")
return pre + env_name + post
venv_prompt = builtins.__xonsh__.env.get("VIRTUAL_ENV_PROMPT")
if venv_prompt is not None:
return venv_prompt
else:
pf = builtins.__xonsh__.shell.prompt_formatter
pre = pf._get_field_value("env_prefix")
post = pf._get_field_value("env_postfix")
return pre + env_name + post
def vte_new_tab_cwd():