id | title | sidebar_label |
---|---|---|
contributing_segment |
Add Segment |
Add Segment |
Add a new file following this convention: new_segment.go
.
Ensure new
is a single verb indicating the context the segment renders.
You can use the following template as a guide.
package main
type new struct {
props *properties
env environmentInfo
}
const (
//NewProp switches something
NewProp Property = "newprop"
)
func (n *new) enabled() bool {
true
}
func (n *new) string() string {
newText := n.props.getString(NewProp, "\uEFF1")
return newText
}
func (n *new) init(props *properties, env environmentInfo) {
n.props = props
n.env = env
}
When it comes to properties, make sure to use the UTF32 representation (e.g. "\uEFF1") rather than the icon itself. This will facilitate the review process as not all environments display the icons based on the font being used. You can find these values and query for icons easily at Nerd Fonts.
For each segment, there's a single test file ensuring the functionality going forward. The convention
is new_segment_test.go
, have a look at existing segment tests for inspiration.
segment.go
contains the list of available SegmentType
's, which gives them a name we can map from the
.json
themes.
Add your segment.
//New is brand new
New SegmentType = "new"
Map your SegmentType
to your Segment in the mapSegmentWithWriter
function.
New: &new{},
Even with unit tests, it's a good idea to build and validate the changes:
go build -o $GOPATH/bin/oh-my-posh
Create a new markdown
file underneath the docs/docs
folder called segment-new.md
.
Use the following template as a guide.
---
id: new
title: New
sidebar_label: New
---
## What
Display something new.
## Sample Configuration
```json
{
"type": "new",
"style": "powerline",
"powerline_symbol": "\uE0B0",
"foreground": "#193549",
"background": "#ffeb3b",
"properties": {
"newprop": "\uEFF1"
}
}
```
## Properties
- newprop: `string` - the new text to show - defaults to `\uEFF1`
Open sidebars.js
and add your document id (new
) to the items of the Segments category.
Edit the themes/schema.json
file to add your segment.
At $.definitions.segment.properties.type.enum
, add your SegmentType
to the array:
new,
At $.definitions.segment.allOf
, add your segment details:
{
"if": {
"properties": {
"type": { "const": "new" }
}
},
"then": {
"title": "Display something new",
"description": "https://ohmyposh.dev/docs/new",
"properties": {
"properties": {
"properties": {
"nwprop": {
"type": "string",
"title": "New Prop",
"description": "the new text to show",
"default": "\uEFF1"
}
}
}
}
}
}
And be patient, I'm going as fast as I can 🏎