-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BREAKING CHANGE: exit segment is now called status segment. The exit keyword is now deprecated and will be removed in a future release. Please use the status keyword instead: ```diff "segments": { { - "type": "exit" + "type": "status" } } ``` Additionally, the status segment configuration has changed to support $PIPESTATUS. You can include a status template to customize the rendering of each individual status code (supported in fish, zsh and bash). ```json "segments": { { "type": "status", "properties": { "status_template": "{{ if gt .Code 0 }}\uf071{{ else }}\uf00c{{ end }}", "status_separator": " " } } } ``` In case no $PIPESTATUS is available, the status segment will fall back to the exit code of the last command using the status template for rendering. The `{{ .Meaning }}` property has been marked as deprecated and can be replaced with `{{ reason .Code }}`, allowing it to be reused in cross segment templates. resolves #4070
- Loading branch information
1 parent
2da3722
commit f47da95
Showing
109 changed files
with
470 additions
and
330 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,7 +40,7 @@ | |
"print", | ||
"transient", | ||
"--shell=pwsh", | ||
"--error=1" | ||
"--status=1" | ||
] | ||
}, | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
package segments | ||
|
||
import ( | ||
"strconv" | ||
"strings" | ||
|
||
"github.com/jandedobbeleer/oh-my-posh/src/platform" | ||
"github.com/jandedobbeleer/oh-my-posh/src/properties" | ||
"github.com/jandedobbeleer/oh-my-posh/src/template" | ||
) | ||
|
||
const ( | ||
StatusTemplate properties.Property = "status_template" | ||
StatusSeparator properties.Property = "status_separator" | ||
) | ||
|
||
type Status struct { | ||
props properties.Properties | ||
env platform.Environment | ||
|
||
String string | ||
Error bool | ||
Code int | ||
|
||
template *template.Text | ||
|
||
// Deprecated: Use {{ reason .Code }} instead | ||
Meaning string | ||
} | ||
|
||
func (s *Status) Template() string { | ||
return " {{ .String }} " | ||
} | ||
|
||
func (s *Status) Enabled() bool { | ||
status, pipeStatus := s.env.StatusCodes() | ||
|
||
s.String = s.formatStatus(status, pipeStatus) | ||
// Deprecated: Use {{ reason .Code }} instead | ||
s.Meaning = template.GetReasonFromStatus(status) | ||
|
||
if s.props.GetBool(properties.AlwaysEnabled, false) { | ||
return true | ||
} | ||
|
||
return s.Error | ||
} | ||
|
||
func (s *Status) Init(props properties.Properties, env platform.Environment) { | ||
s.props = props | ||
s.env = env | ||
|
||
statusTemplate := s.props.GetString(StatusTemplate, "{{ .Code }}") | ||
s.template = &template.Text{ | ||
Template: statusTemplate, | ||
Env: s.env, | ||
} | ||
} | ||
|
||
func (s *Status) formatStatus(status int, pipeStatus string) string { | ||
if status != 0 { | ||
s.Error = true | ||
} | ||
|
||
if len(pipeStatus) == 0 { | ||
s.Code = status | ||
s.template.Context = s | ||
if text, err := s.template.Render(); err == nil { | ||
return text | ||
} | ||
return strconv.Itoa(status) | ||
} | ||
|
||
StatusSeparator := s.props.GetString(StatusSeparator, "|") | ||
|
||
var builder strings.Builder | ||
|
||
splitted := strings.Split(pipeStatus, " ") | ||
for i, codeStr := range splitted { | ||
write := func(text string) { | ||
if i > 0 { | ||
builder.WriteString(StatusSeparator) | ||
} | ||
builder.WriteString(text) | ||
} | ||
|
||
code, err := strconv.Atoi(codeStr) | ||
if err != nil { | ||
write(codeStr) | ||
continue | ||
} | ||
|
||
if code != 0 { | ||
s.Error = true | ||
} | ||
|
||
s.Code = code | ||
s.template.Context = s | ||
text, err := s.template.Render() | ||
if err != nil { | ||
write(codeStr) | ||
continue | ||
} | ||
|
||
write(text) | ||
} | ||
|
||
return builder.String() | ||
} |
Oops, something went wrong.