ohmyzsh/plugins/virtualenv/virtualenv.plugin.zsh
Heinrich Kruger 480f254157
feat(virtualenv): Use $VIRTUAL_ENV_PROMPT if set
Modify the `virtualenv_prompt_info` function to use the prompt string
specified when creating the virtual environment, instead of just the
basename of the environment. If `VIRTUAL_ENV_PROMPT` is not set, fall
back to just using the basename of `$VIRTUAL_ENV`.
2025-03-11 22:12:20 +00:00

17 lines
662 B
Bash

function virtualenv_prompt_info(){
[[ -n ${VIRTUAL_ENV} ]] || return
# Some versions of virtualenv (e.g the version bundled with 'uv') wrap the
# prompt in parentheses with a trailing space.
local venv_prompt="${(*)VIRTUAL_ENV_PROMPT:/#%(#b)\((*)\) /${match[1]}}"
if [ -z ${venv_prompt} ]; then
# Older versions of virtualenv do not set VIRTUAL_ENV_PROMPT, so fall back
# to the basename of the virtualenv path.
venv_prompt="${VIRTUAL_ENV:t}"
fi
echo "${ZSH_THEME_VIRTUALENV_PREFIX=[}${venv_prompt:gs/%/%%}${ZSH_THEME_VIRTUALENV_SUFFIX=]}"
}
# disables prompt mangling in virtual_env/bin/activate
export VIRTUAL_ENV_DISABLE_PROMPT=1