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.
This commit is contained in:
R Sivaram 2026-07-11 13:01:21 +05:30
parent 7e7aadc207
commit 540860445a
2 changed files with 22 additions and 1 deletions

View file

@ -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

View file

@ -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 := ""