If I understand the question correctly, you want to have your prompt display the entire path of your current directory in blue but with each of the forward slashes ("/") in pink.
Unfortunately, you can't do this in your prompt.
Use the builtin precmd ()
function.
ZSH gives us a precmd
function which is similar to Bash's PROMPT_COMMAND
. These allow a command to be issued before the prompt is displayed.
I also wouldn't recommend a long prompt anyway as it makes usability very difficult when entering commands. Putting the full directory above your prompt is much better from a UI standpoint. The following code accomplishes that.
Simply put the following in your ~/.zprofile
.
precmd () { printf "\n"; pwd | awk -F "/" ' {for (i=1; i<=NF; i++) printf "\033[01;34m"$i"\033[38;5;206m/"; printf"\n" }' }
And here are the results:

The above screenshot is my iTerm window showing that I have traversed deep into my /Applications/Firefox.app
directory with the current directory formatted in blue separated by pink forward slashes.
How it Works...
I've expanded the one line premcmd
function above so that it's multi-line and added in some variables so we can better see what's going on.
precmd() {
printf "\n";
pwd | awk -F "/" '{ blue="\033[01;34m"; \
pink="\033[38;5;206m"; \
for (i=1; i<=NF; i++) \
printf blue $i pink "/"; \
printf "\n"
}'
}
Here's what it all means:
printf "\n"
prints out a new line char. This is for aesthetics.
pwd
returns the working directory name (man pwd
) which is then piped ("|") to the next command, awk
(man awk
).
-F "/"
defines the field separator to the forward slash; awk
's default is a space. I kept my prompt to it's short and succinct setup.
Within the awk "program," delimited by the braces ("{" and "}") we have the following:
- variables
blue
and pink
are set to their ANSI escape codes \033[01;34m
and \033[38;5;206m
respectively.
- We then have a for/do loop that iterates through each of the fields that
awk
has processed. NF
is the total number of fields.
printf blue $i
and printf pink "/"
prints out the directory name in blue and the forward slash in pink