Oh My Posh supports multiple different color references, being:
Typical hex colors (for example
16 ANSI color names. These include 8 basic ANSI colors and
as well as 8 extended ANSI colors:
transparentkeyword which can be used to create either a transparent foreground override or transparent background color using the segment's foreground property.
foregroundkeyword which can be used to reference the current segment's foreground color.
backgroundkeyword which can be used to reference the current segment's background color.
parentForegroundkeyword which can be used to inherit the previous active segment's foreground color.
parentBackgroundkeyword which can be used to inherit the previous active segment's background color.
accentkeyword which references the OS accent color (Windows only).
Array of string templates to define the color based on the current context. Under the hood this uses go's [text/template][go-text-template] feature extended with [sprig][sprig] and offers a few standard properties to work with. For segments, you can look at the Template Properties section in the documentation. The general template properties are listed here.
The following sample is based on the AWS Segment.
The logic is as follows: when
foreground_templates contains an array, we will check every template line until there's
one that returns a non-empty string. So, when the contents of
.Profile contain the word
default, the first template
#FFA400 and that's the color that will be used. If it contains
jan, it returns
#f1184c. When none of the
templates returns a value, the foreground value
#ffffff is used as a fallback value.
You have the ability to override the foreground and/or background color for text in any property that accepts it.
The syntax is custom but should be rather straight-forward:
<foreground,background>text</>. For example,
<#ffffff,#000000>this is white with black background</> <#FF479C>but this is pink</>.
Anything between the color start
<#FF479C> and end
</> will be colored accordingly.
If you want
prefix to print a colored bracket that isn't the same as the segment's
foreground, you can
do so like this:
If you also wanted to change the background color in the previous command, you would do so like this:
To change only the background color, just omit the first color from the above string:
If your theme defined the Palette, you can use the Palette reference
p:<palette key> in places where the
Standard color is expected.
Palette is a set of named Standard colors. To use a Palette, define a
at the top level of your theme:
Color names (palette keys) can have any string value, so be creative. Color values, on the other hand, should adhere to the Standard color format.
You can now Palette references in any [Segment's][segment]
background_templates properties, and other config properties that expect Standard color value.
Palette reference format is
p:<palette key>. Take a look at the Git segment using Palette references:
Having all of the colors defined in one place allows you to import existing color themes (usually with slight tweaking to adhere to the format), easily change colors of multiple segments at once, and have a more organized theme overall. Be creative!
Using Palette does not interfere with using Standard colors in your theme. You can still use Standard colors everywhere. This can be useful if you want to use a specific color for a single segment element, or in a Color override (Battery segment):
Should you use an invalid Palette reference as a color (for example typo
p:bleu instead of
the Pallete engine will use the Transparent keyword as a fallback value. So if you see your prompt segments
rendered with incorrect colors, and you are using a Palette, be sure to check the correctness of your references.
Palette allows for recursive Palette reference resolution. You can use a Palette reference as a color
value in Palette. This allows you to define named colors, and use references to those colors as Palette values.
p:background will be correctly set to "#CAF0F80" and "#023E8A":