mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-12-31 13:57:26 -08:00
fix(template): allow literal dot word
This commit is contained in:
parent
5f8cf3e353
commit
0b0f119420
|
@ -77,13 +77,16 @@ func (t *Text) cleanTemplate() {
|
||||||
*knownVariables = append(*knownVariables, splitted[0])
|
*knownVariables = append(*knownVariables, splitted[0])
|
||||||
return splitted[0], true
|
return splitted[0], true
|
||||||
}
|
}
|
||||||
|
|
||||||
knownVariables := []string{"Root", "PWD", "Folder", "Shell", "ShellVersion", "UserName", "HostName", "Env", "Data", "Code", "OS", "WSL", "Segments"}
|
knownVariables := []string{"Root", "PWD", "Folder", "Shell", "ShellVersion", "UserName", "HostName", "Env", "Data", "Code", "OS", "WSL", "Segments"}
|
||||||
matches := regex.FindAllNamedRegexMatch(`(?: |{|\()(?P<var>(\.[a-zA-Z_][a-zA-Z0-9]*)+)`, t.Template)
|
matches := regex.FindAllNamedRegexMatch(`(?: |{|\()(?P<VAR>(\.[a-zA-Z_][a-zA-Z0-9]*)+)`, t.Template)
|
||||||
for _, match := range matches {
|
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)
|
pattern := fmt.Sprintf(`\.%s\b`, variable)
|
||||||
dataVar := fmt.Sprintf(".Data.%s", variable)
|
dataVar := fmt.Sprintf(".Data.%s", variable)
|
||||||
t.Template = regex.ReplaceAllString(pattern, t.Template, dataVar)
|
t.Template = regex.ReplaceAllString(pattern, t.Template, dataVar)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// allow literal dots in template
|
||||||
|
t.Template = strings.ReplaceAll(t.Template, `\.`, ".")
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,6 +40,15 @@ New-Alias -Name 'Set-PoshContext' -Value 'Set-EnvVar' -Scope Global -Force
|
||||||
|
|
||||||
## Template logic
|
## 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 "
|
||||||
|
```
|
||||||
|
:::
|
||||||
|
|
||||||
<!-- markdownlint-disable MD013 -->
|
<!-- markdownlint-disable MD013 -->
|
||||||
| Template | Description |
|
| Template | Description |
|
||||||
| -------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
| -------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||||
|
|
Loading…
Reference in a new issue