It's much simpler than you're making it out to be. When you run the command ext-color 172 \u
(either as part of setting PS1 or on its own), the shell parses \u
, removing what it thinks is an irrelevant \
, before passing it to ext-color
as $2
. The solution is simple: enclose it in quotes before passing it to ext-color
:
PS1="$(ext-color 172 '\u') in $(ext-color 172 '\w')"
(Note that I've also replaced the backquotes with $( )
, used \w
instead of $(PWD)
, and quoted '\w'
for the same reason as '\u'
.)