Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Misterous bug with %(# ...



On Feb 6, 10:13pm, beber mailing wrote:
}
} host_color=%(#.magenta.green)
} host="%{$fg[$host_color]%}(%m)"
} warninfo="%{$fg[$host_color]%}^^ ROOT ^^ "
[...]
} PS1="$jobs$warninfo$cpath$end $ret%# "
} RPS1="$host $date$end"
} 
} But the color for $host is always black, I don't know why.

You have a problem with understanding the order of evaluation.

%(#.true.false) is evaluated only when a prompt is printed, not at
other times when variables are interpolated.  What's happening is that
the value of $fg[%(#.magenta.green)] is looked up at the time of the
assignment to "host" -- and there is no key "%(#.magenta.green)" in the
$fg associative array, so that returns nothing.  By the time the various
remaining %-expandos in the PS1 and RPS1 strings are interpreted, it's
too late.

What you need is:

host_color="%(#.$fg[magenta].$fg[green])"
host="%{$host_color%}(%m)"
warninfo="%{$host_color%}^^ ROOT ^^ "



Messages sorted by: Reverse Date, Date, Thread, Author