From b21c2d2c71df6fb8eca465455c289eddeb4f53f6 Mon Sep 17 00:00:00 2001 From: Jan De Dobbeleer Date: Wed, 13 Nov 2024 23:45:47 +0100 Subject: [PATCH] fix(config): correctly set config flag resolves #5882 --- src/cli/config_export.go | 3 ++- src/cli/config_export_image.go | 5 +++-- src/cli/config_migrate.go | 5 +++-- src/cli/config_migrate_glyphs.go | 5 +++-- src/cli/debug.go | 9 +++++++-- src/cli/init.go | 9 +++++++-- src/config/load.go | 2 -- src/prompt/engine.go | 1 + src/runtime/terminal.go | 5 ----- 9 files changed, 26 insertions(+), 18 deletions(-) diff --git a/src/cli/config_export.go b/src/cli/config_export.go index 6093402c..359ea1f3 100644 --- a/src/cli/config_export.go +++ b/src/cli/config_export.go @@ -40,7 +40,8 @@ Exports the current config to "~/new_config.omp.json" (in JSON format).`, os.Exit(2) } - cfg := config.Load(configFlag, shell.GENERIC, false) + configFile := config.Path(configFlag) + cfg := config.Load(configFile, shell.GENERIC, false) validateExportFormat := func() { format = strings.ToLower(format) diff --git a/src/cli/config_export_image.go b/src/cli/config_export_image.go index ceead33c..5150ffb7 100644 --- a/src/cli/config_export_image.go +++ b/src/cli/config_export_image.go @@ -50,10 +50,11 @@ Exports the config to an image file ~/mytheme.png. Exports the config to an image file using customized output options.`, Args: cobra.NoArgs, Run: func(_ *cobra.Command, _ []string) { - cfg := config.Load(configFlag, shell.GENERIC, false) + configFile := config.Path(configFlag) + cfg := config.Load(configFile, shell.GENERIC, false) flags := &runtime.Flags{ - Config: configFlag, + Config: configFile, Shell: shell.GENERIC, TerminalWidth: 150, } diff --git a/src/cli/config_migrate.go b/src/cli/config_migrate.go index dbe2a612..f794c5b5 100644 --- a/src/cli/config_migrate.go +++ b/src/cli/config_migrate.go @@ -40,10 +40,11 @@ Migrates the ~/myconfig.omp.json config file to TOML and writes the result to yo A backup of the current config can be found at ~/myconfig.omp.json.bak.`, Args: cobra.NoArgs, Run: func(_ *cobra.Command, _ []string) { - cfg := config.Load(configFlag, shell.GENERIC, true) + configFile := config.Path(configFlag) + cfg := config.Load(configFile, shell.GENERIC, true) flags := &runtime.Flags{ - Config: configFlag, + Config: configFile, Migrate: true, } diff --git a/src/cli/config_migrate_glyphs.go b/src/cli/config_migrate_glyphs.go index e93dae20..d65714d6 100644 --- a/src/cli/config_migrate_glyphs.go +++ b/src/cli/config_migrate_glyphs.go @@ -35,10 +35,11 @@ Migrates the ~/myconfig.omp.json config file's glyphs and writes the result to y A backup of the current config can be found at ~/myconfig.omp.json.bak.`, Args: cobra.NoArgs, Run: func(_ *cobra.Command, _ []string) { - cfg := config.Load(configFlag, shell.GENERIC, false) + configFile := config.Path(configFlag) + cfg := config.Load(configFile, shell.GENERIC, false) flags := &runtime.Flags{ - Config: configFlag, + Config: configFile, } env := &runtime.Terminal{} diff --git a/src/cli/debug.go b/src/cli/debug.go index 1001fdf2..d1a88eaa 100644 --- a/src/cli/debug.go +++ b/src/cli/debug.go @@ -6,6 +6,7 @@ import ( "github.com/jandedobbeleer/oh-my-posh/src/build" "github.com/jandedobbeleer/oh-my-posh/src/config" + "github.com/jandedobbeleer/oh-my-posh/src/log" "github.com/jandedobbeleer/oh-my-posh/src/prompt" "github.com/jandedobbeleer/oh-my-posh/src/runtime" "github.com/jandedobbeleer/oh-my-posh/src/template" @@ -36,10 +37,14 @@ func createDebugCmd() *cobra.Command { return } - cfg := config.Load(configFlag, args[0], false) + log.Enable() + log.Debug("debug mode enabled") + + configFile := config.Path(configFlag) + cfg := config.Load(configFile, args[0], false) flags := &runtime.Flags{ - Config: configFlag, + Config: configFile, Debug: true, PWD: pwd, Shell: args[0], diff --git a/src/cli/init.go b/src/cli/init.go index 66c6788a..f564c063 100644 --- a/src/cli/init.go +++ b/src/cli/init.go @@ -5,6 +5,7 @@ import ( "time" "github.com/jandedobbeleer/oh-my-posh/src/config" + "github.com/jandedobbeleer/oh-my-posh/src/log" "github.com/jandedobbeleer/oh-my-posh/src/runtime" "github.com/jandedobbeleer/oh-my-posh/src/shell" "github.com/jandedobbeleer/oh-my-posh/src/template" @@ -66,15 +67,19 @@ See the documentation to initialize your shell: https://ohmyposh.dev/docs/instal func runInit(sh string) { var startTime time.Time + if debug { startTime = time.Now() + log.Enable() + log.Debug("debug mode enabled") } - cfg := config.Load(configFlag, sh, false) + configFile := config.Path(configFlag) + cfg := config.Load(configFile, sh, false) flags := &runtime.Flags{ Shell: sh, - Config: configFlag, + Config: configFile, Strict: strict, Debug: debug, } diff --git a/src/config/load.go b/src/config/load.go index f6c8dde6..d4609dc9 100644 --- a/src/config/load.go +++ b/src/config/load.go @@ -25,8 +25,6 @@ import ( func Load(configFile, sh string, migrate bool) *Config { defer log.Trace(time.Now()) - configFile = Path(configFile) - cfg := loadConfig(configFile) // only migrate automatically when the switch isn't set diff --git a/src/prompt/engine.go b/src/prompt/engine.go index 0647cebe..ab6f1ebe 100644 --- a/src/prompt/engine.go +++ b/src/prompt/engine.go @@ -462,6 +462,7 @@ func (e *Engine) rectifyTerminalWidth(diff int) { // given configuration options, and is ready to print any // of the prompt components. func New(flags *runtime.Flags) *Engine { + flags.Config = config.Path(flags.Config) cfg := config.Load(flags.Config, flags.Shell, flags.Migrate) env := &runtime.Terminal{} diff --git a/src/runtime/terminal.go b/src/runtime/terminal.go index c19f70ed..0e0cc5b3 100644 --- a/src/runtime/terminal.go +++ b/src/runtime/terminal.go @@ -49,11 +49,6 @@ func (term *Terminal) Init(flags *Flags) { term.CmdFlags = &Flags{} } - if term.CmdFlags.Debug { - log.Enable() - log.Debug("debug mode enabled") - } - if term.CmdFlags.Plain { log.Plain() log.Debug("plain mode enabled")