Add virtualenv to prompt, if it exists

With my starting to get deeper into Python development, I noticed an
issue with the virtualenv, where the current virtualenv was not set on
activation. I traced this to the fact that PS1 is always reset in the
prompt_header function, therefore, I need to add the virtual environment
details into prompt_header

This change checks if the virtual environment is set, if so, it adds the
current virtual environment to the prompt in magenta color.
master
nirenjan 2018-12-21 17:08:41 -08:00
parent 6f89117689
commit b712bc45dd
1 changed files with 8 additions and 1 deletions

View File

@ -19,12 +19,19 @@ function prompt_header
# Build the prompt prefix
local prefix
# Add the current date in YYYY-MM-DD HH:MM:SS format (yellow color)
prefix='%F{yellow}%D{%F %T}%f'
prefix='%F{yellow}%D{%F %T}%f'
# Add <user>@<hostname> (blue color)
prefix="$prefix %F{blue}%n@%m%f"
# Add current working directory (green color)
# This replaces the smartwd functionality with zsh conditionals
prefix="$prefix [%F{green}%(6~#%-3~/.../%2~#%~)%f]"
# Add the current virtualenv, if present
if [ -n "$VIRTUAL_ENV" ]
then
prefix="$prefix Py(%F{magenta}${VIRTUAL_ENV##*/}%f)"
fi
# Add the status of the last command, but only if it failed
prefix="$prefix %(?..%F{red}!! %? !!%f)"