From 0b0f119420ac060770396b9aa57d09fedc78af6f Mon Sep 17 00:00:00 2001 From: Jan De Dobbeleer Date: Tue, 28 Jun 2022 20:23:07 +0200 Subject: [PATCH] fix(template): allow literal dot word --- src/template/text.go | 7 +++++-- website/docs/configuration/templates.mdx | 9 +++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) 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 | | -------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |