Customize ZSH Prompt with Virtual Environment Name and Current Branch

  command-prompt, git, pipenv, python, zsh

I’d like to customize my ZSH-prompt such that it displays the name of my current pipenv virtual environment (or nothing if no virtual environment is activated) followed by the path of the current working directory and the name of the git branch I’m working on (or, once again, nothing if git doesn’t run). Thus, it should look like this:

(name of virtual environment) path (name of current branch) >

I managed to get git branch information with vcs_info by modifying ~/.zshrc as follows:

# Load version control information
autoload -Uz vcs_info
precmd() { vcs_info }

# Format the vcs_info_msg_0_ variable
zstyle ':vcs_info:git:*' formats '(%b)'

# Set up the prompt (with git branch name)
setopt PROMPT_SUBST
PROMPT='%n in ${PWD/#$HOME/~} ${vcs_info_msg_0_} > '

Running source ~/.zshrc makes my prompt appear like this:

path (name of current branch) >

How can I complete my script with the current virtual environment information? Or should I choose another way altogether? Thanks for your help.

Source: Python Questions

LEAVE A COMMENT