Full scaffolding workflow for creating a new Oh My Posh segment. Invoke when asked to add a new segment: generates the Go source, registers the type, creates documentation, updates the sidebar and JSON schema.
Goal
Inputs
type and docs filename (e.g., new)New)New){{.Text}})Contract
markdown skill (.github/skills/markdown/SKILL.md).Implementation steps
src/segments/<id>.gopackage segments
import (
"github.com/jandedobbeleer/oh-my-posh/src/segments/options"
"github.com/jandedobbeleer/oh-my-posh/src/runtime"
)
type {{goType}} struct {
Base
// computed fields used in template
Text string
}
// properties
const (
{{#each properties}}
// {{this.title}}: {{this.description}}
{{ pascalCase this.key }} options.Property = "{{this.key}}"
{{/each}})
func (s *{{goType}}) Enabled() bool {
// set up data for the template, using defaults from properties
{{#if (propExists properties "text")}}
s.Text = s.props.GetString({{ pascalCase "text" }}, {{ defaultFor "text" }})
{{else}}
s.Text = s.props.GetString({{ pascalCase (firstKey properties) }}, "")
{{/if}}
return true
}
func (s *{{goType}}) Template() string {
return {{ printf "%q" template }}
}
src/config/segment_types.goinit() there is gob.Register(&segments.{{goType}}{}) exactly
once.{{ upper id }} SegmentType = "{{id}}" in the alphabetical
block.var Segments = map[SegmentType]func() SegmentWriter{} with key
{{ upper id }} mapping to &segments.{{goType}}{}.segment-docs skill (.github/skills/segment-docs/SKILL.md) for the
Go-to-documentation type mapping and rules for extracting options and template properties.website/docs/segments/{{category}}/{{id}}.mdx.---