I have a zsh config on MacOS Catalina which works well. No, I would like to get the same but for Debian 10 Buster.
The issue occurs in the using of function for PROMPT that displays pink slashes that separate the PATH current working where directories are in blue.
On MacOS, I do it like this (into my .zshrc) :
# Path with colorized forward slash
slash_color() {
dirs | awk -F "/" '{ blue="%{ 33[38;5;75m%}";
pink="%{ 33[38;5;206m%}";
for (i=1; i<NF; i++)
printf blue $i pink "/";
printf blue $NF pink;
}';
}
# Prompt final
PROMPT=$'%F{13}|%F{green}%n@%F{cyan}%m%F{13}|%f%T%F{13}|$(slash_color)%F{13}|%F{7} '
The result looks like for PROMPT :
Now, on Debian Buster, I have copied the ~/.zshrc from MacOS Catalina.
and when PROMPT is displayed, the PATH of current working directory is not displayed (empty) and I get the following error :
awk: run time error: not enough arguments passed to printf("%{%}~%{%}/")
FILENAME="-" FNR=1 NR=1
I don’t know why I have this error on Debian and not on MacOS. I suspect this is due to a difference on the working of my slash_color()
function but I don’t understand the origin.
It seems that a variable is missing in Debian version for awk
, but I can’t see which one.
2
Answers
Do not do:
printf something
. Always doprintf "%s", something
. The awk errors, because you passed invalidprintf
format specifiers%{
and%}
, yet you did not pass any arguments. Do:I think you can just:
I would use a pre-command hook and simple parameter expansion instead of forking various external programs.
Add this to your
.zshrc
file, andprompt
will be reset prior to displaying it, rather than embedding a shell function in the prompt itself.PWD
is the current working directory. Thegs.---.---
expansion modifier replaces each/
with%F{206}/%F{75}
, usingzsh
‘s own color escape sequences rather than using raw ANSI escape sequences.