Below is the way to do it, you can customize it as per your needs
# Helper method to add background and foreground colors prompt_segment () { local bg fg [[ -n $1 ]] && bg="%K{$1}" || bg="%k" [[ -n $2 ]] && fg="%F{$2}" || fg="%f" if [[ $CURRENT_BG != 'NONE' && $1 != $CURRENT_BG ]] then echo -n " %{$bg%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR%{$fg%} " else echo -n "%{$bg%}%{$fg%} " fi CURRENT_BG=$1 [[ -n $3 ]] && echo -n $3 } prompt_virtualenv () { # Check if we are in a virtual environment # if we are then VIRTUAL_ENV variable will be set local virtualenv_path="$VIRTUAL_ENV" if [[ -n $virtualenv_path && -n $VIRTUAL_ENV_DISABLE_PROMPT ]] then # We are in virtual env so show just the project name prompt_segment blue black "(`basename $virtualenv_path`)" fi } prompt_directory() { # Show the current directory prompt_segment red blue $PWD } build_my_zsh_prompt() { # Call all the prompt functions to build the actual prompt prompt_virtualenv prompt_directory prompt_segment black white "" } # Assign the PROMPT variable with the function, so bash call it everytime # Single quotes are important here, else you will get a fixed PROMPT # Without single quotes, the function will be called once and evaluated value # will be assigned PROMPT='$(build_my_zsh_prompt)'
PROMPT variable is used by zsh shell to determine what needs to be displayed as the prompt. When we set PROMPT=$(build_my_zsh_prompt), we are asking shell to call our function build_my_zsh_prompt.
This function in turn (ideally) should call different function which create individual parts of prompt. Now let's look at prompt_directory
prompt_segment black red $PWD"
The prompt_segment is a helper function to echo some text with background and the foreground color
First parameter black is the background and second parameter red is the foreground color in this case. Next we show what text needs to be given for this prompt.
All of this needs to be added to your ~/.zshrc file at the very end