Segment scaffolding instructions
Goal
- Given user inputs (segment id, Go type name, title, category, description,
properties, template), generate all required code and docs to add a new
segment end-to-end, following repo conventions.
Inputs
- id: kebab/slug used as
type and docs filename (e.g., new)
- goType: PascalCase name for the Go struct (e.g.,
New)
- title: human readable (e.g.,
New)
- category: one of cli|cloud|health|languages|music|scm|system|web
- description: one-line description
- properties: list of { key, type, title, description, default }
- template: default template string (e.g.,
{{.Text}})
Contract
- Idempotent: do not duplicate registrations, constants, map entries, sidebar
links, or schema entries.
- Alphabetical insertions where applicable.
- Compile-ready Go code, formatted.
- Docs lint clean according to the
markdown skill (.agents/skills/markdown/SKILL.md).
Implementation steps
- Create Go writer file:
src/segments/<id>.go
- If file exists, skip creation.
- Use this template; include property consts for each property key.
package 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 }}
}
- Register in
src/config/segment_types.go
- Ensure in
init() there is gob.Register(&segments.{{goType}}{}) exactly
once.
- Add constant:
{{ upper id }} SegmentType = "{{id}}" in the alphabetical
block.
- Add to
var Segments = map[SegmentType]func() SegmentWriter{} with key
{{ upper id }} mapping to &segments.{{goType}}{}.
- Keep lists alphabetically sorted. If not sorted, insert at correct position.
- Documentation file
- Consult the
segment-docs skill (.agents/skills/segment-docs/SKILL.md) for the
Go-to-documentation type mapping and rules for extracting options and template properties.
- Path:
website/docs/segments/{{category}}/{{id}}.mdx.
- If file exists, skip. Else create with this template:
---
id: {{id}}
title: {{title}}
sidebar_label: {{title}}
---
## What
{{description}}
## Sample Configuration
import Config from '@site/src/components/Config.js';
<Config data={{
"type": "{{id}}",
"style": "powerline",
"powerline_symbol": "\uE0B0",
"foreground": "#193549",
"background": "#ffeb3b",
"options": {
{{#each option}}
"{{this.key}}": {{ json this.default }},
{{/each}}
}
}}/>
## Options
| Name | Type | Description | Default |
| ---- | ---- | ----------- | ------- |
{{#each option}}| `{{this.key}}` | `{{this.type}}` | {{this.description}} | `{{ stringify this.default }}` |
{{/each}}
- Sidebar
- Update
website/sidebars.js under the correct category array to include
"segments/{{category}}/{{id}}".
- Insert alphabetically; if already present, do nothing.
- JSON Schema
- File:
themes/schema.json.
- Add
"{{id}}" to #/definitions/segment/properties/type/enum if missing.
- Add an
allOf entry for this segment guarded by
{ properties: { type: { const: "{{id}}" } } } that declares each property
as defined by inputs. Use appropriate JSON Schema types and include title,
description, default.
- Keep the
allOf array in a stable order by type name if feasible; otherwise
append if not present.
Validation
- After changes, run
go build (task: build oh-my-posh). Ensure no compile
errors.
- Check markdown formatting; respect 120-char line length and fenced blocks with
language.
Notes
- Use UTF-32 escapes (e.g., "\uEFF1") for icon defaults in docs and code.
- Keep code minimal. Complex logic should be added by maintainers after
scaffold if needed.
Optional
- Tests
- Create a minimal test file at
src/segments/{{id}}_test.go using the
table-driven style. Include at least a happy-path test that asserts
Enabled() returns true and the template renders expected output with default
options.
1---2name: segment-create3description: 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.4---56# Segment scaffolding instructions78Goal910- Given user inputs (segment id, Go type name, title, category, description,11 properties, template), generate all required code and docs to add a new12 segment end-to-end, following repo conventions.1314Inputs1516- id: kebab/slug used as `type` and docs filename (e.g., `new`)17- goType: PascalCase name for the Go struct (e.g., `New`)18- title: human readable (e.g., `New`)19- category: one of cli|cloud|health|languages|music|scm|system|web20- description: one-line description21- properties: list of { key, type, title, description, default }22- template: default template string (e.g., ` {{.Text}} `)2324Contract2526- Idempotent: do not duplicate registrations, constants, map entries, sidebar27 links, or schema entries.28- Alphabetical insertions where applicable.29- Compile-ready Go code, formatted.30- Docs lint clean according to the `markdown` skill (`.agents/skills/markdown/SKILL.md`).3132Implementation steps33341. Create Go writer file: `src/segments/<id>.go`3536- If file exists, skip creation.37- Use this template; include property consts for each property key.3839```go40package segments4142import (43 "github.com/jandedobbeleer/oh-my-posh/src/segments/options"44 "github.com/jandedobbeleer/oh-my-posh/src/runtime"45)4647type {{goType}} struct {48 Base4950 // computed fields used in template51 Text string52}5354// properties55const (56{{#each properties}}57 // {{this.title}}: {{this.description}}58 {{ pascalCase this.key }} options.Property = "{{this.key}}"59{{/each}})6061func (s *{{goType}}) Enabled() bool {62 // set up data for the template, using defaults from properties63 {{#if (propExists properties "text")}}64 s.Text = s.props.GetString({{ pascalCase "text" }}, {{ defaultFor "text" }})65 {{else}}66 s.Text = s.props.GetString({{ pascalCase (firstKey properties) }}, "")67 {{/if}}68 return true69}7071func (s *{{goType}}) Template() string {72 return {{ printf "%q" template }}73}74```75761. Register in `src/config/segment_types.go`7778- Ensure in `init()` there is `gob.Register(&segments.{{goType}}{})` exactly79 once.80- Add constant: `{{ upper id }} SegmentType = "{{id}}"` in the alphabetical81 block.82- Add to `var Segments = map[SegmentType]func() SegmentWriter{}` with key83 `{{ upper id }}` mapping to `&segments.{{goType}}{}`.84- Keep lists alphabetically sorted. If not sorted, insert at correct position.85861. Documentation file8788- Consult the `segment-docs` skill (`.agents/skills/segment-docs/SKILL.md`) for the89 Go-to-documentation type mapping and rules for extracting options and template properties.90- Path: `website/docs/segments/{{category}}/{{id}}.mdx`.91- If file exists, skip. Else create with this template:9293````mdx94---95id: {{id}}96title: {{title}}97sidebar_label: {{title}}98---99100## What101102{{description}}103104## Sample Configuration105106import Config from '@site/src/components/Config.js';107108<Config data={{109 "type": "{{id}}",110 "style": "powerline",111 "powerline_symbol": "\uE0B0",112 "foreground": "#193549",113 "background": "#ffeb3b",114 "options": {115{{#each option}}116 "{{this.key}}": {{ json this.default }},117{{/each}}118 }119}}/>120121## Options122123| Name | Type | Description | Default |124| ---- | ---- | ----------- | ------- |125{{#each option}}| `{{this.key}}` | `{{this.type}}` | {{this.description}} | `{{ stringify this.default }}` |126{{/each}}127````1281291. Sidebar130131- Update `website/sidebars.js` under the correct category array to include132 `"segments/{{category}}/{{id}}"`.133- Insert alphabetically; if already present, do nothing.1341351. JSON Schema136137- File: `themes/schema.json`.138- Add `"{{id}}"` to `#/definitions/segment/properties/type/enum` if missing.139- Add an `allOf` entry for this segment guarded by140 `{ properties: { type: { const: "{{id}}" } } }` that declares each property141 as defined by inputs. Use appropriate JSON Schema types and include title,142 description, default.143- Keep the `allOf` array in a stable order by type name if feasible; otherwise144 append if not present.145146Validation147148- After changes, run `go build` (task: build oh-my-posh). Ensure no compile149 errors.150- Check markdown formatting; respect 120-char line length and fenced blocks with151 language.152153Notes154155- Use UTF-32 escapes (e.g., "\uEFF1") for icon defaults in docs and code.156- Keep code minimal. Complex logic should be added by maintainers after157 scaffold if needed.158159Optional1601611. Tests162163- Create a minimal test file at `src/segments/{{id}}_test.go` using the164 table-driven style. Include at least a happy-path test that asserts165 `Enabled()` returns true and the template renders expected output with default166 options.