I would like to setup the prompt colors in .bashrc
depending on the colors it is using for foreground and background.
For example, blue prompt if background is light and beige if it is dark.
Is there a way to find out the current settings in a script?
Best Answer
The email back from Thomas Dickey (xterm's maintainer) has this. Note in particular the part about
?
. ThePs = 4
refers toOSC Ps ; Pt ST
whereOSC
(the "Operating System Control" prefix) isESC ]
andST
(the "String Terminator" suffix) is\
(backslash). The4
is one of the possible subcommands to OSC.A bit later in the docs are more OSC subcommands,
Ps = 10
andPs = 11
, and others.Example - this queries the background using
Ps = "11"
(from just above) andPt = "?"
, plugged into theOSC Ps ; Pt ST
. In the echo,\033
is being used for escape, and\\
for the final backslash.Output:
Warning: The returned color does not reflect whether reverse video, like
-rv
, is enabled, and crawling through the ~260 colors available viaOSC 4 ; c ; ? ST
doesn't show any that both follow the background AND change with reverse video. Since many users set a dark background by using justxterm -rv
, this complicates determining whether the background is actually dark or not. Most colors don't adjust to-rv
, either.A script to do the full query and actually capture the reply from xterm: