diff --git a/pkg/config/app_config.go b/pkg/config/app_config.go index 0ebc1796..e7b085c6 100644 --- a/pkg/config/app_config.go +++ b/pkg/config/app_config.go @@ -142,6 +142,10 @@ type GuiConfig struct { // Window border style. // One of 'rounded' (default) | 'single' | 'double' | 'hidden' Border string `yaml:"border"` + + // SortEnv sorts the container Env panel alphabetically by key. Default false + // preserves the insertion order from the image / compose file. + SortEnv bool `yaml:"sortEnv,omitempty"` } // CommandTemplatesConfig determines what commands actually get called when we diff --git a/pkg/gui/containers_panel.go b/pkg/gui/containers_panel.go index a638ee29..3d2e81ba 100644 --- a/pkg/gui/containers_panel.go +++ b/pkg/gui/containers_panel.go @@ -3,6 +3,7 @@ package gui import ( "context" "fmt" + "sort" "strings" "time" @@ -155,7 +156,23 @@ func (gui *Gui) containerEnv(container *commands.Container) string { return gui.Tr.NothingToDisplay } - envVarsList := lo.Map(container.Details.Config.Env, func(envVar string, _ int) []string { + envVars := container.Details.Config.Env + if gui.Config.UserConfig.Gui.SortEnv { + envVars = append([]string(nil), envVars...) + sort.SliceStable(envVars, func(i, j int) bool { + ki := envVars[i] + if idx := strings.IndexByte(ki, '='); idx >= 0 { + ki = ki[:idx] + } + kj := envVars[j] + if idx := strings.IndexByte(kj, '='); idx >= 0 { + kj = kj[:idx] + } + return ki < kj + }) + } + + envVarsList := lo.Map(envVars, func(envVar string, _ int) []string { splitEnv := strings.SplitN(envVar, "=", 2) key := splitEnv[0] value := ""