mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-01-29 20:10:56 -08:00
fix(template): support surrounding variables with braces
This commit is contained in:
parent
e6d4413ae7
commit
9e77d0f939
|
@ -105,7 +105,7 @@ func (t *textTemplate) cleanTemplate() {
|
|||
return splitted[0], true
|
||||
}
|
||||
knownVariables := []string{"Root", "PWD", "Folder", "Shell", "UserName", "HostName", "Env", "Data", "Code", "OS"}
|
||||
matches := findAllNamedRegexMatch(`(?: |{)(?P<var>(\.[a-zA-Z_][a-zA-Z0-9]*)+)`, t.Template)
|
||||
matches := findAllNamedRegexMatch(`(?: |{|\()(?P<var>(\.[a-zA-Z_][a-zA-Z0-9]*)+)`, t.Template)
|
||||
for _, match := range matches {
|
||||
if variable, OK := unknownVariable(match["var"], &knownVariables); OK {
|
||||
pattern := fmt.Sprintf(`\.%s\b`, variable)
|
||||
|
|
|
@ -175,6 +175,11 @@ func TestCleanTemplate(t *testing.T) {
|
|||
Expected: "{{ .Env.HELLO }} {{ .Data.World }} {{ .Data.World }}",
|
||||
Template: "{{ .Env.HELLO }} {{ .World }} {{ .World }}",
|
||||
},
|
||||
{
|
||||
Case: "Braces",
|
||||
Expected: "{{ if or (.Data.Working.Changed) (.Data.Staging.Changed) }}#FF9248{{ end }}",
|
||||
Template: "{{ if or (.Working.Changed) (.Staging.Changed) }}#FF9248{{ end }}",
|
||||
},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
template := &textTemplate{
|
||||
|
|
Loading…
Reference in a new issue