Skip to content

Commit

Permalink
fix(config): correctly set config flag
Browse files Browse the repository at this point in the history
resolves #5882
  • Loading branch information
JanDeDobbeleer committed Nov 13, 2024
1 parent 9349de4 commit b21c2d2
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 18 deletions.
3 changes: 2 additions & 1 deletion src/cli/config_export.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions src/cli/config_export_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
5 changes: 3 additions & 2 deletions src/cli/config_migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down
5 changes: 3 additions & 2 deletions src/cli/config_migrate_glyphs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down
9 changes: 7 additions & 2 deletions src/cli/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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],
Expand Down
9 changes: 7 additions & 2 deletions src/cli/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
}
Expand Down
2 changes: 0 additions & 2 deletions src/config/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/prompt/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down
5 changes: 0 additions & 5 deletions src/runtime/terminal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit b21c2d2

Please # to comment.