Reputation:
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="%{\033[38;5;75m%}"; \
pink="%{\033[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.
Upvotes: 0
Views: 180
Reputation: 532093
I would use a pre-command hook and simple parameter expansion instead of forking various external programs.
precmd () {
bar='%F{13}|'
prompt="$bar%F{green}%n@%F{cyan}%m$bar%f%T$bar%F{75}"
prompt+=${PWD:gs./.%F{206}/%F{75}}
prompt+="$bar%F{7} "
}
Add this to your .zshrc
file, and prompt
will be reset prior to displaying it, rather than embedding a shell function in the prompt itself.
PWD
is the current working directory. The gs.---.---
expansion modifier replaces each /
with %F{206}/%F{75}
, using zsh
's own color escape sequences rather than using raw ANSI escape sequences.
Upvotes: 0
Reputation: 141698
Do not do: printf something
. Always do printf "%s", something
. The awk errors, because you passed invalid printf
format specifiers %{
and %}
, yet you did not pass any arguments. Do:
printf "%s%s%s/", blue, $i, pink;
I think you can just:
{gsub("/", pink "/" blue)}1
Upvotes: 1