diff --git a/src/template/text.go b/src/template/text.go index 65e09a85..a4d5399d 100644 --- a/src/template/text.go +++ b/src/template/text.go @@ -77,13 +77,16 @@ func (t *Text) cleanTemplate() { *knownVariables = append(*knownVariables, splitted[0]) return splitted[0], true } + knownVariables := []string{"Root", "PWD", "Folder", "Shell", "ShellVersion", "UserName", "HostName", "Env", "Data", "Code", "OS", "WSL", "Segments"} - matches := regex.FindAllNamedRegexMatch(`(?: |{|\()(?P(\.[a-zA-Z_][a-zA-Z0-9]*)+)`, t.Template) + matches := regex.FindAllNamedRegexMatch(`(?: |{|\()(?P(\.[a-zA-Z_][a-zA-Z0-9]*)+)`, t.Template) for _, match := range matches { - if variable, OK := unknownVariable(match["var"], &knownVariables); OK { + if variable, OK := unknownVariable(match["VAR"], &knownVariables); OK { pattern := fmt.Sprintf(`\.%s\b`, variable) dataVar := fmt.Sprintf(".Data.%s", variable) t.Template = regex.ReplaceAllString(pattern, t.Template, dataVar) } } + // allow literal dots in template + t.Template = strings.ReplaceAll(t.Template, `\.`, ".") } diff --git a/website/docs/configuration/templates.mdx b/website/docs/configuration/templates.mdx index a5f0d96d..dacaae4c 100644 --- a/website/docs/configuration/templates.mdx +++ b/website/docs/configuration/templates.mdx @@ -40,6 +40,15 @@ New-Alias -Name 'Set-PoshContext' -Value 'Set-EnvVar' -Scope Global -Force ## Template logic +:::tip +Oh My Posh replaces all unknown `.Var` variables in the template with the right references. If you need a literal `.Var`, use `\.Var` +in the template. + +```json +"template": " \\.NET \uE77F " +``` +::: + | Template | Description | | -------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |