mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-12-27 11:59:40 -08:00
fix(config): migrate glyphs correctly for all formats
This commit is contained in:
parent
42b75241c7
commit
76c7ea536b
3
.vscode/launch.json
vendored
3
.vscode/launch.json
vendored
|
@ -109,7 +109,8 @@
|
|||
"args": [
|
||||
"config",
|
||||
"migrate",
|
||||
"glyphs"
|
||||
"glyphs",
|
||||
"--config=/Users/jan/.posh.omp.yaml"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
|
|
@ -40,21 +40,28 @@ A backup of the current config can be found at ~/myconfig.omp.json.bak.`,
|
|||
Config: config,
|
||||
},
|
||||
}
|
||||
|
||||
env.Init()
|
||||
defer env.Close()
|
||||
cfg := engine.LoadConfig(env)
|
||||
|
||||
cfg.MigrateGlyphs = true
|
||||
if len(format) == 0 {
|
||||
format = cfg.Format
|
||||
}
|
||||
|
||||
if write {
|
||||
cfg.Backup()
|
||||
cfg.Write(format)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Print(cfg.Export(format))
|
||||
},
|
||||
}
|
||||
|
||||
func init() { //nolint:gochecknoinits
|
||||
migrateGlyphsCmd.Flags().BoolVarP(&write, "write", "w", false, "write the migrated config back to the config file")
|
||||
migrateGlyphsCmd.Flags().StringVarP(&format, "format", "f", "json", "the config format to migrate to")
|
||||
migrateGlyphsCmd.Flags().StringVarP(&format, "format", "f", "", "the config format to migrate to")
|
||||
migrateCmd.AddCommand(migrateGlyphsCmd)
|
||||
}
|
||||
|
|
|
@ -55,8 +55,8 @@ type Config struct {
|
|||
|
||||
Output string `json:"-"`
|
||||
MigrateGlyphs bool `json:"-"`
|
||||
Format string `json:"-"`
|
||||
|
||||
format string
|
||||
origin string
|
||||
// eval bool
|
||||
updated bool
|
||||
|
@ -107,10 +107,10 @@ func loadConfig(env platform.Environment) *Config {
|
|||
|
||||
var cfg Config
|
||||
cfg.origin = configFile
|
||||
cfg.format = strings.TrimPrefix(filepath.Ext(configFile), ".")
|
||||
cfg.Format = strings.TrimPrefix(filepath.Ext(configFile), ".")
|
||||
cfg.env = env
|
||||
if cfg.format == "yml" {
|
||||
cfg.format = YAML
|
||||
if cfg.Format == "yml" {
|
||||
cfg.Format = YAML
|
||||
}
|
||||
|
||||
config.AddDriver(yaml.Driver)
|
||||
|
@ -166,7 +166,7 @@ func (cfg *Config) Export(format string) string {
|
|||
cfg.sync()
|
||||
|
||||
if len(format) != 0 {
|
||||
cfg.format = format
|
||||
cfg.Format = format
|
||||
}
|
||||
|
||||
config.AddDriver(yaml.Driver)
|
||||
|
@ -174,7 +174,7 @@ func (cfg *Config) Export(format string) string {
|
|||
|
||||
var result bytes.Buffer
|
||||
|
||||
if cfg.format == JSON {
|
||||
if cfg.Format == JSON {
|
||||
jsonEncoder := json2.NewEncoder(&result)
|
||||
jsonEncoder.SetEscapeHTML(false)
|
||||
jsonEncoder.SetIndent("", " ")
|
||||
|
@ -184,23 +184,21 @@ func (cfg *Config) Export(format string) string {
|
|||
return escapeGlyphs(data, cfg.MigrateGlyphs)
|
||||
}
|
||||
|
||||
_, _ = config.DumpTo(&result, cfg.format)
|
||||
switch cfg.format {
|
||||
_, _ = config.DumpTo(&result, cfg.Format)
|
||||
var prefix string
|
||||
switch cfg.Format {
|
||||
case YAML:
|
||||
prefix := "# yaml-language-server: $schema=https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json\n\n"
|
||||
return prefix + result.String()
|
||||
prefix = "# yaml-language-server: $schema=https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json\n\n"
|
||||
case TOML:
|
||||
prefix := "#:schema https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json\n\n"
|
||||
return prefix + escapeGlyphs(result.String(), cfg.MigrateGlyphs)
|
||||
default:
|
||||
return result.String()
|
||||
prefix = "#:schema https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json\n\n"
|
||||
}
|
||||
return prefix + escapeGlyphs(result.String(), cfg.MigrateGlyphs)
|
||||
}
|
||||
|
||||
func (cfg *Config) BackupAndMigrate() {
|
||||
cfg.Backup()
|
||||
cfg.Migrate()
|
||||
cfg.Write(cfg.format)
|
||||
cfg.Write(cfg.Format)
|
||||
}
|
||||
|
||||
func (cfg *Config) Write(format string) {
|
||||
|
|
Loading…
Reference in a new issue