Bash and True Color

Solution 1:

ANSI color codes use decimal, not hex.

For example, white is 255;255;255 (that is \e[38;2;255;255;255m) and your "working directory background" dark green is 54;128;45 (that is \e[38;2;54;128;45m).

Also: Don't bother with printf here – you can directly put escape codes such as \x1b or \e in PS1 and bash itself will automatically expand them when displaying the prompt. (In your case, replace the single quotes of PS1 with double quotes.)

pipe_color='255;255;255'
pipe_bg_color='0;0;0'
username_color='0;0;0'
username_bg_color='192;197;206'
at_color='255;255;255'
at_bg_color='65;74;76'
host_color='255;255;255'
host_bg_color='0;91;150'
workingdir_color='255;255;255'
workingdir_bg_color='54;128;45'

pipe="\e[38;2;${pipe_color}m"
pipe_bg="\e[48;2;${pipe_bg_color}m"
username="\e[38;2;${username_color}m"
username_bg="\e[48;2;${username_bg_color}m"
at="\e[38;2;${at_color}m"
at_bg="\e[48;2;${at_bg_color}m"
host="\e[38;2;${host_color}m"
host_bg="\e[48;2;${host_bg_color}m"
workingdir="\e[38;2;${workingdir_color}m"
workingdir_bg="\e[48;2;${workingdir_bg_color}m"
color_reset='\e[0m'

PS1="\[${pipe}${pipe_bg}\]|\[${username}${username_bg}\][\u]\[${pipe}${pipe_bg}\]|\[${at}${at_bg}\]@\[${pipe}${pipe_bg}\]|\[${host}${host_bg}\][\h]\[${pipe}${pipe_bg}\]|\[${color_reset}\] "