Back to Oh My Posh

Status Code

website/docs/segments/system/status.mdx

29.12.02.4 KB
Original Source

What

Displays the last known status code and/or the reason that the last command failed.

Sample Configuration

import Config from "@site/src/components/Config.js";

<Config data={{ type: "status", style: "diamond", foreground: "#ffffff", background: "#00897b", background_templates: ["{{ if .Error }}#e91e63{{ end }}"], trailing_diamond: "\uE0B4", template: "<#193549>\uE0B0</> \uE23A ", options: { always_enabled: true, }, }} />

Options

NameTypeDefaultDescription
always_enabledbooleanfalsealways show the status
status_templatestring{{ .Code }}template used to render an individual status code
status_separatorstring|used to separate multiple statuses when $PIPESTATUS is available

Template (info)

:::note default template

template
 {{ .String }}

:::

Properties

NameTypeDescription
.Codenumberthe last known exit code (command or pipestatus)
.Stringstringthe formatted status codes using status_template and status_separator
.Errorbooleantrue if one of the commands has an error (validates on command status and pipestatus)

Status Template

When using status_template, use if eq .Code 0 to check for a successful exit code. The .Error property is used on a global context and will not necessarily indicate that the current validated code is a non-zero value.

template
{{ if eq .Code 0 }}\uf00c{{ else }}\uf071{{ end }}

In case you want the reason for the exit code instead of code itself, you can use the reason function:

template
{{ if eq .Code 0 }}\uf00c{{ else }}\uf071 {{ reason .Code }}{{ end }}