From 540860445a53e1eabeb8c05b2116539246b885f4 Mon Sep 17 00:00:00 2001 From: R Sivaram <96035753+rsiva0400@users.noreply.github.com> Date: Sat, 11 Jul 2026 13:01:21 +0530 Subject: [PATCH] Add gui.sortEnv option to sort Env panel alphabetically New optional bool 'gui.sortEnv' (default: false). When true, the container Env panel is rendered with variables sorted alphabetically by key; default preserves the existing image / compose insertion order. --- pkg/config/app_config.go | 4 ++++ pkg/gui/containers_panel.go | 19 ++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) 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 := ""