fix: migrate console title template

relates to #1678
This commit is contained in:
Jan De Dobbeleer 2022-02-04 09:09:19 +01:00 committed by Jan De Dobbeleer
parent b0072ae039
commit 7dab387a11
2 changed files with 22 additions and 0 deletions

View file

@ -24,6 +24,9 @@ func (cfg *Config) Migrate(env environment.Environment) {
for _, segment := range cfg.Tooltips { for _, segment := range cfg.Tooltips {
segment.migrate(env, cfg.Version) segment.migrate(env, cfg.Version)
} }
if strings.Contains(cfg.ConsoleTitleTemplate, ".Path") {
cfg.ConsoleTitleTemplate = strings.ReplaceAll(cfg.ConsoleTitleTemplate, ".Path", ".PWD")
}
cfg.updated = true cfg.updated = true
cfg.Version = configVersion cfg.Version = configVersion
} }

View file

@ -383,3 +383,22 @@ func TestMigratePreAndPostfix(t *testing.T) {
assert.NotContains(t, segment.Properties, "postfix", tc.Case) assert.NotContains(t, segment.Properties, "postfix", tc.Case)
} }
} }
func TestMigrateConfig(t *testing.T) {
cases := []struct {
Case string
Expected string
Template string
}{
{Case: "Path", Expected: "{{ .PWD }}", Template: "{{ .Path }}"},
{Case: "No Path", Expected: "foo", Template: "foo"},
{Case: "Empty", Expected: "", Template: ""},
}
for _, tc := range cases {
cfg := &Config{
ConsoleTitleTemplate: tc.Template,
}
cfg.Migrate(&mock.MockedEnvironment{})
assert.Equal(t, tc.Expected, cfg.ConsoleTitleTemplate, tc.Case)
}
}