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

@ -25,6 +25,13 @@ function prompt_header
# Add current working directory (green color) # Add current working directory (green color)
# This replaces the smartwd functionality with zsh conditionals # This replaces the smartwd functionality with zsh conditionals
prefix="$prefix [%F{green}%(6~#%-3~/.../%2~#%~)%f]" 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 # Add the status of the last command, but only if it failed
prefix="$prefix %(?..%F{red}!! %? !!%f)" prefix="$prefix %(?..%F{red}!! %? !!%f)"