I found the set default background color code from @user313992's answer:
On xterm-like terminal emulators:
This sets the background to a light green without having to clear the screen:
printf %b '\e]11;#ccffcc\a'
It works. But how to set the default foreground color in Bash shell in a similar manner? Something like:
printf %b '???(default_foreground_color)???'
And, where to find the related information about the \e]11;
code for the background color and the respective ???
code for the foreground color?
See https://invisible-island.net/xterm/ctlseqs/ctlseqs.pdf (page 34):
You already used
11
(\e]11;
) to change the background, now use10
(\e]10;
) to change the foreground, e.g.:will set the foreground to red, while:
will set the background to red and foreground to blue.
As @ubfan1 mentioned in a comment, if you prefer you can use color names instead of #rrggbb color codes in the printf, e.g.