- Add the virtualenv plugin in the
~/.zshrc
file. This is done by modifying the plugins line to include the virtualenv plugin - Make sure the following lines are in the file
~/.oh-my-zsh/plugins/virtualenv/virtualenv.plugin.zsh
# disables prompt mangling in virtual_env/bin/activate
export VIRTUAL_ENV_DISABLE_PROMPT=1
#Disable conda prompt changes
#https://conda.io/docs/user-guide/configuration/use-condarc.html#change-command-prompt-changeps1
#changeps1: False
`conda config --set changeps1 false`
- In the file
~/.oh-my-zsh/themes/agnoster.zsh-theme
locate the function calledprompt_virtualenv()
and modify it to look as follows:
# Display current virtual environment
prompt_virtualenv() {
local env='';
# if "$CONDA_DEFAULT_ENV" variable exists,
# then you are using conda to manage python virtual env
if [[ -n "$CONDA_DEFAULT_ENV" ]]; then
env="$CONDA_DEFAULT_ENV"
elif [[ -n "$VIRTUAL_ENV" ]]; then
env="$VIRTUAL_ENV"
fi
if [[ -n $env ]]; then
color=cyan
prompt_segment $color $PRIMARY_FG
print -Pn " $(basename $env) "
fi
}
This function uses a conditional statement to check the type of virtual environment being used (conda or virtualenv) and grabs the name of the environment from the appropriate shell variable.
You can change the line color=cyan
to whatever you like (do make sure to take a look at oh-my-zsh documentation to see what colours are allowed), and the virtual env name will be displayed in a segment of that colour. (magenta
is my personal favourite :p)
- Save the file, and run
source ~/.zshrc
(or restart the terminal) to see the changes
Adding the conda env name to agnoster worked well for me! However, for removing
(<env name>)
I found that I had to do the following:and then simply add the line