From b712bc45dddd946ec26a4bb3adaa417a37f153ae Mon Sep 17 00:00:00 2001 From: nirenjan Date: Fri, 21 Dec 2018 17:08:41 -0800 Subject: [PATCH] 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. --- zsh/prompt.zsh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/zsh/prompt.zsh b/zsh/prompt.zsh index dfb2025..389d656 100644 --- a/zsh/prompt.zsh +++ b/zsh/prompt.zsh @@ -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 @ (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)"