diff --git a/.vscode/launch.json b/.vscode/launch.json index 5ec22047..87f43fff 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -40,7 +40,7 @@ "print", "transient", "--shell=pwsh", - "--error=1" + "--status=1" ] }, { diff --git a/src/cli/print.go b/src/cli/print.go index 2a13959d..4f589a63 100644 --- a/src/cli/print.go +++ b/src/cli/print.go @@ -12,7 +12,8 @@ import ( var ( pwd string pswd string - exitCode int + status int + pipestatus string timing float64 stackCount int terminalWidth int @@ -22,7 +23,7 @@ var ( command string shellVersion string plain bool - noExitCode bool + noStatus bool ) // printCmd represents the prompt command @@ -51,7 +52,8 @@ var printCmd = &cobra.Command{ Config: config, PWD: pwd, PSWD: pswd, - ErrorCode: exitCode, + ErrorCode: status, + PipeStatus: pipestatus, ExecutionTime: timing, StackCount: stackCount, TerminalWidth: terminalWidth, @@ -61,7 +63,7 @@ var printCmd = &cobra.Command{ Plain: plain, Primary: args[0] == "primary", Cleared: cleared, - NoExitCode: noExitCode, + NoExitCode: noStatus, } eng := engine.New(flags) @@ -95,7 +97,9 @@ func init() { //nolint:gochecknoinits printCmd.Flags().StringVar(&pswd, "pswd", "", "current working directory (according to pwsh)") printCmd.Flags().StringVar(&shellName, "shell", "", "the shell to print for") printCmd.Flags().StringVar(&shellVersion, "shell-version", "", "the shell version") - printCmd.Flags().IntVarP(&exitCode, "error", "e", 0, "last exit code") + printCmd.Flags().IntVar(&status, "status", 0, "last known status code") + printCmd.Flags().BoolVar(&noStatus, "no-status", false, "no valid status code (cancelled or no command yet)") + printCmd.Flags().StringVar(&pipestatus, "pipestatus", "", "the PIPESTATUS array") printCmd.Flags().Float64Var(&timing, "execution-time", 0, "timing of the last command") printCmd.Flags().IntVarP(&stackCount, "stack-count", "s", 0, "number of locations on the stack") printCmd.Flags().IntVarP(&terminalWidth, "terminal-width", "w", 0, "width of the terminal") @@ -103,6 +107,8 @@ func init() { //nolint:gochecknoinits printCmd.Flags().BoolVarP(&plain, "plain", "p", false, "plain text output (no ANSI)") printCmd.Flags().BoolVar(&cleared, "cleared", false, "do we have a clear terminal or not") printCmd.Flags().BoolVar(&eval, "eval", false, "output the prompt for eval") - printCmd.Flags().BoolVar(&noExitCode, "no-exit-code", false, "no valid exit code (cancelled or no command yet)") + // Deprecated flags + printCmd.Flags().IntVarP(&status, "error", "e", 0, "last exit code") + printCmd.Flags().BoolVar(&noStatus, "no-exit-code", false, "no valid exit code (cancelled or no command yet)") RootCmd.AddCommand(printCmd) } diff --git a/src/engine/migrate.go b/src/engine/migrate.go index 11e1e94c..eaf9d194 100644 --- a/src/engine/migrate.go +++ b/src/engine/migrate.go @@ -135,7 +135,7 @@ func (segment *Segment) migrationOne(env platform.Environment) { segment.migrateColorOverride("version_mismatch_color", "{{ if .Mismatch }}%s{{ end }}", background) } case EXIT: - template := segment.Properties.GetString(segmentTemplate, segment.writer.Template()) + template := segment.Properties.GetString(segmentTemplate, "{{ if gt .Code 0 }}\uf00d {{ .Meaning }}{{ else }}\uf42e{{ end }}") if strings.Contains(template, ".Text") { template = strings.ReplaceAll(template, ".Text", ".Meaning") segment.Properties[segmentTemplate] = template diff --git a/src/engine/migrate_test.go b/src/engine/migrate_test.go index 76512077..0b7c2beb 100644 --- a/src/engine/migrate_test.go +++ b/src/engine/migrate_test.go @@ -9,6 +9,7 @@ import ( "github.com/jandedobbeleer/oh-my-posh/src/segments" "github.com/stretchr/testify/assert" + mock2 "github.com/stretchr/testify/mock" ) const ( @@ -326,7 +327,9 @@ func TestSegmentTemplateMigration(t *testing.T) { Type: tc.Type, Properties: tc.Props, } - segment.migrationOne(&mock.MockedEnvironment{}) + env := &mock.MockedEnvironment{} + env.On("Debug", mock2.Anything).Return(nil) + segment.migrationOne(env) assert.Equal(t, tc.Expected, segment.Properties[segmentTemplate], tc.Case) } } diff --git a/src/engine/prompt.go b/src/engine/prompt.go index 7cea9515..f419f3e1 100644 --- a/src/engine/prompt.go +++ b/src/engine/prompt.go @@ -21,7 +21,7 @@ const ( func (e *Engine) Primary() string { if e.Config.ShellIntegration { - exitCode := e.Env.ErrorCode() + exitCode, _ := e.Env.StatusCodes() e.write(e.Writer.CommandFinished(exitCode, e.Env.Flags().NoExitCode)) e.write(e.Writer.PromptStart()) } @@ -150,7 +150,7 @@ func (e *Engine) ExtraPrompt(promptType ExtraPromptType) string { } if promptType == Transient && e.Config.ShellIntegration { - exitCode := e.Env.ErrorCode() + exitCode, _ := e.Env.StatusCodes() e.write(e.Writer.CommandFinished(exitCode, e.Env.Flags().NoExitCode)) e.write(e.Writer.PromptStart()) } diff --git a/src/engine/segment.go b/src/engine/segment.go index 04f7cf2e..7bb003c6 100644 --- a/src/engine/segment.go +++ b/src/engine/segment.go @@ -217,6 +217,8 @@ const ( SITECORE SegmentType = "sitecore" // SPOTIFY writes the SPOTIFY status for Mac SPOTIFY SegmentType = "spotify" + // STATUS writes the last know command status + STATUS SegmentType = "status" // STRAVA is a sports activity tracker STRAVA SegmentType = "strava" // Subversion segment @@ -275,7 +277,7 @@ var Segments = map[SegmentType]func() SegmentWriter{ DOTNET: func() SegmentWriter { return &segments.Dotnet{} }, EXECUTIONTIME: func() SegmentWriter { return &segments.Executiontime{} }, ELIXIR: func() SegmentWriter { return &segments.Elixir{} }, - EXIT: func() SegmentWriter { return &segments.Exit{} }, + EXIT: func() SegmentWriter { return &segments.Status{} }, FLUTTER: func() SegmentWriter { return &segments.Flutter{} }, FOSSIL: func() SegmentWriter { return &segments.Fossil{} }, GCP: func() SegmentWriter { return &segments.Gcp{} }, @@ -314,6 +316,7 @@ var Segments = map[SegmentType]func() SegmentWriter{ SHELL: func() SegmentWriter { return &segments.Shell{} }, SITECORE: func() SegmentWriter { return &segments.Sitecore{} }, SPOTIFY: func() SegmentWriter { return &segments.Spotify{} }, + STATUS: func() SegmentWriter { return &segments.Status{} }, STRAVA: func() SegmentWriter { return &segments.Strava{} }, SVN: func() SegmentWriter { return &segments.Svn{} }, SWIFT: func() SegmentWriter { return &segments.Swift{} }, diff --git a/src/mock/environment.go b/src/mock/environment.go index dea6207e..bd0ee3a2 100644 --- a/src/mock/environment.go +++ b/src/mock/environment.go @@ -105,9 +105,9 @@ func (env *MockedEnvironment) RunShellCommand(shell, command string) string { return args.String(0) } -func (env *MockedEnvironment) ErrorCode() int { +func (env *MockedEnvironment) StatusCodes() (int, string) { args := env.Called() - return args.Int(0) + return args.Int(0), args.String(1) } func (env *MockedEnvironment) ExecutionTime() float64 { diff --git a/src/platform/shell.go b/src/platform/shell.go index 7eec498f..599ade2d 100644 --- a/src/platform/shell.go +++ b/src/platform/shell.go @@ -52,6 +52,7 @@ var ( type Flags struct { ErrorCode int + PipeStatus string Config string Shell string ShellVersion string @@ -215,7 +216,7 @@ type Environment interface { GOOS() string Shell() string Platform() string - ErrorCode() int + StatusCodes() (int, string) PathSeparator() string HasFiles(pattern string) bool HasFilesInDir(dir, pattern string) bool @@ -611,9 +612,9 @@ func (env *Shell) HasCommand(command string) bool { return false } -func (env *Shell) ErrorCode() int { +func (env *Shell) StatusCodes() (int, string) { defer env.Trace(time.Now()) - return env.CmdFlags.ErrorCode + return env.CmdFlags.ErrorCode, env.CmdFlags.PipeStatus } func (env *Shell) ExecutionTime() float64 { @@ -798,7 +799,7 @@ func (env *Shell) TemplateCache() *TemplateCache { tmplCache.Root = env.Root() tmplCache.Shell = env.Shell() tmplCache.ShellVersion = env.CmdFlags.ShellVersion - tmplCache.Code = env.ErrorCode() + tmplCache.Code, _ = env.StatusCodes() tmplCache.WSL = env.IsWsl() tmplCache.Segments = make(map[string]interface{}) tmplCache.PromptCount = env.CmdFlags.PromptCount diff --git a/src/segments/exit_test.go b/src/segments/exit_test.go deleted file mode 100644 index 81c0b215..00000000 --- a/src/segments/exit_test.go +++ /dev/null @@ -1,92 +0,0 @@ -package segments - -import ( - "testing" - - "github.com/jandedobbeleer/oh-my-posh/src/mock" - "github.com/jandedobbeleer/oh-my-posh/src/platform" - "github.com/jandedobbeleer/oh-my-posh/src/properties" - - "github.com/stretchr/testify/assert" -) - -func TestExitWriterEnabled(t *testing.T) { - cases := []struct { - ExitCode int - Expected bool - }{ - {ExitCode: 102, Expected: true}, - {ExitCode: 0, Expected: false}, - {ExitCode: -1, Expected: true}, - } - - for _, tc := range cases { - env := new(mock.MockedEnvironment) - env.On("ErrorCode").Return(tc.ExitCode) - e := &Exit{ - env: env, - props: properties.Map{}, - } - assert.Equal(t, tc.Expected, e.Enabled()) - } -} - -func TestGetMeaningFromExitCode(t *testing.T) { - errorMap := make(map[int]string) - errorMap[1] = "ERROR" - errorMap[2] = "USAGE" - errorMap[126] = "NOPERM" - errorMap[127] = "NOTFOUND" - errorMap[129] = "SIGHUP" - errorMap[130] = "SIGINT" - errorMap[131] = "SIGQUIT" - errorMap[132] = "SIGILL" - errorMap[133] = "SIGTRAP" - errorMap[134] = "SIGIOT" - errorMap[135] = "SIGBUS" - errorMap[136] = "SIGFPE" - errorMap[137] = "SIGKILL" - errorMap[138] = "SIGUSR1" - errorMap[139] = "SIGSEGV" - errorMap[140] = "SIGUSR2" - errorMap[141] = "SIGPIPE" - errorMap[142] = "SIGALRM" - errorMap[143] = "SIGTERM" - errorMap[144] = "SIGSTKFLT" - errorMap[145] = "SIGCHLD" - errorMap[146] = "SIGCONT" - errorMap[147] = "SIGSTOP" - errorMap[148] = "SIGTSTP" - errorMap[149] = "SIGTTIN" - errorMap[150] = "SIGTTOU" - errorMap[151] = "151" - errorMap[7000] = "7000" - for exitcode, want := range errorMap { - e := &Exit{} - assert.Equal(t, want, e.getMeaningFromExitCode(exitcode)) - } -} - -func TestExitWriterTemplateString(t *testing.T) { - cases := []struct { - Case string - ExitCode int - Expected string - Template string - }{ - {Case: "Only code", ExitCode: 129, Expected: "129", Template: "{{ .Code }}"}, - } - - for _, tc := range cases { - env := new(mock.MockedEnvironment) - env.On("ErrorCode").Return(tc.ExitCode) - env.On("TemplateCache").Return(&platform.TemplateCache{ - Code: tc.ExitCode, - }) - e := &Exit{ - env: env, - props: properties.Map{}, - } - assert.Equal(t, tc.Expected, renderTemplate(env, tc.Template, e), tc.Case) - } -} diff --git a/src/segments/status.go b/src/segments/status.go new file mode 100644 index 00000000..14bbf83d --- /dev/null +++ b/src/segments/status.go @@ -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() +} diff --git a/src/segments/status_test.go b/src/segments/status_test.go new file mode 100644 index 00000000..11b2d870 --- /dev/null +++ b/src/segments/status_test.go @@ -0,0 +1,106 @@ +package segments + +import ( + "testing" + + "github.com/jandedobbeleer/oh-my-posh/src/mock" + "github.com/jandedobbeleer/oh-my-posh/src/platform" + "github.com/jandedobbeleer/oh-my-posh/src/properties" + + "github.com/stretchr/testify/assert" + mock2 "github.com/stretchr/testify/mock" +) + +func TestStatusWriterEnabled(t *testing.T) { + cases := []struct { + Status int + Expected bool + Template string + }{ + {Status: 102, Expected: true}, + {Status: 0, Expected: false}, + {Status: -1, Expected: true}, + {Status: 144, Expected: true, Template: "{{}}"}, + } + + for _, tc := range cases { + env := new(mock.MockedEnvironment) + env.On("StatusCodes").Return(tc.Status, "") + env.On("TemplateCache").Return(&platform.TemplateCache{ + Code: 133, + }) + env.On("Error", mock2.Anything).Return(nil) + + props := properties.Map{} + if len(tc.Template) > 0 { + props[StatusTemplate] = tc.Template + } + + s := &Status{} + s.Init(props, env) + + assert.Equal(t, tc.Expected, s.Enabled()) + } +} + +func TestFormatStatus(t *testing.T) { + cases := []struct { + Case string + Status int + PipeStatus string + Template string + Separator string + Expected string + }{ + { + Case: "No PipeStatus", + Status: 12, + Template: "{{ .Code }}", + Separator: "|", + Expected: "12", + }, + { + Case: "Defaults", + PipeStatus: "0 127 0", + Template: "{{ .Code }}", + Separator: "|", + Expected: "0|127|0", + }, + { + Case: "No integer", + PipeStatus: "0 err 0", + Template: "{{ .Code }}", + Separator: "|", + Expected: "0|err|0", + }, + { + Case: "Incorrect template", + PipeStatus: "1 0 0", + Template: "{{}}", + Separator: "|", + Expected: "1|0|0", + }, + { + Case: "Advanced template", + PipeStatus: "1 0 0", + Template: "{{ if eq .Code 0 }}\uf058{{ else }}\uf071{{ end }}", + Separator: "|", + Expected: "\uf071|\uf058|\uf058", + }, + } + + for _, tc := range cases { + env := new(mock.MockedEnvironment) + env.On("TemplateCache").Return(&platform.TemplateCache{ + Code: 133, + }) + env.On("Error", mock2.Anything).Return(nil) + props := properties.Map{ + StatusTemplate: tc.Template, + StatusSeparator: tc.Separator, + } + s := &Status{} + s.Init(props, env) + assert.Equal(t, tc.Expected, s.formatStatus(tc.Status, tc.PipeStatus), tc.Case) + } +} diff --git a/src/shell/scripts/omp.bash b/src/shell/scripts/omp.bash index ca41f34f..33c2007b 100644 --- a/src/shell/scripts/omp.bash +++ b/src/shell/scripts/omp.bash @@ -11,7 +11,7 @@ PS0='${omp_start_time:0:$((omp_start_time="$(_omp_start_timer)",0))}$(_omp_ftcs_ PS2="$(::OMP:: print secondary --config="$POSH_THEME" --shell=bash --shell-version="$BASH_VERSION")" function _set_posh_cursor_position() { - # not supported in Midnight Commander + # not supported in Midnight Commander # see https://github.com/JanDeDobbeleer/oh-my-posh/issues/3415 if [[ "::CURSOR::" != "true" ]] || [[ -v MC_SID ]]; then return @@ -46,19 +46,26 @@ function set_poshcontext() { } function _omp_hook() { - local ret=$? + local ret=$? pipeStatus=(${PIPESTATUS[@]}) + if [[ "${#BP_PIPESTATUS[@]}" -gt "${#pipeStatus[@]}" ]]; then + pipeStatus=(${BP_PIPESTATUS[@]}) + fi + local omp_stack_count=$((${#DIRSTACK[@]} - 1)) local omp_elapsed=-1 local no_exit_code="true" + if [[ -n "$omp_start_time" ]]; then local omp_now=$(::OMP:: get millis --shell=bash) omp_elapsed=$((omp_now-omp_start_time)) omp_start_time="" no_exit_code="false" fi + set_poshcontext _set_posh_cursor_position - PS1="$(::OMP:: print primary --config="$POSH_THEME" --shell=bash --shell-version="$BASH_VERSION" --error="$ret" --execution-time="$omp_elapsed" --stack-count="$omp_stack_count" --no-exit-code="$no_exit_code" | tr -d '\0')" + + PS1="$(::OMP:: print primary --config="$POSH_THEME" --shell=bash --shell-version="$BASH_VERSION" --status="$ret" --pipestatus="${pipeStatus[*]}" --execution-time="$omp_elapsed" --stack-count="$omp_stack_count" --no-status="$no_exit_code" | tr -d '\0')" return $ret } diff --git a/src/shell/scripts/omp.elv b/src/shell/scripts/omp.elv index 81ad4c75..82899a4e 100644 --- a/src/shell/scripts/omp.elv +++ b/src/shell/scripts/omp.elv @@ -23,12 +23,12 @@ set edit:after-command = [ $@edit:after-command $posh-after-command-hook~ ] set edit:prompt = { var cmd-duration = (printf "%.0f" (* $edit:command-duration 1000)) - ::OMP:: print primary --config=$E:POSH_THEME --shell=elvish --execution-time=$cmd-duration --error=$error-code --pwd=$pwd --shell-version=$E:POSH_SHELL_VERSION + ::OMP:: print primary --config=$E:POSH_THEME --shell=elvish --execution-time=$cmd-duration --status=$error-code --pwd=$pwd --shell-version=$E:POSH_SHELL_VERSION } set edit:rprompt = { var cmd-duration = (printf "%.0f" (* $edit:command-duration 1000)) - ::OMP:: print right --config=$E:POSH_THEME --shell=elvish --execution-time=$cmd-duration --error=$error-code --pwd=$pwd --shell-version=$E:POSH_SHELL_VERSION + ::OMP:: print right --config=$E:POSH_THEME --shell=elvish --execution-time=$cmd-duration --status=$error-code --pwd=$pwd --shell-version=$E:POSH_SHELL_VERSION } if (eq '::UPGRADE::' 'true') { diff --git a/src/shell/scripts/omp.fish b/src/shell/scripts/omp.fish index 22e74335..925e304c 100644 --- a/src/shell/scripts/omp.fish +++ b/src/shell/scripts/omp.fish @@ -14,15 +14,17 @@ end function fish_prompt set --local omp_status_cache_temp $status + set --local omp_pipestatus_cache_temp $pipestatus # clear from cursor to end of screen as # commandline --function repaint does not do this # see https://github.com/fish-shell/fish-shell/issues/8418 printf \e\[0J if test "$omp_transient" = "1" - ::OMP:: print transient --config $POSH_THEME --shell fish --error $omp_status_cache --execution-time $omp_duration --stack-count $omp_stack_count --shell-version $FISH_VERSION --no-exit-code=$omp_no_exit_code + ::OMP:: print transient --config $POSH_THEME --shell fish --status $omp_status_cache --pipestatus="$omp_pipestatus_cache" --execution-time $omp_duration --stack-count $omp_stack_count --shell-version $FISH_VERSION --no-status=$omp_no_exit_code return end set --global omp_status_cache $omp_status_cache_temp + set --global omp_pipestatus_cache $omp_pipestatus_cache_temp set --global omp_stack_count (count $dirstack) set --global omp_duration "$CMD_DURATION$cmd_duration" set --global omp_no_exit_code false @@ -49,7 +51,7 @@ function fish_prompt if test "$last_command" = "clear" set omp_cleared true end - ::OMP:: print primary --config $POSH_THEME --shell fish --error $omp_status_cache --execution-time $omp_duration --stack-count $omp_stack_count --shell-version $FISH_VERSION --cleared=$omp_cleared --no-exit-code=$omp_no_exit_code + ::OMP:: print primary --config $POSH_THEME --shell fish --status $omp_status_cache --pipestatus="$omp_pipestatus_cache" --execution-time $omp_duration --stack-count $omp_stack_count --shell-version $FISH_VERSION --cleared=$omp_cleared --no-status=$omp_no_exit_code end function fish_right_prompt @@ -66,7 +68,7 @@ function fish_right_prompt return end set has_omp_tooltip false - ::OMP:: print right --config $POSH_THEME --shell fish --error $omp_status_cache --execution-time $omp_duration --stack-count $omp_stack_count --shell-version $FISH_VERSION + ::OMP:: print right --config $POSH_THEME --shell fish --status $omp_status_cache --execution-time $omp_duration --stack-count $omp_stack_count --shell-version $FISH_VERSION end function postexec_omp --on-event fish_postexec @@ -104,7 +106,7 @@ function _render_tooltip if not test -n "$omp_tooltip_command" return end - set omp_tooltip_prompt (::OMP:: print tooltip --config $POSH_THEME --shell fish --error $omp_status_cache --shell-version $FISH_VERSION --command $omp_tooltip_command) + set omp_tooltip_prompt (::OMP:: print tooltip --config $POSH_THEME --shell fish --status $omp_status_cache --shell-version $FISH_VERSION --command $omp_tooltip_command) if not test -n "$omp_tooltip_prompt" if test "$has_omp_tooltip" = "true" commandline --function repaint diff --git a/src/shell/scripts/omp.lua b/src/shell/scripts/omp.lua index c98e1140..5ea46270 100644 --- a/src/shell/scripts/omp.lua +++ b/src/shell/scripts/omp.lua @@ -142,14 +142,14 @@ end local function error_level_option() if os.geterrorlevel ~= nil and settings.get("cmd.get_errorlevel") then - return "--error "..os.geterrorlevel() + return "--status "..os.geterrorlevel() end return "" end local function no_exit_code_option() if no_exit_code then - return "--no-exit-code" + return "--no-status" end return "" end diff --git a/src/shell/scripts/omp.nu b/src/shell/scripts/omp.nu index 484cf149..0c2972af 100644 --- a/src/shell/scripts/omp.nu +++ b/src/shell/scripts/omp.nu @@ -23,7 +23,7 @@ export-env { let clear = (history | last 1 | get 0.command) == "clear" let width = ((term size).columns | into string) - ^::OMP:: print primary $"--config=($env.POSH_THEME)" --shell=nu $"--shell-version=($env.POSH_SHELL_VERSION)" $"--execution-time=($cmd_duration)" $"--error=($env.LAST_EXIT_CODE)" $"--terminal-width=($width)" $"--cleared=($clear)" + ^::OMP:: print primary $"--config=($env.POSH_THEME)" --shell=nu $"--shell-version=($env.POSH_SHELL_VERSION)" $"--execution-time=($cmd_duration)" $"--status=($env.LAST_EXIT_CODE)" $"--terminal-width=($width)" $"--cleared=($clear)" } } diff --git a/src/shell/scripts/omp.ps1 b/src/shell/scripts/omp.ps1 index 54ecd29a..7852ce20 100644 --- a/src/shell/scripts/omp.ps1 +++ b/src/shell/scripts/omp.ps1 @@ -132,7 +132,7 @@ New-Module -Name "oh-my-posh-core" -ScriptBlock { } $position = $host.UI.RawUI.CursorPosition $cleanPSWD = Get-CleanPSWD - $standardOut = @(Start-Utf8Process $script:OMPExecutable @("print", "tooltip", "--error=$script:ErrorCode", "--shell=$script:ShellName", "--pswd=$cleanPSWD", "--config=$env:POSH_THEME", "--command=$command", "--shell-version=$script:PSVersion")) + $standardOut = @(Start-Utf8Process $script:OMPExecutable @("print", "tooltip", "--status=$script:ErrorCode", "--shell=$script:ShellName", "--pswd=$cleanPSWD", "--config=$env:POSH_THEME", "--command=$command", "--shell-version=$script:PSVersion")) # ignore an empty tooltip if ($standardOut -eq '') { return @@ -420,7 +420,7 @@ Example: $env:POSH_CURSOR_LINE = $Host.UI.RawUI.CursorPosition.Y + 1 $env:POSH_CURSOR_COLUMN = $Host.UI.RawUI.CursorPosition.X + 1 - $standardOut = @(Start-Utf8Process $script:OMPExecutable @("print", $script:PromptType, "--error=$script:ErrorCode", "--pswd=$cleanPSWD", "--execution-time=$script:ExecutionTime", "--stack-count=$stackCount", "--config=$env:POSH_THEME", "--shell-version=$script:PSVersion", "--terminal-width=$terminalWidth", "--shell=$script:ShellName", "--no-exit-code=$script:NoExitCode")) + $standardOut = @(Start-Utf8Process $script:OMPExecutable @("print", $script:PromptType, "--status=$script:ErrorCode", "--pswd=$cleanPSWD", "--execution-time=$script:ExecutionTime", "--stack-count=$stackCount", "--config=$env:POSH_THEME", "--shell-version=$script:PSVersion", "--terminal-width=$terminalWidth", "--shell=$script:ShellName", "--no-status=$script:NoExitCode")) # make sure PSReadLine knows if we have a multiline prompt Set-PSReadLineOption -ExtraPromptLineCount (($standardOut | Measure-Object -Line).Lines - 1) # the output can be multiline, joining these ensures proper rendering by adding line breaks with `n diff --git a/src/shell/scripts/omp.py b/src/shell/scripts/omp.py index a817cc56..c44178de 100644 --- a/src/shell/scripts/omp.py +++ b/src/shell/scripts/omp.py @@ -13,11 +13,11 @@ def get_command_context(): def posh_primary(): status, duration = get_command_context() - return $(::OMP:: print primary --config=@($POSH_THEME) --shell=xonsh --error=@(status) --execution-time=@(duration) --shell-version=@($POSH_SHELL_VERSION)) + return $(::OMP:: print primary --config=@($POSH_THEME) --shell=xonsh --status=@(status) --execution-time=@(duration) --shell-version=@($POSH_SHELL_VERSION)) def posh_right(): status, duration = get_command_context() - return $(::OMP:: print right --config=@($POSH_THEME) --shell=xonsh --error=@(status) --execution-time=@(duration) --shell-version=@($POSH_SHELL_VERSION)) + return $(::OMP:: print right --config=@($POSH_THEME) --shell=xonsh --status=@(status) --execution-time=@(duration) --shell-version=@($POSH_SHELL_VERSION)) $PROMPT = posh_primary diff --git a/src/shell/scripts/omp.tcsh b/src/shell/scripts/omp.tcsh index cbf4d30b..d860db02 100644 --- a/src/shell/scripts/omp.tcsh +++ b/src/shell/scripts/omp.tcsh @@ -4,7 +4,7 @@ setenv POSH_SHELL_VERSION ""; set USER_PRECMD = "`alias precmd`"; set USER_POSTCMD = "`alias postcmd`"; -set POSH_PRECMD = 'set POSH_CMD_STATUS = $status;set POSH_PATH = ::OMP::;set POSH_END_TIME = `$POSH_PATH get millis`;set POSH_DURATION = 0;if ( $POSH_START_TIME != -1 ) @ POSH_DURATION = $POSH_END_TIME - $POSH_START_TIME;set prompt = "`$POSH_PATH print primary --shell=tcsh --config=$POSH_THEME --error=$POSH_CMD_STATUS --execution-time=$POSH_DURATION`";set POSH_START_TIME = -1'; +set POSH_PRECMD = 'set POSH_CMD_STATUS = $status;set POSH_PATH = ::OMP::;set POSH_END_TIME = `$POSH_PATH get millis`;set POSH_DURATION = 0;if ( $POSH_START_TIME != -1 ) @ POSH_DURATION = $POSH_END_TIME - $POSH_START_TIME;set prompt = "`$POSH_PATH print primary --shell=tcsh --config=$POSH_THEME --status=$POSH_CMD_STATUS --execution-time=$POSH_DURATION`";set POSH_START_TIME = -1'; set POSH_POSTCMD = 'set POSH_START_TIME = `::OMP:: get millis`'; alias precmd "$POSH_PRECMD;$USER_PRECMD"; alias postcmd "$POSH_POSTCMD;$USER_POSTCMD"; diff --git a/src/shell/scripts/omp.zsh b/src/shell/scripts/omp.zsh index 3f2654f4..9f43f9a7 100644 --- a/src/shell/scripts/omp.zsh +++ b/src/shell/scripts/omp.zsh @@ -43,7 +43,7 @@ function prompt_ohmyposh_preexec() { } function prompt_ohmyposh_precmd() { - omp_last_error=$? + omp_last_error=$? pipeStatus=(${pipestatus[@]}) omp_stack_count=${#dirstack[@]} omp_elapsed=-1 no_exit_code="true" @@ -56,7 +56,7 @@ function prompt_ohmyposh_precmd() { export POSH_PROMPT_COUNT=$count set_poshcontext _set_posh_cursor_position - eval "$(::OMP:: print primary --config="$POSH_THEME" --error="$omp_last_error" --execution-time="$omp_elapsed" --stack-count="$omp_stack_count" --eval --shell=zsh --shell-version="$ZSH_VERSION" --no-exit-code="$no_exit_code")" + eval "$(::OMP:: print primary --config="$POSH_THEME" --status="$omp_last_error" --pipestatus="${pipeStatus[*]}" --execution-time="$omp_elapsed" --stack-count="$omp_stack_count" --eval --shell=zsh --shell-version="$ZSH_VERSION" --no-status="$no_exit_code")" unset omp_start_time } @@ -96,7 +96,7 @@ function _posh-tooltip() { if [[ -z "$tip" ]]; then return fi - local tooltip=$(::OMP:: print tooltip --config="$POSH_THEME" --shell=zsh --error="$omp_last_error" --command="$tip" --shell-version="$ZSH_VERSION") + local tooltip=$(::OMP:: print tooltip --config="$POSH_THEME" --shell=zsh --status="$omp_last_error" --command="$tip" --shell-version="$ZSH_VERSION") # ignore an empty tooltip if [[ -z "$tooltip" ]]; then return @@ -114,7 +114,7 @@ function _posh-zle-line-init() { local -i ret=$? (( $+zle_bracketed_paste )) && print -r -n - $zle_bracketed_paste[2] - eval "$(::OMP:: print transient --error="$omp_last_error" --execution-time="$omp_elapsed" --stack-count="$omp_stack_count" --config="$POSH_THEME" --eval --shell=zsh --shell-version="$ZSH_VERSION" --no-exit-code="$no_exit_code")" + eval "$(::OMP:: print transient --status="$omp_last_error" --execution-time="$omp_elapsed" --stack-count="$omp_stack_count" --config="$POSH_THEME" --eval --shell=zsh --shell-version="$ZSH_VERSION" --no-status="$no_exit_code")" zle .reset-prompt # If we received EOT, we exit the shell diff --git a/src/template/func_map.go b/src/template/func_map.go index 44d02c59..de3dd1c2 100644 --- a/src/template/func_map.go +++ b/src/template/func_map.go @@ -16,6 +16,7 @@ func funcMap() template.FuncMap { "replaceP": replaceP, "gt": gt, "lt": lt, + "reason": GetReasonFromStatus, } for key, fun := range sprig.TxtFuncMap() { if _, ok := funcMap[key]; !ok { diff --git a/src/segments/exit.go b/src/template/reason.go similarity index 63% rename from src/segments/exit.go rename to src/template/reason.go index e5c06e41..348d6c5a 100644 --- a/src/segments/exit.go +++ b/src/template/reason.go @@ -1,37 +1,8 @@ -package segments +package template -import ( - "strconv" +import "strconv" - "github.com/jandedobbeleer/oh-my-posh/src/platform" - "github.com/jandedobbeleer/oh-my-posh/src/properties" -) - -type Exit struct { - props properties.Properties - env platform.Environment - - Meaning string -} - -func (e *Exit) Template() string { - return " {{ if gt .Code 0 }}\uf00d {{ .Meaning }}{{ else }}\uf42e{{ end }} " -} - -func (e *Exit) Enabled() bool { - e.Meaning = e.getMeaningFromExitCode(e.env.ErrorCode()) - if e.props.GetBool(properties.AlwaysEnabled, false) { - return true - } - return e.env.ErrorCode() != 0 -} - -func (e *Exit) Init(props properties.Properties, env platform.Environment) { - e.props = props - e.env = env -} - -func (e *Exit) getMeaningFromExitCode(code int) string { //nolint: gocyclo +func GetReasonFromStatus(code int) string { //nolint: gocyclo switch code { case 1: return "ERROR" diff --git a/src/template/text.go b/src/template/text.go index ff1c26f1..a4bf9b64 100644 --- a/src/template/text.go +++ b/src/template/text.go @@ -208,6 +208,8 @@ func (f *fields) init(data interface{}) { for key := range m { (*f)[key] = true } + case reflect.Ptr: + f.init(reflect.ValueOf(data).Elem().Interface()) } } diff --git a/src/test/jandedobbeleer-palette.omp.json b/src/test/jandedobbeleer-palette.omp.json index 1987b8f7..85f4f471 100644 --- a/src/test/jandedobbeleer-palette.omp.json +++ b/src/test/jandedobbeleer-palette.omp.json @@ -161,7 +161,7 @@ "style": "diamond", "template": "\ue0b0 \ue23a ", "trailing_diamond": "\ue0b4", - "type": "exit" + "type": "status" } ], "type": "prompt" diff --git a/src/test/jandedobbeleer.omp.json b/src/test/jandedobbeleer.omp.json index aeafcc01..ea40d4ac 100644 --- a/src/test/jandedobbeleer.omp.json +++ b/src/test/jandedobbeleer.omp.json @@ -161,7 +161,7 @@ "style": "diamond", "template": "\ue0b0 \ue23a ", "trailing_diamond": "\ue0b4", - "type": "exit" + "type": "status" } ], "type": "prompt" diff --git a/themes/1_shell.omp.json b/themes/1_shell.omp.json index 961c118b..ceeba8c0 100644 --- a/themes/1_shell.omp.json +++ b/themes/1_shell.omp.json @@ -109,7 +109,7 @@ }, "style": "plain", "template": " \ue286 ", - "type": "exit" + "type": "status" } ], "type": "prompt" diff --git a/themes/agnoster.minimal.omp.json b/themes/agnoster.minimal.omp.json index 15c954e7..8badc525 100644 --- a/themes/agnoster.minimal.omp.json +++ b/themes/agnoster.minimal.omp.json @@ -7,8 +7,8 @@ { "foreground": "#ffffff", "style": "plain", - "template": "{{ .Meaning }}\u274c ", - "type": "exit" + "template": "{{ reason .Code }}\u274c ", + "type": "status" }, { "foreground": "#ff0000", diff --git a/themes/agnoster.omp.json b/themes/agnoster.omp.json index 80a825f7..4d88e6c0 100644 --- a/themes/agnoster.omp.json +++ b/themes/agnoster.omp.json @@ -55,8 +55,8 @@ "foreground": "#ffffff", "powerline_symbol": "\ue0b0", "style": "powerline", - "template": " {{ .Meaning }} ", - "type": "exit" + "template": " {{ reason .Code }} ", + "type": "status" } ], "type": "prompt" diff --git a/themes/atomic.omp.json b/themes/atomic.omp.json index 88c6ef9b..a0dc7348 100644 --- a/themes/atomic.omp.json +++ b/themes/atomic.omp.json @@ -266,7 +266,7 @@ }, "style": "plain", "template": "\ue285\ueb9e ", - "type": "exit" + "type": "status" } ], "type": "prompt" diff --git a/themes/atomicBit.omp.json b/themes/atomicBit.omp.json index 9cedb550..2a06465c 100644 --- a/themes/atomicBit.omp.json +++ b/themes/atomicBit.omp.json @@ -183,7 +183,7 @@ }, "style": "plain", "template": "\ue285\ueb9e ", - "type": "exit" + "type": "status" } ], "type": "prompt" diff --git a/themes/avit.omp.json b/themes/avit.omp.json index 386aaf8e..e9c2c02b 100644 --- a/themes/avit.omp.json +++ b/themes/avit.omp.json @@ -28,8 +28,8 @@ { "foreground": "#C94A16", "style": "plain", - "template": "x{{ .Meaning }} ", - "type": "exit" + "template": "x{{ reason .Code }} ", + "type": "status" } ], "type": "prompt" diff --git a/themes/blue-owl.omp.json b/themes/blue-owl.omp.json index 5e0d04d0..f6fa3c83 100644 --- a/themes/blue-owl.omp.json +++ b/themes/blue-owl.omp.json @@ -69,8 +69,8 @@ "foreground": "#ffffff", "powerline_symbol": "\ue0b0", "style": "powerline", - "template": " \uf12a {{ .Meaning }} ", - "type": "exit" + "template": " \uf12a {{ reason .Code }} ", + "type": "status" } ], "type": "prompt" @@ -113,7 +113,7 @@ }, "style": "plain", "template": "\u276f ", - "type": "exit" + "type": "status" } ], "type": "prompt" diff --git a/themes/blueish.omp.json b/themes/blueish.omp.json index a9297ba5..7ce11199 100644 --- a/themes/blueish.omp.json +++ b/themes/blueish.omp.json @@ -97,7 +97,7 @@ "style": "diamond", "template": " \uea6c ", "trailing_diamond": "\ue0b0", - "type": "exit" + "type": "status" } ], "type": "prompt" diff --git a/themes/cinnamon.omp.json b/themes/cinnamon.omp.json index 2adb84e5..9f0afeee 100644 --- a/themes/cinnamon.omp.json +++ b/themes/cinnamon.omp.json @@ -58,7 +58,7 @@ "style": "diamond", "template": " \ueb05 ", "trailing_diamond": "\ue0b4", - "type": "exit" + "type": "status" } ], "type": "prompt" diff --git a/themes/clean-detailed.omp.json b/themes/clean-detailed.omp.json index 8475c5df..a6fc2f07 100644 --- a/themes/clean-detailed.omp.json +++ b/themes/clean-detailed.omp.json @@ -120,7 +120,7 @@ }, "style": "plain", "template": "\u2570\u2500 ", - "type": "exit" + "type": "status" } ], "type": "prompt" diff --git a/themes/cloud-context.omp.json b/themes/cloud-context.omp.json index 7ca8de45..3b7d1a55 100644 --- a/themes/cloud-context.omp.json +++ b/themes/cloud-context.omp.json @@ -105,7 +105,7 @@ "style": "powerline", "powerline_symbol": "\ue0b4", "template": "{{ if eq .Code 0 }} \uf004 {{ end }}", - "type": "exit" + "type": "status" }, { "background": "p:error-background", @@ -113,8 +113,8 @@ "leading_diamond": " \ue0c5", "trailing_diamond": "\ue0c4", "style": "diamond", - "template": "{{ if ne .Code 0 }} \uf00d {{ .Code }}{{ if (ne .Meaning (toString .Code)) }} - {{ .Meaning }}{{else}}{{ end }} {{ end }}", - "type": "exit" + "template": "{{ if ne .Code 0 }} \uf00d {{ .Code }}{{ if (ne (reason .Code) (toString .Code)) }} - {{ reason .Code }}{{else}}{{ end }} {{ end }}", + "type": "status" } ], "type": "prompt" diff --git a/themes/cloud-native-azure.omp.json b/themes/cloud-native-azure.omp.json index 2fb6a2fa..32bdb992 100644 --- a/themes/cloud-native-azure.omp.json +++ b/themes/cloud-native-azure.omp.json @@ -54,9 +54,9 @@ "always_enabled": true }, "style": "diamond", - "template": " \ue23a {{ if gt .Code 0 }}\uf00d {{ .Meaning }}{{ else }}\uf42e{{ end }} ", + "template": " \ue23a {{ if gt .Code 0 }}\uf00d {{ reason .Code }}{{ else }}\uf42e{{ end }} ", "trailing_diamond": "\ue0b4", - "type": "exit" + "type": "status" } ], "type": "prompt" diff --git a/themes/craver.omp.json b/themes/craver.omp.json index 7649a02b..491af607 100644 --- a/themes/craver.omp.json +++ b/themes/craver.omp.json @@ -85,7 +85,7 @@ "powerline_symbol": "\ue0b4", "style": "powerline", "template": " \ueb05 ", - "type": "exit" + "type": "status" } ], "type": "prompt" diff --git a/themes/darkblood.omp.json b/themes/darkblood.omp.json index 182aceb5..fb2a6536 100644 --- a/themes/darkblood.omp.json +++ b/themes/darkblood.omp.json @@ -25,8 +25,8 @@ { "foreground": "#ffffff", "style": "plain", - "template": "<#CB4B16>[x{{ .Meaning }}<#CB4B16>]", - "type": "exit" + "template": "<#CB4B16>[x{{ reason .Code }}<#CB4B16>]", + "type": "status" } ], "type": "prompt" diff --git a/themes/emodipt-extend.omp.json b/themes/emodipt-extend.omp.json index fb65a43c..208505aa 100644 --- a/themes/emodipt-extend.omp.json +++ b/themes/emodipt-extend.omp.json @@ -53,13 +53,13 @@ "alignment": "right", "segments": [ { - "type": "exit", + "type": "status", "style": "plain", "foreground": "#b8ff75", "foreground_templates": [ "{{ if gt .Code 0 }}#E06C75{{ end }}" ], - "template": " x{{ .Meaning }}" + "template": " x{{ reason .Code }}" }, { "foreground": "#b8ff75", diff --git a/themes/emodipt.omp.json b/themes/emodipt.omp.json index 394cc4c3..325dcc7e 100644 --- a/themes/emodipt.omp.json +++ b/themes/emodipt.omp.json @@ -41,8 +41,8 @@ { "foreground": "#C94A16", "style": "plain", - "template": "x{{ .Meaning }} ", - "type": "exit" + "template": "x{{ reason .Code }} ", + "type": "status" }, { "foreground": "#E06C75", diff --git a/themes/fish.omp.json b/themes/fish.omp.json index 113880a3..21c106b4 100644 --- a/themes/fish.omp.json +++ b/themes/fish.omp.json @@ -7,8 +7,8 @@ { "foreground": "#ffffff", "style": "plain", - "template": " {{ .Meaning }}", - "type": "exit" + "template": " {{ reason .Code }}", + "type": "status" }, { "foreground": "#100e23", diff --git a/themes/free-ukraine.omp.json b/themes/free-ukraine.omp.json index 4311c8b8..cb65301e 100644 --- a/themes/free-ukraine.omp.json +++ b/themes/free-ukraine.omp.json @@ -93,7 +93,7 @@ "style": "diamond", "template": " {{ if gt .Code 0 }}\uf421 \uf119 {{ else }}\uf469 \u2665 {{ end }}", "trailing_diamond": "\ue0b0", - "type": "exit" + "type": "status" } ], "type": "prompt" diff --git a/themes/froczh.omp.json b/themes/froczh.omp.json index 6765a186..8274ef59 100644 --- a/themes/froczh.omp.json +++ b/themes/froczh.omp.json @@ -90,8 +90,8 @@ "foreground": "#ffffff", "powerline_symbol": "\ue0b0", "style": "powerline", - "template": " \uf12a {{ .Meaning }} ", - "type": "exit" + "template": " \uf12a {{ reason .Code }} ", + "type": "status" } ], "type": "prompt" @@ -138,7 +138,7 @@ }, "style": "plain", "template": "\u276f ", - "type": "exit" + "type": "status" } ], "type": "prompt" @@ -146,4 +146,4 @@ ], "console_title_template": "{{if .Root}} \u26a1 {{end}}{{.Folder | replace \"~\" \"🏚\" }} @ {{.HostName}}", "version": 2 -} \ No newline at end of file +} diff --git a/themes/glowsticks.omp.yaml b/themes/glowsticks.omp.yaml index 8a35e7a1..6c0ae5c4 100644 --- a/themes/glowsticks.omp.yaml +++ b/themes/glowsticks.omp.yaml @@ -64,7 +64,7 @@ blocks: properties: always_enabled: true style: diamond - template: " {{ if gt .Code 0 }} {{ .Meaning }}{{ else }}{{ end }} " + template: " {{ if gt .Code 0 }} {{ reason .Code }}{{ else }}{{ end }} " trailing_diamond:  type: exit type: prompt diff --git a/themes/gmay.omp.json b/themes/gmay.omp.json index 89693a5e..9949648a 100644 --- a/themes/gmay.omp.json +++ b/themes/gmay.omp.json @@ -82,7 +82,7 @@ "style": "diamond", "template": " \ueb05 ", "trailing_diamond": "\ue0b4", - "type": "exit" + "type": "status" } ], "type": "prompt" diff --git a/themes/grandpa-style.omp.json b/themes/grandpa-style.omp.json index 42a07985..93e398d5 100644 --- a/themes/grandpa-style.omp.json +++ b/themes/grandpa-style.omp.json @@ -69,8 +69,8 @@ "always_enabled": true }, "style": "plain", - "template": "{{ if gt .Code 0 }}\ue0b0 \uf12a {{ .Meaning }} \ue0b0{{ else }}\ue0b0{{ end }}", - "type": "exit" + "template": "{{ if gt .Code 0 }}\ue0b0 \uf12a {{ reason .Code }} \ue0b0{{ else }}\ue0b0{{ end }}", + "type": "status" } ], "type": "prompt" @@ -113,7 +113,7 @@ }, "style": "plain", "template": "\u276f ", - "type": "exit" + "type": "status" } ], "type": "prompt" diff --git a/themes/honukai.omp.json b/themes/honukai.omp.json index ec63b360..686d3ea9 100644 --- a/themes/honukai.omp.json +++ b/themes/honukai.omp.json @@ -61,8 +61,8 @@ { "foreground": "#CB4B16", "style": "plain", - "template": " {{ .Meaning }} ", - "type": "exit" + "template": " {{ reason .Code }} ", + "type": "status" }, { "foreground": "#CC4B16", diff --git a/themes/hul10.omp.json b/themes/hul10.omp.json index ed186081..48fec88b 100644 --- a/themes/hul10.omp.json +++ b/themes/hul10.omp.json @@ -119,7 +119,7 @@ }, "style": "plain", "template": "\u276f", - "type": "exit" + "type": "status" } ] } @@ -127,4 +127,4 @@ "console_title_template": "{{if .Root}}[root] {{end}}{{.Shell}} in <{{.Folder}}>", "final_space": true, "version": 2 -} \ No newline at end of file +} diff --git a/themes/if_tea.omp.json b/themes/if_tea.omp.json index b6ba1e89..0260dc33 100644 --- a/themes/if_tea.omp.json +++ b/themes/if_tea.omp.json @@ -156,7 +156,7 @@ }, "style": "plain", "template": " ", - "type": "exit" + "type": "status" } ], "type": "prompt" diff --git a/themes/iterm2.omp.json b/themes/iterm2.omp.json index 047d5635..b6ac65bd 100644 --- a/themes/iterm2.omp.json +++ b/themes/iterm2.omp.json @@ -65,7 +65,7 @@ }, "style": "powerline", "template": " \uea6c ", - "type": "exit" + "type": "status" } ], "type": "prompt" diff --git a/themes/jandedobbeleer.omp.json b/themes/jandedobbeleer.omp.json index 350ebbf4..eeeba264 100644 --- a/themes/jandedobbeleer.omp.json +++ b/themes/jandedobbeleer.omp.json @@ -161,7 +161,7 @@ "style": "diamond", "template": "\ue0b0 \ue23a ", "trailing_diamond": "\ue0b4", - "type": "exit" + "type": "status" } ], "type": "prompt" diff --git a/themes/jblab_2021.omp.json b/themes/jblab_2021.omp.json index bf4365dd..a7ea811a 100644 --- a/themes/jblab_2021.omp.json +++ b/themes/jblab_2021.omp.json @@ -86,9 +86,9 @@ "foreground": "#ffffff", "leading_diamond": "\ue0b0", "style": "diamond", - "template": " \uf12a {{ .Meaning }} ", + "template": " \uf12a {{ reason .Code }} ", "trailing_diamond": "\ue0b0", - "type": "exit" + "type": "status" } ], "type": "prompt" diff --git a/themes/jonnychipz.omp.json b/themes/jonnychipz.omp.json index f9a19963..f65bfc9b 100644 --- a/themes/jonnychipz.omp.json +++ b/themes/jonnychipz.omp.json @@ -40,7 +40,7 @@ "style": "diamond", "template": "\ue0b0\ue23a ", "trailing_diamond": "\ue0b4", - "type": "exit" + "type": "status" } ], "type": "prompt" diff --git a/themes/jv_sitecorian.omp.json b/themes/jv_sitecorian.omp.json index b521abb5..cc5a9153 100644 --- a/themes/jv_sitecorian.omp.json +++ b/themes/jv_sitecorian.omp.json @@ -72,7 +72,7 @@ }, "style": "powerline", "template": " {{ if gt .Code 0 }}\uf421{{ else }}\uf469 \u2665{{ end }} ", - "type": "exit" + "type": "status" } ], "type": "prompt" diff --git a/themes/kali.omp.json b/themes/kali.omp.json index f2911275..c6239370 100644 --- a/themes/kali.omp.json +++ b/themes/kali.omp.json @@ -68,7 +68,7 @@ }, "style": "plain", "template": " {{ if gt .Code 0 }}\u2a2f{{else}}\u2713{{ end }} ", - "type": "exit" + "type": "status" } ], "type": "prompt" diff --git a/themes/kushal.omp.json b/themes/kushal.omp.json index bbe71941..933c3f08 100644 --- a/themes/kushal.omp.json +++ b/themes/kushal.omp.json @@ -123,7 +123,7 @@ }, "style": "diamond", "template": " {{ if gt .Code 0 }}\uf00d{{ else }}\uf00c{{ end }} ", - "type": "exit" + "type": "status" }, { "background": "#575656", @@ -193,7 +193,7 @@ }, "style": "plain", "template": "\u276f ", - "type": "exit" + "type": "status" } ], "type": "prompt" diff --git a/themes/lambdageneration.omp.json b/themes/lambdageneration.omp.json index 03467760..05f53c79 100644 --- a/themes/lambdageneration.omp.json +++ b/themes/lambdageneration.omp.json @@ -77,9 +77,9 @@ "display_exit_code": true }, "style": "diamond", - "template": " {{ if gt .Code 0 }}\uf00d {{ .Meaning }}{{ else }}\uf00c{{ end }} ", + "template": " {{ if gt .Code 0 }}\uf00d {{ reason .Code }}{{ else }}\uf00c{{ end }} ", "trailing_diamond": "\ue0b4", - "type": "exit" + "type": "status" } ], "type": "prompt" diff --git a/themes/larserikfinholt.omp.json b/themes/larserikfinholt.omp.json index 3a55643c..d237c24c 100644 --- a/themes/larserikfinholt.omp.json +++ b/themes/larserikfinholt.omp.json @@ -90,7 +90,7 @@ "style": "diamond", "template": "\ue0b0 \ue23a ", "trailing_diamond": "\ue0b4", - "type": "exit" + "type": "status" } ], "type": "prompt" diff --git a/themes/marcduiker.omp.json b/themes/marcduiker.omp.json index 6b0804f1..fce09447 100644 --- a/themes/marcduiker.omp.json +++ b/themes/marcduiker.omp.json @@ -49,7 +49,7 @@ "style": "diamond", "template": " \uf0e7 ", "trailing_diamond": "\ue0b4", - "type": "exit" + "type": "status" } ], "type": "prompt" diff --git a/themes/markbull.omp.json b/themes/markbull.omp.json index 4ab4773b..54b2707d 100644 --- a/themes/markbull.omp.json +++ b/themes/markbull.omp.json @@ -87,8 +87,8 @@ "foreground": "#fffef9", "powerline_symbol": "\ue0b0", "style": "powerline", - "template": " \uf12a >>{{ .Meaning }} ", - "type": "exit" + "template": " \uf12a >>{{ reason .Code }} ", + "type": "status" } ], "type": "prompt" diff --git a/themes/material.omp.json b/themes/material.omp.json index 022c8545..c29f335f 100644 --- a/themes/material.omp.json +++ b/themes/material.omp.json @@ -33,7 +33,7 @@ "foreground": "#DCB977", "style": "plain", "template": " \uf119", - "type": "exit" + "type": "status" }, { "foreground": "#66F68F", diff --git a/themes/microverse-power.omp.json b/themes/microverse-power.omp.json index e9b74b82..a96162ad 100644 --- a/themes/microverse-power.omp.json +++ b/themes/microverse-power.omp.json @@ -73,7 +73,7 @@ }, "style": "powerline", "template": " \uea6c ", - "type": "exit" + "type": "status" } ], "type": "prompt" diff --git a/themes/mojada.omp.json b/themes/mojada.omp.json index c69c7622..a97305a7 100644 --- a/themes/mojada.omp.json +++ b/themes/mojada.omp.json @@ -94,7 +94,7 @@ }, "style": "plain", "template": " {{ if gt .Code 0 }}\uf52f{{ else }}\uf4a7{{ end }} ", - "type": "exit" + "type": "status" }, { "foreground": "#ffffff", diff --git a/themes/montys.omp.json b/themes/montys.omp.json index 642eeee0..fd11aa23 100644 --- a/themes/montys.omp.json +++ b/themes/montys.omp.json @@ -83,7 +83,7 @@ "style": "diamond", "template": " {{ if gt .Code 0 }}\uf421{{ else }}\uf469{{ end }}", "trailing_diamond": "\ue0b4", - "type": "exit" + "type": "status" } ], "type": "prompt" diff --git a/themes/multiverse-neon.omp.json b/themes/multiverse-neon.omp.json index 0844a741..dfab405c 100644 --- a/themes/multiverse-neon.omp.json +++ b/themes/multiverse-neon.omp.json @@ -42,7 +42,7 @@ "foreground": "#C94A16", "style": "plain", "template": "x ", - "type": "exit" + "type": "status" } ], "type": "prompt" diff --git a/themes/negligible.omp.json b/themes/negligible.omp.json index 1df4ea64..b293e13e 100644 --- a/themes/negligible.omp.json +++ b/themes/negligible.omp.json @@ -100,7 +100,7 @@ }, "style": "powerline", "template": "\u279c ", - "type": "exit" + "type": "status" } ], "type": "prompt" diff --git a/themes/night-owl.omp.json b/themes/night-owl.omp.json index 06a36bbf..2d5a29de 100644 --- a/themes/night-owl.omp.json +++ b/themes/night-owl.omp.json @@ -399,7 +399,7 @@ }, "style": "plain", "template": "\ue285\ue285", - "type": "exit" + "type": "status" } ], "type": "prompt" diff --git a/themes/nordtron.omp.json b/themes/nordtron.omp.json index 7c4e47f3..71ac50de 100644 --- a/themes/nordtron.omp.json +++ b/themes/nordtron.omp.json @@ -42,8 +42,8 @@ { "foreground": "#d8dee9", "style": "plain", - "template": "<#5e81ac>[x{{ .Meaning }}<#5e81ac>]", - "type": "exit" + "template": "<#5e81ac>[x{{ reason .Code }}<#5e81ac>]", + "type": "status" } ], "type": "prompt" diff --git a/themes/nu4a.omp.json b/themes/nu4a.omp.json index 2a4be79e..d7590991 100644 --- a/themes/nu4a.omp.json +++ b/themes/nu4a.omp.json @@ -65,7 +65,7 @@ "style": "diamond", "template": " \ue70f ", "trailing_diamond": "\ue0c0", - "type": "exit" + "type": "status" }, { "background": "#2f2f2f", diff --git a/themes/onehalf.minimal.omp.json b/themes/onehalf.minimal.omp.json index 258357cd..62d3a3e8 100644 --- a/themes/onehalf.minimal.omp.json +++ b/themes/onehalf.minimal.omp.json @@ -59,11 +59,11 @@ }, "style": "plain", "template": "{{ if gt .Code 0 }}({{ .Code }}) {{ else }}({{ .Code }}) {{ end }}> ", - "type": "exit" + "type": "status" } ], "type": "prompt" } ], "version": 2 -} \ No newline at end of file +} diff --git a/themes/paradox.omp.json b/themes/paradox.omp.json index 08e7d66e..62e59b4b 100644 --- a/themes/paradox.omp.json +++ b/themes/paradox.omp.json @@ -55,7 +55,7 @@ "powerline_symbol": "\ue0b0", "style": "powerline", "template": " \ue20f ", - "type": "exit" + "type": "status" } ], "type": "prompt" diff --git a/themes/pararussel.omp.json b/themes/pararussel.omp.json index d62cc707..c81e13eb 100644 --- a/themes/pararussel.omp.json +++ b/themes/pararussel.omp.json @@ -32,7 +32,7 @@ "foreground": "#DCB977", "style": "plain", "template": " \uf119 ", - "type": "exit" + "type": "status" } ], "type": "prompt" diff --git a/themes/peru.omp.json b/themes/peru.omp.json index 8b841c75..499386bd 100644 --- a/themes/peru.omp.json +++ b/themes/peru.omp.json @@ -67,7 +67,7 @@ }, "style": "plain", "template": " {{ if gt .Code 0 }}<#ff0000>\uf00d{{ else }}<#23d18b>\uf42e{{ end }} ", - "type": "exit" + "type": "status" }, { "foreground": "#bab02a", diff --git a/themes/plague.omp.json b/themes/plague.omp.json index e256ee2a..3fc5c39a 100644 --- a/themes/plague.omp.json +++ b/themes/plague.omp.json @@ -79,7 +79,7 @@ }, "style": "plain", "template": "\ue0b0 \ue23a \ue0b4", - "type": "exit" + "type": "status" } ], "type": "prompt" diff --git a/themes/powerlevel10k_classic.omp.json b/themes/powerlevel10k_classic.omp.json index 08baddfc..ad2c3eb9 100644 --- a/themes/powerlevel10k_classic.omp.json +++ b/themes/powerlevel10k_classic.omp.json @@ -83,7 +83,7 @@ }, "style": "plain", "template": "\u276f ", - "type": "exit" + "type": "status" } ], "type": "prompt" diff --git a/themes/powerlevel10k_modern.omp.json b/themes/powerlevel10k_modern.omp.json index 5b8d7a7d..d12186bc 100644 --- a/themes/powerlevel10k_modern.omp.json +++ b/themes/powerlevel10k_modern.omp.json @@ -94,7 +94,7 @@ }, "style": "plain", "template": "\u276f ", - "type": "exit" + "type": "status" } ], "type": "prompt" diff --git a/themes/powerlevel10k_rainbow.omp.json b/themes/powerlevel10k_rainbow.omp.json index 47ade7fd..18d88bb7 100644 --- a/themes/powerlevel10k_rainbow.omp.json +++ b/themes/powerlevel10k_rainbow.omp.json @@ -170,8 +170,8 @@ "always_enabled": true }, "style": "powerline", - "template": " {{ if gt .Code 0 }}{{ .Meaning }}{{ else }}\u2714{{ end }} ", - "type": "exit" + "template": " {{ if gt .Code 0 }}{{ reason .Code }}{{ else }}\u2714{{ end }} ", + "type": "status" }, { "background": "#d3d7cf", diff --git a/themes/powerline.omp.json b/themes/powerline.omp.json index efac8778..4bf9b5a6 100644 --- a/themes/powerline.omp.json +++ b/themes/powerline.omp.json @@ -49,7 +49,7 @@ "powerline_symbol": "\ue0b0", "style": "powerline", "template": " \ue20f ", - "type": "exit" + "type": "status" } ], "type": "prompt" diff --git a/themes/probua.minimal.omp.json b/themes/probua.minimal.omp.json index a862a29a..f700f1db 100644 --- a/themes/probua.minimal.omp.json +++ b/themes/probua.minimal.omp.json @@ -45,7 +45,7 @@ }, "style": "plain", "template": "> ", - "type": "exit" + "type": "status" } ], "type": "prompt" diff --git a/themes/pure.omp.json b/themes/pure.omp.json index 664bc7da..a0468e73 100644 --- a/themes/pure.omp.json +++ b/themes/pure.omp.json @@ -72,7 +72,7 @@ }, "style": "plain", "template": "\u276f ", - "type": "exit" + "type": "status" } ], "type": "prompt" diff --git a/themes/robbyrussell.omp.json b/themes/robbyrussell.omp.json index 1e310aab..3b0ae7f9 100644 --- a/themes/robbyrussell.omp.json +++ b/themes/robbyrussell.omp.json @@ -32,7 +32,7 @@ "foreground": "#BF616A", "style": "plain", "template": " \u2717", - "type": "exit" + "type": "status" } ], "type": "prompt" diff --git a/themes/schema.json b/themes/schema.json index 369552b0..9a0332e7 100644 --- a/themes/schema.json +++ b/themes/schema.json @@ -264,7 +264,6 @@ "docker", "dotnet", "dart", - "exit", "executiontime", "flutter", "fossil", @@ -300,6 +299,7 @@ "session", "sitecore", "spotify", + "status", "shell", "sysinfo", "strava", @@ -777,13 +777,13 @@ "if": { "properties": { "type": { - "const": "exit" + "const": "status" } } }, "then": { - "title": "Exit Segment", - "description": "https://ohmyposh.dev/docs/segments/exit", + "title": "Status Segment", + "description": "https://ohmyposh.dev/docs/segments/status", "properties": { "properties": { "properties": { diff --git a/themes/sim-web.omp.json b/themes/sim-web.omp.json index f5ced86d..cffbca0f 100644 --- a/themes/sim-web.omp.json +++ b/themes/sim-web.omp.json @@ -65,7 +65,7 @@ "type": "prompt", "segments": [ { - "type": "exit", + "type": "status", "style": "diamond", "foreground": "#00c7fc", "properties": { diff --git a/themes/slim.omp.json b/themes/slim.omp.json index bf5192e3..c4fe36b2 100644 --- a/themes/slim.omp.json +++ b/themes/slim.omp.json @@ -170,7 +170,7 @@ }, "style": "plain", "template": " \uea9f {{ if gt .Code 0 }}{{ .Code }}{{ end }} ", - "type": "exit" + "type": "status" } ], "type": "rprompt" diff --git a/themes/slimfat.omp.json b/themes/slimfat.omp.json index bcd76c50..ecd10bbe 100644 --- a/themes/slimfat.omp.json +++ b/themes/slimfat.omp.json @@ -168,7 +168,7 @@ }, "style": "plain", "template": " \uea9f {{ if gt .Code 0 }}{{ .Code }}{{ end }} ", - "type": "exit" + "type": "status" } ], "type": "rprompt" diff --git a/themes/smoothie.omp.json b/themes/smoothie.omp.json index 68584104..7ec6aef2 100644 --- a/themes/smoothie.omp.json +++ b/themes/smoothie.omp.json @@ -52,7 +52,7 @@ "foreground": "#fb0207", "style": "plain", "template": " ××× ", - "type": "exit" + "type": "status" }, { "foreground": "#9966ff", diff --git a/themes/sonicboom_dark.omp.json b/themes/sonicboom_dark.omp.json index ca665b73..dcd0c137 100644 --- a/themes/sonicboom_dark.omp.json +++ b/themes/sonicboom_dark.omp.json @@ -114,7 +114,7 @@ }, "style": "plain", "template": "\uf432 ", - "type": "exit" + "type": "status" } ], "type": "prompt" diff --git a/themes/sonicboom_light.omp.json b/themes/sonicboom_light.omp.json index b5c5d9c1..ab6f749d 100644 --- a/themes/sonicboom_light.omp.json +++ b/themes/sonicboom_light.omp.json @@ -114,7 +114,7 @@ }, "style": "plain", "template": "\uf432 ", - "type": "exit" + "type": "status" } ], "type": "prompt" diff --git a/themes/sorin.omp.json b/themes/sorin.omp.json index be1a4e5a..d2e59d0e 100644 --- a/themes/sorin.omp.json +++ b/themes/sorin.omp.json @@ -7,8 +7,8 @@ { "foreground": "#CB4B16", "style": "plain", - "template": " {{ .Meaning }} ", - "type": "exit" + "template": " {{ reason .Code }} ", + "type": "status" }, { "foreground": "#CECE04", diff --git a/themes/star.omp.json b/themes/star.omp.json index bc7f0ca6..360cf1c2 100644 --- a/themes/star.omp.json +++ b/themes/star.omp.json @@ -41,7 +41,7 @@ "foreground": "#C94A16", "style": "plain", "template": "x ", - "type": "exit" + "type": "status" } ], "type": "prompt" diff --git a/themes/stelbent-compact.minimal.omp.json b/themes/stelbent-compact.minimal.omp.json index 2c73558d..ca5b54c8 100644 --- a/themes/stelbent-compact.minimal.omp.json +++ b/themes/stelbent-compact.minimal.omp.json @@ -68,7 +68,7 @@ "template": " {{ .WorkspaceName }}{{ if .Version }} {{ .Version }}{{ end }} " }, { - "type": "exit", + "type": "status", "background": "#ff8080", "foreground": "#ffffff", "powerline_symbol": "\ue0b0", diff --git a/themes/stelbent.minimal.omp.json b/themes/stelbent.minimal.omp.json index cf16f443..65f2819b 100644 --- a/themes/stelbent.minimal.omp.json +++ b/themes/stelbent.minimal.omp.json @@ -92,7 +92,7 @@ "powerline_symbol": "\ue0b0", "style": "powerline", "template": " error ", - "type": "exit" + "type": "status" } ], "type": "prompt" diff --git a/themes/takuya.omp.json b/themes/takuya.omp.json index c5ecb667..fdeb90b1 100644 --- a/themes/takuya.omp.json +++ b/themes/takuya.omp.json @@ -105,7 +105,7 @@ }, "style": "plain", "template": "\u276f ", - "type": "exit" + "type": "status" } ], "type": "prompt" diff --git a/themes/thecyberden.omp.json b/themes/thecyberden.omp.json index 4028e8cb..d92cbfa3 100644 --- a/themes/thecyberden.omp.json +++ b/themes/thecyberden.omp.json @@ -55,7 +55,7 @@ "style": "diamond", "template": " ", "trailing_diamond": "\ue0b4", - "type": "exit" + "type": "status" } ], "type": "prompt" diff --git a/themes/tiwahu.omp.json b/themes/tiwahu.omp.json index 16a70f49..42913a49 100644 --- a/themes/tiwahu.omp.json +++ b/themes/tiwahu.omp.json @@ -20,7 +20,7 @@ "foreground": "#ff8888", "style": "plain", "template": "{{ if gt .Code 0 }} {{ .Code }} {{ end }}", - "type": "exit" + "type": "status" }, { "background": "#ffcc88", diff --git a/themes/tokyo.omp.json b/themes/tokyo.omp.json index d3378d9e..36d6a91b 100644 --- a/themes/tokyo.omp.json +++ b/themes/tokyo.omp.json @@ -76,7 +76,7 @@ "foreground": "#ffa5d8", "style": "powerline", "template": "[<#ffffff>\uea6c Error, check your command]", - "type": "exit" + "type": "status" } ], "type": "prompt" diff --git a/themes/tokyonight_storm.omp.json b/themes/tokyonight_storm.omp.json index 9262edf1..a8820a72 100644 --- a/themes/tokyonight_storm.omp.json +++ b/themes/tokyonight_storm.omp.json @@ -56,7 +56,7 @@ } }, { - "type": "exit", + "type": "status", "style": "plain", "foreground": "p:terminal-red", "template": " \uf00d" diff --git a/themes/uew.omp.json b/themes/uew.omp.json index 8881f29e..ee214c14 100644 --- a/themes/uew.omp.json +++ b/themes/uew.omp.json @@ -109,7 +109,7 @@ }, "style": "plain", "template": " \u007E ", - "type": "exit" + "type": "status" } ], "type": "prompt" diff --git a/themes/velvet.omp.json b/themes/velvet.omp.json index da62315c..5bac7071 100644 --- a/themes/velvet.omp.json +++ b/themes/velvet.omp.json @@ -74,7 +74,7 @@ "style": "diamond", "template": " \ueb05{{ if gt .Code 0 }} {{.Code}}{{ end }} ", "trailing_diamond": "\ue0b4", - "type": "exit" + "type": "status" } ], "type": "prompt" diff --git a/themes/wholespace.omp.json b/themes/wholespace.omp.json index 9b5836b7..a875d6a0 100644 --- a/themes/wholespace.omp.json +++ b/themes/wholespace.omp.json @@ -121,7 +121,7 @@ }, "style": "plain", "template": " \ueb05 ", - "type": "exit" + "type": "status" } ], "type": "prompt" diff --git a/themes/wopian.omp.json b/themes/wopian.omp.json index a5687f98..54962bb8 100644 --- a/themes/wopian.omp.json +++ b/themes/wopian.omp.json @@ -97,7 +97,7 @@ }, "style": "powerline", "template": "\u279c ", - "type": "exit" + "type": "status" } ], "type": "prompt" diff --git a/themes/xtoys.omp.json b/themes/xtoys.omp.json index c9fa0754..e07ff6e0 100644 --- a/themes/xtoys.omp.json +++ b/themes/xtoys.omp.json @@ -44,7 +44,7 @@ }, "style": "plain", "template": "<#66CDAA>\u276f<#76EEC6>\u276f\u276f ", - "type": "exit" + "type": "status" } ], "type": "prompt" diff --git a/themes/ys.omp.json b/themes/ys.omp.json index 290d47c4..213947c7 100644 --- a/themes/ys.omp.json +++ b/themes/ys.omp.json @@ -64,7 +64,7 @@ "foreground": "red", "style": "plain", "template": " C:{{ if gt .Code 0 }}{{ .Code }}{{ end }} ", - "type": "exit" + "type": "status" } ], "type": "prompt" diff --git a/themes/zash.omp.json b/themes/zash.omp.json index d3cd6ae3..41382ceb 100644 --- a/themes/zash.omp.json +++ b/themes/zash.omp.json @@ -38,7 +38,7 @@ "foreground": "#DCB977", "style": "plain", "template": " \uf119", - "type": "exit" + "type": "status" } ], "type": "prompt" diff --git a/website/docs/configuration/example.mdx b/website/docs/configuration/example.mdx index ce1181c8..e78adae4 100644 --- a/website/docs/configuration/example.mdx +++ b/website/docs/configuration/example.mdx @@ -83,7 +83,7 @@ import Config from '@site/src/components/Config.js'; }, "style": "diamond", "trailing_diamond": "\ue0b4", - "type": "exit" + "type": "status" } ], "type": "prompt" diff --git a/website/docs/segments/exit.mdx b/website/docs/segments/exit.mdx deleted file mode 100644 index aa2127a7..00000000 --- a/website/docs/segments/exit.mdx +++ /dev/null @@ -1,53 +0,0 @@ ---- -id: exit -title: Exit code -sidebar_label: Exit code ---- - -## What - -Displays the last exit code or that the last command failed based on the configuration. - -## Sample Configuration - -import Config from '@site/src/components/Config.js'; - -\uE0B0 \uE23A ", - "properties": { - "always_enabled": true - } -}}/> - -## Properties - -| Name | Type | Description | -| ---------------- | --------- | -------------------------------------------- | -| `always_enabled` | `boolean` | always show the status - defaults to `false` | - -[colors]: /docs/configuration/colors - -## Template ([info][templates]) - -:::note default template - -```template -{{ if gt .Code 0 }}\uf00d {{ .Meaning }}{{ else }}\uf42e{{ end }} -``` - -::: - -### Properties - -| Name | Type | Description | -| ---------- | -------- | --------------------------------------------------------------------------------------- | -| `.Code` | `number` | the last known exit code | -| `.Meaning` | `string` | the textual meaning linked to exit code (if applicable, otherwise identical to `.Code`) | - -[templates]: /docs/configuration/templates diff --git a/website/docs/segments/status.mdx b/website/docs/segments/status.mdx new file mode 100644 index 00000000..2ed335da --- /dev/null +++ b/website/docs/segments/status.mdx @@ -0,0 +1,74 @@ +--- +id: status +title: Status Code +sidebar_label: Status Code +--- + +## 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"; + +\uE0B0 \uE23A ", + properties: { + always_enabled: true, + }, + }} +/> + +## Properties + +| Name | Type | Description | +| ------------------ | --------- | ---------------------------------------------------------------------------------------------------- | +| `always_enabled` | `boolean` | always show the status - defaults to `false` | +| `status_template` | `string` | [template][status-template] used to render an individual status code - defaults to `{{ .Code }}` | +| `status_separator` | `string` | used to separate multiple statuses when `$PIPESTATUS` is available - defaults to | | + +[colors]: /docs/configuration/colors + +## Template ([info][templates]) + +:::note default template + +```template +{{ if .Error }}\uf00d {{ reason .Code }}{{ else }}\uf42e{{ end }} +``` + +::: + +### 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. + +```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 }} +``` + +[templates]: /docs/configuration/templates +[status-template]: #status-template diff --git a/website/sidebars.js b/website/sidebars.js index b93f9863..c268bd96 100644 --- a/website/sidebars.js +++ b/website/sidebars.js @@ -72,7 +72,6 @@ module.exports = { "segments/dotnet", "segments/elixir", "segments/executiontime", - "segments/exit", "segments/flutter", "segments/fossil", "segments/gcp", @@ -111,6 +110,7 @@ module.exports = { "segments/shell", "segments/sitecore", "segments/spotify", + "segments/status", "segments/strava", "segments/svn", "segments/swift",