Skip to content

Commit afa625b

Browse files
authored
Hide virtualenv when explicitly disabled by the user (#381)
When `VIRTUAL_ENV_DISABLE_PROMPT` is set (to true) by the user, Pure will not display the virtualenv in the prompt. Setting this manually likely means the user does not care. The user can, at any point, run `export VIRTUAL_ENV_DISABLE_PROMPT=1` and the virtualenv will disappear. Likewise, `unset VIRTUAL_ENV_DISABLE_PROMPT` will bring it back. Closes #350. A big thanks to classner and pfrybar for their efforts and reference implementations, inspiring this one.
1 parent 6c86c74 commit afa625b

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

pure.zsh

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ prompt_pure_preexec() {
8585

8686
# shows the current dir and executed command in the title while a process is active
8787
prompt_pure_set_title 'ignore-escape' "$PWD:t: $2"
88+
89+
# Disallow python virtualenv from updating the prompt, set it to 12 if
90+
# untouched by the user to indicate that Pure modified it. Here we use
91+
# magic number 12, same as in psvar.
92+
export VIRTUAL_ENV_DISABLE_PROMPT=${VIRTUAL_ENV_DISABLE_PROMPT:-12}
8893
}
8994

9095
# string length ignoring ansi escapes
@@ -171,9 +176,15 @@ prompt_pure_precmd() {
171176
# preform async git dirty check and fetch
172177
prompt_pure_async_tasks
173178

174-
# store name of virtualenv in psvar if activated
179+
# Check if we should display the virtual env, we use a sufficiently high
180+
# index of psvar (12) here to avoid collisions with user defined entries.
175181
psvar[12]=
176-
[[ -n $VIRTUAL_ENV ]] && psvar[12]="${VIRTUAL_ENV:t}"
182+
# When VIRTUAL_ENV_DISABLE_PROMPT is empty, it was unset by the user and
183+
# Pure should take back control.
184+
if [[ -n $VIRTUAL_ENV ]] && [[ -z $VIRTUAL_ENV_DISABLE_PROMPT || $VIRTUAL_ENV_DISABLE_PROMPT = 12 ]]; then
185+
psvar[12]="${VIRTUAL_ENV:t}"
186+
export VIRTUAL_ENV_DISABLE_PROMPT=12
187+
fi
177188

178189
# print the preprompt
179190
prompt_pure_preprompt_render "precmd"
@@ -430,9 +441,6 @@ prompt_pure_setup() {
430441
# Prevent percentage showing up if output doesn't end with a newline.
431442
export PROMPT_EOL_MARK=''
432443

433-
# disallow python virtualenvs from updating the prompt
434-
export VIRTUAL_ENV_DISABLE_PROMPT=1
435-
436444
prompt_opts=(subst percent)
437445

438446
# borrowed from promptinit, sets the prompt options in case pure was not

0 commit comments

Comments
 (0)