Status Code
What
Displays the last known status code and/or the reason that the last command failed.
Sample Configuration
)}
- json
- yaml
- toml
Options
| Name | Type | Default | Description |
|---|---|---|---|
always_enabled | boolean | false | always show the status |
status_template | string | {{ .Code }} | template used to render an individual status code |
status_separator | string | | | used to separate multiple statuses when $PIPESTATUS is available |
Template (info)
default template
{{ .String }}
Properties
| Name | Type | Description |
|---|---|---|
.Code | number | the last known exit code (command or pipestatus) |
.String | string | the formatted status codes using status_template and status_separator |
.Error | boolean | true 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.
{{ 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:
{{ if eq .Code 0 }}\uf00c{{ else }}\uf071 {{ reason .Code }}{{ end }}
hide stale exit codes
Pressing enter on an empty line does not run a command, so .Code still holds the previous
command's exit code. Use the global .Executed property in a template override to
hide the segment when no command ran:
{{ if .Executed }}{{ .Code }}{{ end }}