diff --git a/src/engine/segment.go b/src/engine/segment.go
index 088be4b6..d6e2adab 100644
--- a/src/engine/segment.go
+++ b/src/engine/segment.go
@@ -32,6 +32,7 @@ type Segment struct {
TemplatesLogic template.Logic `json:"templates_logic,omitempty"`
Properties properties.Map `json:"properties,omitempty"`
Interactive bool `json:"interactive,omitempty"`
+ Alias string `json:"alias,omitempty"`
writer SegmentWriter
Enabled bool `json:"-"`
@@ -384,7 +385,11 @@ func (segment *Segment) SetEnabled(env environment.Environment) {
}
if segment.writer.Enabled() {
segment.Enabled = true
- env.TemplateCache().AddSegmentData(string(segment.Type), segment.writer)
+ name := segment.Alias
+ if len(name) == 0 {
+ name = string(segment.Type)
+ }
+ env.TemplateCache().AddSegmentData(name, segment.writer)
}
}
diff --git a/themes/schema.json b/themes/schema.json
index 612b1888..8ad81410 100644
--- a/themes/schema.json
+++ b/themes/schema.json
@@ -358,6 +358,12 @@
"title": "Allow the use of interactive prompt escape sequences",
"description": "https://ohmyposh.dev/docs/configuration/segment#interactive",
"default": false
+ },
+ "alias": {
+ "type": "string",
+ "title": "Give the segment an alias for use in templates",
+ "description": "https://ohmyposh.dev/docs/configuration/segment#alias",
+ "default": ""
}
},
"allOf": [
diff --git a/website/docs/configuration/segment.mdx b/website/docs/configuration/segment.mdx
index 6d6a7f88..206a231b 100644
--- a/website/docs/configuration/segment.mdx
+++ b/website/docs/configuration/segment.mdx
@@ -50,6 +50,7 @@ understand how to configure a segment.
| `templates_logic` | `string` |
- `first_match`: return the first non-whitespace string and skip everything else
- `join`:evaluate all templates and join all non-whitespace strings (**default**)
|
| `properties` | `[]Property` | see [Properties][properties] below |
| `interactive` | `boolean` | when is true, the segment text is not escaped to allow the use of interactive prompt escape sequences - defaults to `false` |
+| `alias` | `string` | for use with [cross segment template properties][cstp] |
## Style
@@ -154,3 +155,4 @@ This means that for user Bill, who has a user account `Bill` on Windows and `bil
[regex]: https://www.regular-expressions.info/tutorial.html
[templates]: /docs/configuration/templates
[color-templates]: /docs/configuration/colors#color-templates
+[cstp]: templates.mdx#cross-segment-template-properties
diff --git a/website/docs/configuration/templates.mdx b/website/docs/configuration/templates.mdx
index 14a54acc..6299b3b0 100644
--- a/website/docs/configuration/templates.mdx
+++ b/website/docs/configuration/templates.mdx
@@ -109,6 +109,41 @@ For this to work, the segment you refer to needs to be in your config. The above
your config does not contain a git segment as Oh My Posh only populates the properties when it needs to.
:::
+:::tip
+If you have two identical segments for a different purpose, you can make use of the `alias` property on the segment
+to distinct between both. For example:
+
+```json
+{
+ "type": "command",
+ // highlight-next-line
+ "alias": "Hello",
+ "style": "plain",
+ "foreground": "#ffffff",
+ "properties": {
+ "command": "echo Hello"
+ }
+},
+{
+ "type": "command",
+ // highlight-next-line
+ "alias": "World",
+ "style": "plain",
+ "foreground": "#ffffff",
+ "properties": {
+ "command": "echo World"
+ }
+},
+{
+ "type": "text",
+ "style": "plain",
+ "foreground": "#ffffff",
+ // highlight-next-line
+ "template": "{{ .Segments.Hello.Output }} {{ .Segments.World.Output }}"
+}
+```
+:::
+
## Text decoration
You can make use of the following syntax to decorate text: