跳转到主内容

状态码

非官方测试版翻译

本页面由 PageTurner AI 翻译(测试版)。未经项目官方认可。 发现错误? 报告问题 →

功能

显示最后已知的状态码和/或上一条命令失败的原因。

示例配置

{
"type": "status",
"style": "diamond",
"foreground": "#ffffff",
"background": "#00897b",
"background_templates": [
"{{ if .Error }}#e91e63{{ end }}"
],
"trailing_diamond": "",
"template": "<#193549></>  ",
"options": {
"always_enabled": true
}
}

选项

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

模板 (信息)

默认模板
 {{ .String }}

属性

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 时,请通过 if eq .Code 0 检查是否成功退出。.Error 属性 在全局上下文中使用,不一定表示当前验证的代码是非零值。

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

若需要获取退出码的原因而非数值本身,可使用 reason 函数:

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