mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2025-03-27 21:37:05 +01:00
Merge 689787e117
into ac1335125c
This commit is contained in:
commit
af05263202
2 changed files with 21 additions and 3 deletions
plugins/virtualenv
|
@ -7,8 +7,16 @@ To use it, add `virtualenv` to the plugins array of your zshrc file:
|
|||
plugins=(... virtualenv)
|
||||
```
|
||||
|
||||
The plugin creates a `virtualenv_prompt_info` function that you can use in your theme, which displays
|
||||
the basename of the current `$VIRTUAL_ENV`. It uses two variables to control how that is shown:
|
||||
The plugin creates a `virtualenv_prompt_info` function that you can use in your
|
||||
theme. It displays the prompt string set in the `$VIRTUAL_ENV_PROMPT`
|
||||
environment variable. The `activate` scripts for most Python virtual environment
|
||||
implementations set this variable to the value provided via the `--prompt`
|
||||
option when creating the virtual environment, or the basename of the environment
|
||||
directory if the option was not provided. For implementations that do not set
|
||||
`$VIRTUAL_ENV_PROMPT`, the plugin will display the basename of the virtual
|
||||
environment directory instead.
|
||||
|
||||
It uses two variables to control how that is shown:
|
||||
|
||||
- `ZSH_THEME_VIRTUALENV_PREFIX`: sets the prefix of the VIRTUAL_ENV. Defaults to `[`.
|
||||
|
||||
|
|
|
@ -1,6 +1,16 @@
|
|||
function virtualenv_prompt_info(){
|
||||
[[ -n ${VIRTUAL_ENV} ]] || return
|
||||
echo "${ZSH_THEME_VIRTUALENV_PREFIX=[}${VIRTUAL_ENV:t:gs/%/%%}${ZSH_THEME_VIRTUALENV_SUFFIX=]}"
|
||||
# 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
|
||||
|
|
Loading…
Add table
Reference in a new issue